在对PerformLayout()RenderCustomMultiChildLayoutBox对象赋予无限大小期间引发了以下断言

时间:2019-04-17 19:06:33

标签: flutter google-cloud-firestore

我尝试使用标题作为集合字段来创建ExpansionTileList,而使用示例here,其中的ListTile是子集合 但是,当我运行这段代码时,我却黑屏了,我不明白是什么使它发生的 那是我的代码:

class PackagesPage extends StatefulWidget {
  final DocumentSnapshot documentID;
  final Firestore firestore;
  PackagesPage({this.documentID, this.firestore});

  @override
  PackagesPageState createState() => PackagesPageState();
}

class PackagesPageState extends State<PackagesPage> {
  @override
  void initState(){
    super.initState();
  }
  void showSnackBar(BuildContext context){
    var snackBar = SnackBar(
      content: Text("Voulez vous Acheter le service?"),
      action: SnackBarAction(
          label: "OUI",
          onPressed: (){
            PaiementStripe().buyService(priceService);
          }
      ),
    );
    Scaffold.of(context).showSnackBar(snackBar);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Services'),
        backgroundColor: Colors.deepOrangeAccent[400],
      ),
      floatingActionButton:  FloatingActionButton(
        heroTag: 'fab1',
        onPressed: (){
          showSnackBar(context);
        },
        child: Icon(
            Icons.credit_card,
            color: Colors.white),
        backgroundColor: Colors.deepOrangeAccent,
      ),
      body: ReviewService(),
    );
  }
}
class ReviewService extends StatelessWidget {
  ReviewService({this.firestore, this.docID});
  final Firestore firestore;
  final String docID;

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: Firestore.instance.collection('hospital').document(docID).collection('services').snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
        if (!snapshot.hasData){
          return const Text("Chargement...");
        }
        List<DocumentSnapshot> documents = snapshot.data.documents;
        return ExpansionTileList(
            firestore: firestore,
            documents: documents,
            docID: docID
        );
      },
    );
  }
}
class ExpansionTileList extends StatelessWidget{
  final List<DocumentSnapshot> documents;
  final String docID;
  final Firestore firestore;

  ExpansionTileList({this.firestore, this.documents,this.docID });
  List<Widget> _getChildren(){
    List<Widget> children= [];
    documents.forEach((doc){
      children.add(
          ServiceExpansionTile(
              name: doc['nom'],
              serviceKey: doc.documentID,
              firestore: firestore,
              docID: docID
          )
      );
    });
    return children;
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ListView(
      children: _getChildren(),
    );
  }
}
class ServiceExpansionTile extends StatelessWidget {
  ServiceExpansionTile({this.serviceKey, this.name, this.firestore, this.docID });
  final String serviceKey;
  final String name;
  final Firestore firestore;
  final String docID;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    PageStorageKey _serviceKey = PageStorageKey('$serviceKey');

    return Scaffold(
      body: ExpansionTile(
        key: _serviceKey,
        title: Text(
          name,
          style: TextStyle(
              fontSize: 20.0,
              fontWeight: FontWeight.bold
          ),
        ),
        children: <Widget>[
          StreamBuilder(
              stream: Firestore.instance.collection('hospital')
                  .document(docID)
                  .collection('services')
                  .document(serviceKey)
                  .collection('details').snapshots(),
              builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
                if (!snapshot.hasData) return const Text('Chargement...');
                List<DocumentSnapshot> documents = snapshot.data.documents;
                List<Widget> detailsList = [];
                documents.forEach((doc){
                  PageStorageKey _detailsKey = new PageStorageKey('${doc.documentID}');
                  detailsList.add(
                      ListTile(
                        key: _detailsKey,
                        leading: Icon(Icons.hotel),
                        title: Text(doc['nom']),
                      ));
                });
                return Column(children: detailsList);
              })
        ],
      ),
    );
  }
}

运行后,我在控制台日志中收到此消息:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (26849): The following assertion was thrown during performLayout():
I/flutter (26849): RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
I/flutter (26849): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (26849): inside another render object that allows its children to pick their own size.
I/flutter (26849): The nearest ancestor providing an unbounded height constraint is:
I/flutter (26849):   RenderIndexedSemantics#96d29 relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):   creator: IndexedSemantics ← NotificationListener<KeepAliveNotification> ← KeepAlive ←
I/flutter (26849):   AutomaticKeepAlive ← SliverList ← MediaQuery ← SliverPadding ← Viewport ←
I/flutter (26849):   IgnorePointer-[GlobalKey#663be] ← Semantics ← Listener ← _GestureSemantics ← ⋯
I/flutter (26849):   parentData: index=0; layoutOffset=0.0 (can use size)
I/flutter (26849):   constraints: BoxConstraints(w=392.7, 0.0<=h<=Infinity)
I/flutter (26849):   semantic boundary
I/flutter (26849):   size: MISSING
I/flutter (26849):   index: 0
I/flutter (26849): The constraints that applied to the RenderCustomMultiChildLayoutBox were:
I/flutter (26849):   BoxConstraints(w=392.7, 0.0<=h<=Infinity)
I/flutter (26849): The exact size it was given was:
I/flutter (26849):   Size(392.7, Infinity)
I/flutter (26849): See https://flutter.io/layout/ for more information.
I/flutter (26849): 
I/flutter (26849): When the exception was thrown, this was the stack:
I/flutter (26849): #0      RenderBox.debugAssertDoesMeetConstraints.<anonymous closure> (package:flutter/src/rendering/box.dart:1749:9)
I/flutter (26849): #1      RenderBox.debugAssertDoesMeetConstraints (package:flutter/src/rendering/box.dart:1823:6)
I/flutter (26849): #2      RenderBox.size=.<anonymous closure> (package:flutter/src/rendering/box.dart:1543:17)
I/flutter (26849): #3      RenderBox.size= (package:flutter/src/rendering/box.dart:1543:65)
I/flutter (26849): #4      RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:355:5)
I/flutter (26849): #5      RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #6      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #7      RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #8      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #9      _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1206:11)
I/flutter (26849): #10     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #11     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #12     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #13     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #14     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #15     RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:164:27)
I/flutter (26849): #16     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #17     RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:182:11)
I/flutter (26849): #18     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #19     RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:407:13)
I/flutter (26849): #20     RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1322:12)
I/flutter (26849): #21     RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1240:20)
I/flutter (26849): #22     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #23     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #24     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #25     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #26     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #27     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #28     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #29     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #30     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #31     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #32     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #33     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #34     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #35     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #36     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #37     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #38     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (26849): #39     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (26849): #40     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1507:7)
I/flutter (26849): #41     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:766:18)
I/flutter (26849): #42     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:329:19)
I/flutter (26849): #43     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:701:13)
I/flutter (26849): #44     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:268:5)
I/flutter (26849): #45     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:988:15)
I/flutter (26849): #46     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:928:9)
I/flutter (26849): #47     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:840:5)
I/flutter (26849): #51     _invoke (dart:ui/hooks.dart:209:10)
I/flutter (26849): #52     _drawFrame (dart:ui/hooks.dart:168:3)
I/flutter (26849): (elided 3 frames from package dart:async)
I/flutter (26849): 
I/flutter (26849): The following RenderObject was being processed when the exception was fired:
I/flutter (26849):   RenderCustomMultiChildLayoutBox#170ff relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):   creator: CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
I/flutter (26849):   _InkFeatures-[GlobalKey#66af1 ink renderer] ← NotificationListener<LayoutChangedNotification> ←
I/flutter (26849):   PhysicalModel ← AnimatedPhysicalModel ← Material ← PrimaryScrollController ← _ScaffoldScope ←
I/flutter (26849):   Scaffold ← ⋯
I/flutter (26849):   parentData: <none> (can use size)
I/flutter (26849):   constraints: BoxConstraints(w=392.7, 0.0<=h<=Infinity)
I/flutter (26849):   size: Size(392.7, Infinity)
I/flutter (26849): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (26849):   RenderDecoratedBox#d870a NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):     RenderPadding#14ba8 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):       RenderFlex#6e752 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):         RenderSemanticsGestureHandler#36b67 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):           RenderPointerListener#cfb29 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):         RenderClipRect#66eaf NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):           RenderPositionedBox#85283 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):   RenderStack#057e0 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):     RenderTransform#6ab00 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849):       RenderTransform#23709 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (26849): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (26849): Another exception was thrown: _RenderInkFeatures object was given an infinite size during layout.
I/flutter (26849): Another exception was thrown: RenderPhysicalModel object was given an infinite size during layout.
I/flutter (26849): Another exception was thrown: RenderRepaintBoundary object was given an infinite size during layout.
I/flutter (26849): Another exception was thrown: RenderIndexedSemantics object was given an infinite size during layout.
E/flutter (26849): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Cannot hit test a render box that has never been laid out.
E/flutter (26849): The hitTest() method was called on this RenderBox:
E/flutter (26849):   RenderStack#057e0 NEEDS-LAYOUT NEEDS-PAINT
E/flutter (26849): Unfortunately, this object's geometry is not known at this time, probably because it has never been laid out. This means it cannot be accurately hit-tested. If you are trying to perform a hit test during the layout phase itself, make sure you only hit test nodes that have completed layout (e.g. the node's children, after their layout() method has been called).
E/flutter (26849): #0      RenderBox.hitTest.<anonymous closure> (package:flutter/src/rendering/box.dart:1889:11)
E/flutter (26849): #1      RenderBox.hitTest (package:flutter/src/rendering/box.dart:1912:6)
E/flutter (26849): #2      _RenderCustomMultiChildLayoutBox&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultHitTestChildren (package:flutter/src/rendering/box.dart:2256:17)
E/flutter (26849): #3      RenderCustomMultiChildLayoutBox.hitTestChildren (package:flutter/src/rendering/custom_layout.dart:366:12)
E/flutter (26849): #4      RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #5      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #6      RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #7      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #8      RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #9      RenderPhysicalModel.hitTest (package:flutter/src/rendering/proxy_box.dart:1683:18)
E/flutter (26849): #10     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #11     RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #12     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #13     RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #14     _RenderSliverMultiBoxAdaptor&RenderSliver&ContainerRenderObjectMixin&RenderSliverHelpers.hitTestBoxChild (package:flutter/src/rendering/sliver.dart:1509:22)
E/flutter (26849): #15     RenderSliverMultiBoxAdaptor.hitTestChildren (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:481:11)
E/flutter (26849): #16     RenderSliver.hitTest (package:flutter/src/rendering/sliver.dart:1171:11)
E/flutter (26849): #17     RenderSliverPadding.hitTestChildren (package:flutter/src/rendering/sliver_padding.dart:266:20)
E/flutter (26849): #18     RenderSliver.hitTest (package:flutter/src/rendering/sliver.dart:1171:11)
E/flutter (26849): #19     RenderViewportBase.hitTestChildren (package:flutter/src/rendering/viewport.dart:576:43)
E/flutter (26849): #20     RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #21     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #22     RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #23     RenderIgnorePointer.hitTest (package:flutter/src/rendering/proxy_box.dart:2928:37)
E/flutter (26849): #24     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #25     RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #26     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #27     RenderProxyBoxWithHitTestBehavior.hitTest (package:flutter/src/rendering/proxy_box.dart:161:19)
E/flutter (26849): #28     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #29     RenderBox.hitTest (package:flutter/src/rendering/box.dart:1914:11)
E/flutter (26849): #30     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (26849): #31     RenderBox.hitTest (package:flutter

请有人可以告诉我,并帮助我找到解决方法...

1 个答案:

答案 0 :(得分:0)

错误消息提示您需要为列表设置大小。我知道这很模糊,但是您需要做的是用容器包装streamBuilder并给容器固定大小。这是因为您可能会因医院收集而产生许多对象,并且在渲染结果时超出范围时会发生抖动。做这样的事情...

Container(
          height: 200,
          child: StreamBuilder(...

几天前,animatedList也发生了类似的问题。让我知道怎么回事。