dart RenderBox未布局:RenderPointerListener

lnxxn5zx  于 2023-07-31  发布在  其他
关注(0)|答案(4)|浏览(93)

我在从模拟模型中获取数据时遇到问题,但得到错误代码:RenderBox未布局:RenderPointerListener#33496 relayoutBoundary=up15 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
我的模特. /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'),
];

字符串
这是我的视图页。/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: () {
                // การทำงานเมื่อกดที่รายการข้อความ
                // คุณสามารถเพิ่มโค้ดที่นี่เพื่อรายละเอียดเพิ่มเติมหากต้องการ
              },
            ),
          );
        },
      ),
    ],
         ),
      ),
    );
  }

}


错误enter image description here
怎么修谢谢先生

zed5wv10

zed5wv101#

您在Scrollable小部件中放置了一个无限高的子小部件,导致了此错误。要解决此问题,您可以尝试以下操作:

  • 删除SingleChildScrollViewColumn小部件,仅保留ListView小部件,使整个页面仅由ListView.builder组成。

  • shrinkWrap: truephysics: const NeverScrollableScrollPhysics()属性添加到ListView小部件,这样您就可以在Column中使用其他小部件沿着ListView。必须从ListView.builder中删除const标记。

希望这对你有帮助!

6qftjkof

6qftjkof2#

删除SingleChildScrollView和列小部件,只需添加ListView.Buidler在脚手架体像下面的代码:

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: () {
                // การทำงานเมื่อกดที่รายการข้อความ
                // คุณสามารถเพิ่มโค้ดที่นี่เพื่อรายละเอียดเพิ่มเติมหากต้องการ
              },
            ),
          );
        },
      ),
    );
  }
}

字符串

7gcisfzg

7gcisfzg3#

删除SingleChildScrollView和Column小部件将有所帮助。

zc0qhyus

zc0qhyus4#

enter image description here
我删除了CircleAvatar并开始工作,但是CircleAvatar有什么问题吗

相关问题