RenderBox was not laid out: RenderCustomPaint Flutter

Alex Ali

I keep getting this error when I try to run the app :

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

The relevant error-causing widget was ListView account_screen.dart:32 ════════════════════════════════════════════════════════════════════════════════

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

The relevant error-causing widget was Column account_screen.dart:19 ════════════════════════════════════════════════════════════════════════════════

here is my code:

body: SingleChildScrollView(
      child: Column(
        children: [
          StreamBuilder(
              stream:
                  FirebaseFirestore.instance.collection('Ads').snapshots(),
              builder: (BuildContext context,
                  AsyncSnapshot<QuerySnapshot> snapshot) {
                if (!snapshot.hasData) {
                  return const Center(
                    child: CircularProgressIndicator(),
                  );
                }

                return ListView(
                    children: snapshot.data!.docs.map((document) {
                  return Card(
                    child: ListTile(
                      leading: Image.asset('assets/images/facebook.png'),
                      title: Text(document['Title']),
                      subtitle: Text(document['Description']),
                      trailing: const Icon(Icons.car_crash),
                    ),
                  );
                }).toList());
              })
        ],
      ),
    ),
Kantine

By default, ListView tries to use all the available space but this space is infinite, which leads to the error. You can use shrinkWrap property to make the ListView using only the space needed by its children :

return ListView(
  shrinkWrap: true, // Add this
  children: snapshot.data!.docs.map((document) {
  ...
  }
).toList());

More about shrinkWrap here: https://api.flutter.dev/flutter/widgets/ScrollView/shrinkWrap.html

and here https://stackoverflow.com/a/54008230/11244991

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

RenderBox was not laid out in flutter

Flutter: RenderBox was not laid out

RenderBox was not laid out error in flutter

RenderBox was not laid out: flutter error

Flutter RenderBox was not laid out on SingleChildScrollView

Flutter: RenderBox was not laid out when working with ListView

Flutter:RenderBox not laid out while using ListTile

RenderBox was not laid out, Flutter Listview Builder not Displaying

"RenderBox was not laid out" text field error in flutter

RenderBox was not laid out: RenderPointerListener

Flutter, How to solve "RenderBox was not laid out: ... NEEDS-PAINT"

How to solve ' RenderBox was not laid out:' in flutter in a card widget

Flutter: RenderBox was not laid out when i use LIstView

RenderBox was not laid out: RenderRepaintBoundary#09022 relayoutBoundary

Renderbox was not laid out: Horizontal ListView inside Column

Using ListTile and getting exception: RenderBox was not laid out

Renderbox was not laid out when added to a row

ListView inside SingleChildScrollView: RenderBox was not laid out

Exception while retrieving the data :- RenderBox was not laid out

Many "RenderBox was not laid out" for a Row in a Column

Error with ListView output: RenderBox was not laid out

RenderBox was not laid out: RenderRepaintBoundary#622c4 relayoutBoundary=up2 NEEDS-PAINT Flutter

Flutter Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#eaea6 NEEDS-LAYOUT NEEDS-PAINT

RenderBox was not laid out : The relevant error-causing widget was ExpansionTile

ListView.builder gives error: RenderBox was not laid out

'RenderBox was not laid out' error even after using Expanded

Exception:-RenderBox was not laid out despite removing the expanded widgets

CupertinoActionSheet throws RenderBox was not laid out: RenderFlex#54b93 relayoutBoundary=up8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE error Flutter

Flutter widgets are not getting laid out correctly