listview ne fonctionne pas dans ExpansionTile
J'ai essayé d'afficher un listview.builder dans ExpansionTile mais cela lève quelques exceptions
âââ¡ EXCEPTION CAUGHT BY RENDERING LIBRARY ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ I/flutter ( 8182): The following assertion was thrown during performResize(): I/flutter ( 8182): Vertical viewport was given unbounded height. I/flutter ( 8182): Viewports expand in the scrolling direction to fill their container.In this case, a vertical I/flutter ( 8182): viewport was given an unlimited amount of vertical space in which to expand. This situation I/flutter ( 8182): typically happens when a scrollable widget is nested inside another scrollable widget. I/flutter ( 8182): If this widget is always nested in a scrollable widget there is no need to use a viewport because I/flutter ( 8182): there will always be enough vertical space for the children. In this case, consider using a Column I/flutter ( 8182): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size I/flutter ( 8182): the height of the viewport to the sum of the heights of its children. I/flutter ( 8182):
Je veux réaliser comme ça https://imgur.com/a/0lubABC
Card( child: ExpansionTile( leading: Icon( Icons.stars, color: Colors.pinkAccent, ), title: Text('Reviews', style: Theme.of(context).textTheme.title, ), children: [ ListView.builder( itemCount: 5, itemBuilder: (_, i) { return (Text('item $i')); }) ], ), ),
3 Réponses :
La taille verticale de votre ListView
est illimitée, ce qui rend impossible le rendu. Définissez la propriété shrinkWrap
de ListView
à true
pour contourner ce problème.
merci cela fonctionne mais cela lève cette exception chaque fois que je fais défiler ExpansionTile `` `` [ERROR: flutter / shell / common / shell.cc (184)] Dart Error: Unhandled exception: E / flutter (8182): 'package: flutter / src / widgets / page_view.dart ': Échec de l'assertion: ligne 96 pos 7:' positions.isNotEmpty ': PageController.page n'est pas accessible avant qu'une PageView soit construite avec elle. E / flutter (8182): # 0 _AssertionError._doThrowNew (dart: core / runtime / liberrors_patch.dart: 40: 39) E / flutter (8182): # 1 _AssertionError._throwNew (dart: core / runtime / liberrors_patch.dart: 36: 5) ''
c'est encore l'exception [ERREUR: flutter / shell / common / shell.cc (184)] Dart Error: Exception non gérée: E / flutter (8182): 'package: flutter / src / widgets / page_view.dart' : Échec de l'assertion: ligne 96 pos 7: 'positions.isNotEmpty': PageController.page n'est pas accessible avant qu'une PageView soit construite avec elle. E / flutter (8182): # 0 _AssertionError._doThrowNew (dart: core / runtime / liberrors_patch.dart: 40: 39) E / flutter (8182): # 1 _AssertionError._throwNew (dart: core / runtime / liberrors_patch.dart: 36: 5)
Cela doit être autre chose dans votre interface utilisateur. Je ne vois aucune PageView
nulle part dans votre code.
Ajoutez à la fois un film rétractable et un contrôleur à ListView.builder
final ScrollController _scrollController = ScrollController(); ListView.builder( controller: _scrollController, shrinkWrap: true, ...
Aucune des solutions ci-dessus ne fonctionne comme prévu. J'ai donc résolu le problème. Vous devez l'utiliser dans Listview.builder () dans les enfants de ExpansionTile :
ExpansionTile( onExpansionChanged: (e){ //Your code }, title: Text("You title text"), children: [ ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), scrollDirection: Axis.vertical, itemCount: items.length, itemBuilder: (BuildContext context, int index){ return Text(items[index]); } ) ], ),
Code complet:
shrinkWrap: true, physics: NeverScrollableScrollPhysics(),
ajoutez
shrinkWrap: true,
dansListView.builder