简体   繁体   中英

Flutter dart error (The relevant error-causing widget was ...)

Im getting multiple errors because of my widget's size or datas ( i guess). I tried to wrote this part all over again but it didn't work. Is it because of widgets size or something else?

 @override
 Widget build(BuildContext context) {
   var questionsOf = widget.setType(InputPage.topicN);

   CollectionReference contestantsRef =
       FirebaseFirestore.instance.collection('contestants');

   return Scaffold(
     backgroundColor: Colors.blue,
     appBar: AppBar(
       centerTitle: true,
     ),
     body: SafeArea(
         child: Column(
       children: <Widget>[
         Flexible(
             child: Container(
           height: 100,
           child: iconCreate(),
         )),
         Container(
           child: StreamBuilder<QuerySnapshot>(
             stream: contestantsRef.snapshots(),
             builder: (BuildContext context, AsyncSnapshot asyncSnapshot) {
               List<DocumentSnapshot> listOfDocumentSnap =
                   asyncSnapshot.data.docs;

               return ListView.builder(
                 itemBuilder: (context, index) {
                   return Text('${listOfDocumentSnap[index].data()}');
                 },
                 itemCount: listOfDocumentSnap.length,
               );
             },
           ),
         ),
         SizedBox(
           height: 100,
         ),
         Flexible(
           flex: 4,
           child: Container(
             height: 200,
             margin: EdgeInsets.all(20),
             decoration:
                 BoxDecoration(border: Border.all(color: Colors.black)),
             child: Center(
               child: StreamBuilder(
                 stream: questionsOf.snapshots(),
                 builder: (BuildContext context, AsyncSnapshot asyncsnapshot) {
                   String question1 =
                       asyncsnapshot.data.data()['q$questionIndexa']
                           ['q$questionIndexa' + 'Sent'];
                   return Text('$question1');
                 },
               ),
             ),
           ),
         ),
         Flexible(
             flex: 3,
             child: Container(
               child: Column(
                 children: [
                   buildAnswerBox(questionsOf, 1, questionIndexa),
                   SizedBox(
                     height: 10,
                   ),
                   buildAnswerBox(questionsOf, 2, questionIndexa),
                   SizedBox(
                     height: 10,
                   ),
                   buildAnswerBox(questionsOf, 3, questionIndexa),
                   SizedBox(
                     height: 10,
                   ),
                   buildAnswerBox(questionsOf, 4, questionIndexa),
                 ],
               ),
             ))
       ],
     )),
   );
 }

This is the Error part:

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderCustomPaint#60178 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1929 pos 12: 'hasSize'

The relevant error-causing widget was
ListView
lib\guess_page.dart:74


════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderRepaintBoundary#c207a relayoutBoundary=up3 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1929 pos 12: 'hasSize'

The relevant error-causing widget was
Column
lib\guess_page.dart:60
═══════════════════════════════

After all i get is a flat blue screen like this

在此处输入图像描述

The things i tried. Firstly i thought it's because of stream builder and i tried to change stream builder and listview part but it didn't work. Than i wrap widgets with expanded and flexible (given flex) but it didn'T work too.

add shrinkWrap property to true in ListView.builder like below

 return ListView.builder(
             shrinkWrap:true
             itemBuilder: (context, index) {
               return Text('${listOfDocumentSnap[index].data()}');
             },
             itemCount: listOfDocumentSnap.length,
           );

add this property to your listview.builder physics: const BouncingScrollPhysics(),

use these properties to your ListView

shrinkWrap: true,
physics: BouncingScrollPhysics(),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM