skip to Main Content

I have a problem fetching data from the simulated model but get error code : RenderBox was not laid out: RenderPointerListener#33496 relayoutBoundary=up15 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

My model . /models/messagemodel.dart

import 'package:flutter/material.dart';

class Message {
  final String name;
  final String message;
  final String imageProfile;
  final String date;

  Message({
  required this.name, 
  required this.message, 
  required this.imageProfile,
  required this.date});
}

final List<Message> messages = [
Message(name: 'อลงกรณ์ ดอนสุวรรณ', message: "สอบถามตัวสินค้าหน่อยครับ", imageProfile:'https://i.pinimg.com/236x/cc/00/75/cc007582be734f3eb536e45006ba8ac1.jpg',date: '2023-05-31'),
Message(name: 'รัชนก ธานี', message: "สินค้ายังมีอยู่ไหมคะ", imageProfile:'https://blogs.jaidee-webdesign.com/wp-content/uploads/2021/09/253-2532493_thinking-man-png-free-download-transparent-png.png',date: '2023-05-30'),
Message(name: 'Gordon Ramsey', message: "Hello , I need to your product", imageProfile:'https://www.nicepng.com/png/detail/340-3400291_smiling-person-png-man-with-arms-crossed-png.png',date: '2023-05-29'),
];

This is My View Page
./messageview.dart


import 'package:flutter/material.dart';
import 'package:rj38_seller/environment/themes.dart';
import 'package:rj38_seller/models/messagemodel.dart';
import 'package:rj38_seller/views/message/components/listmessage.dart';

class MessageView extends StatefulWidget {
  const MessageView({super.key});

  @override
  State<MessageView> createState() => _MessageViewState();
}

class _MessageViewState extends State<MessageView> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Themes().backgroundTheme,
      appBar: AppBar(
        centerTitle: false,
        titleSpacing: 0.0,
        backgroundColor: Themes().white,
          elevation: 0,
        title: Transform(transform: Matrix4.translationValues(30.0, 0.0, 0.0),
        child: Text('Message',style: TextStyle(color: Themes().black)))
      ),
      body:  SingleChildScrollView(
        child: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      const ListView.builder(
        itemCount: messages.length,
        itemBuilder: (context, index) {
          return Card(
            child: ListTile(
              leading: CircleAvatar(
                backgroundImage: NetworkImage(messages[index].imageProfile),
              ),
              title: Text(messages[index].name),
              subtitle: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(messages[index].message),
                  Text('Date: ${messages[index].date}'),
                ],
              ),
              onTap: () {
                // การทำงานเมื่อกดที่รายการข้อความ
                // คุณสามารถเพิ่มโค้ดที่นี่เพื่อรายละเอียดเพิ่มเติมหากต้องการ
              },
            ),
          );
        },
      ),
    ],
         ),
      ),
    );
  }

}

Error
enter image description here

How to fix it thank you sir

2

Answers


  1. You have placed an infinitely tall child widget inside a Scrollable widget, causing this error. To resolve the issue, you can try the following:

    • Remove the SingleChildScrollView and Column widgets and keep only the ListView widget to make the entire page consist of only the ListView.builder.

    OR

    • Add shrinkWrap: true and physics: const NeverScrollableScrollPhysics() properties to the ListView widget, so you can use other widgets inside the Column along with the ListView. You must be remove const tag from ListView.builder.

    Hope this helps!

    Login or Signup to reply.
  2. Remove SingleChildScrollView And Column Widget and simply add ListView.Buidler in Scaffold Body Like Below Code:

    Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.deepPurple,
          appBar: AppBar(
              centerTitle: false,
              titleSpacing: 0.0,
              backgroundColor: Colors.white,
              elevation: 0,
              title: Transform(
                  transform: Matrix4.translationValues(30.0, 0.0, 0.0),
                  child: Text('Message', style: TextStyle(color: Colors.black)))),
          body: ListView.builder(
            itemCount: messages.length,
            itemBuilder: (context, index) {
              return Card(
                child: ListTile(
                  leading: CircleAvatar(
                    backgroundImage: NetworkImage(messages[index].imageProfile),
                  ),
                  title: Text(messages[index].name),
                  subtitle: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(messages[index].message),
                      Text('Date: ${messages[index].date}'),
                    ],
                  ),
                  onTap: () {
                    // การทำงานเมื่อกดที่รายการข้อความ
                    // คุณสามารถเพิ่มโค้ดที่นี่เพื่อรายละเอียดเพิ่มเติมหากต้องการ
                  },
                ),
              );
            },
          ),
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search