Flutter ListView Builder渲染溢出问题求助
Flutter ListView Builder 渲染溢出问题
我在用ListView Builder时碰到了渲染溢出问题,确认问题出在ListView上。试过用Expanded组件包裹ListView,但没解决。以下是相关代码片段和报错信息:
@override Widget build(BuildContext context) { debugPrint('Exercises in build: $exercises'); return AlertDialog( title: const Text('Add Exercise'), content: exercises == null ? const Center(child: CircularProgressIndicator()) : exercises!.isEmpty ? const Center(child: Text('No exercises found.')) : Column( mainAxisSize: MainAxisSize.min, children: [ TextField( controller: widget.controller, decoration: const InputDecoration(labelText: 'Search Exercise'), onChanged: (value) { searchText.value = value; }, ), const SizedBox(height: 16), Flexible( child: ValueListenableBuilder<String>( valueListenable: searchText, builder: (context, value, child) { final filteredExercises = exercises! .where((exercise) => exercise.name.toLowerCase().contains(value.toLowerCase())) .toList(); return ListView.builder( shrinkWrap: true, // Ensures proper sizing itemCount: filteredExercises.length, itemBuilder: (context, index) { return ListTile( title: Text(filteredExercises[index].name), onTap: () { widget.controller.text = filteredExercises[index].name; Navigator.of(context).pop(); widget.onAdd(filteredExercises[index]); }, ); }, ); }, ), ), ], ), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(); widget.controller.clear(); }, child: const Text('Cancel'), ), ], ); }
报错信息
触发异常时正在处理以下RenderObject: RenderIntrinsicWidth#85b9c relayoutBoundary=up6 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: <none> (can use size) constraints: BoxConstraints(280.0<=w<=312.7, 0.0<=h<=702.2) size: Size(280.0, 702.2) stepWidth: null stepHeight: null child: RenderFlex#3ede5 relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: <none> (can use size) constraints: BoxConstraints(w=280.0, 0.0<=h<=702.2) size: Size(280.0, 702.2) direction: vertical mainAxisAlignment: start mainAxisSize: min crossAxisAlignment: stretch verticalDirection: down child 1: RenderPadding#88821 relayoutBoundary=up8 NEEDS-PAINT parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size) constraints: BoxConstraints(w=280.0, 0.0<=h<=Infinity) size: Size(280.0, 56.0) padding: EdgeInsets(24.0, 24.0, 24.0, 0.0) textDirection: ltr child: RenderSemanticsAnnotations#9ccfb relayoutBoundary=up9 NEEDS-PAINT parentData: offset=Offset(24.0, 24.0) (can use size) constraints: BoxConstraints(w=232.0, 0.0<=h<=Infinity) semantic boundary size: Size(232.0, 32.0) child: RenderParagraph#73c17 relayoutBoundary=up10 NEEDS-PAINT parentData: <none> (can use size) constraints: BoxConstraints(w=232.0, 0.0<=h<=Infinity) size: Size(232.0, 32.0) textAlign: start textDirection: ltr softWrap: wrapping at box width overflow: clip locale: en_US maxLines: unlimited child 2: RenderPadding#cdc90 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: offset=Offset(0.0, 56.0); flex=1; fit=FlexFit.loose (can use size) constraints: BoxConstraints(w=280.0, 0.0<=h<=574.2) size: Size(280.0, 574.2) padding: EdgeInsets(24.0, 16.0, 24.0, 24.0) textDirection: ltr child: RenderSemanticsAnnotations#b5239 relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: offset=Offset(24.0, 16.0) (can use size) constraints: BoxConstraints(w=232.0, 0.0<=h<=534.2) semantic boundary size: Size(232.0, 534.2) child: RenderClipRect#5e573 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: <none> constraints: MISSING size: MISSING child 3: RenderPadding#390e9 relayoutBoundary=up8 NEEDS-PAINT parentData: offset=Offset(0.0, 630.2); flex=null; fit=null (can use size) constraints: BoxConstraints(w=280.0, 0.0<=h<=Infinity) size: Size(280.0, 72.0) padding: EdgeInsets(24.0, 0.0, 24.0, 24.0) textDirection: ltr child: _RenderOverflowBar#9e616 relayoutBoundary=up9 NEEDS-PAINT parentData: offset=Offset(24.0, 0.0) (can use size) constraints: BoxConstraints(w=232.0, 0.0<=h<=Infinity) size: Size(232.0, 48.0) spacing: 8.0 overflowAlignment: end textDirection: ltr child 1: RenderSemanticsAnnotations#563d4 relayoutBoundary=up10 NEEDS-PAINT parentData: offset=Offset(157.3, 0.0) (can use size) constraints: BoxConstraints(0.0<=w<=232.0, 0.0<=h<=Infinity) semantic boundary size: Size(74.7, 48.0) RenderObject: RenderIntrinsicWidth#85b9c relayoutBoundary=up6 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: <none> (can use size) constraints: BoxConstraints(280.0<=w<=312.7, 0.0<=h<=702.2) size: Size(280.0, 702.2) stepWidth: null stepHeight: null child: RenderFlex#3ede5 relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: <none> (can use size) constraints: BoxConstraints(w=280.0, 0.0<=h<=702.2) size: Size(280.0, 702.2) direction: vertical mainAxisAlignment: start mainAxisSize: min crossAxisAlignment: stretch verticalDirection: down child 1: RenderPadding#88821 relayoutBoundary=up8 NEEDS-PAINT parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size) constraints: BoxConstraints(w=280.0, 0.0<=h<=Infinity) size: Size(280.0, 56.0) padding: EdgeInsets(24.0, 24.0, 24.0, 0.0) textDirection: ltr child: RenderSemanticsAnnotations#9ccfb relayoutBoundary=up9 NEEDS-PAINT parentData: offset=Offset(24.0, 24.0) (can use size) constraints: BoxConstraints(w=232.0, 0.0<=h<=Infinity) semantic boundary size: Size(232.0, 32.0) child: RenderParagraph#73c17 relayoutBoundary=up10 NEEDS-PAINT parentData: <none> (can use size) constraints: BoxConstraints(w=232.0, 0.0<=h<=Infinity) size: Size(232.0, 32.0) textAlign: start textDirection: ltr softWrap: wrapping at box width overflow: clip locale: en_US maxLines: unlimited child 2: RenderPadding#cdc90 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: offset=Offset(0.0, 56.0); flex=1; fit=FlexFit.loose (can use size) constraints: BoxConstraints(w=280.0, 0.0<=h<=574.2) size: Size(280.0, 574.2) padding: EdgeInsets(24.0, 16.0, 24.0, 24.0) textDirection: ltr child: RenderSemanticsAnnotations#b5239 relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: offset=Offset(24.0, 16.0) (can use size) constraints: BoxConstraints(w=232.0, 0.0<=h<=534.2) semantic boundary size: Size(232.0, 534.2) child: RenderClipRect#5e573 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: <none> constraints: MISSING size: MISSING child 3: RenderPadding#390e9 relayoutBoundary=up8 NEEDS-PAINT parentData: offset=Offset(0.0, 630.2); flex=null; fit=null (can use size) constraints: BoxConstraints(w=280.0, 0.0<=h<=Infinity) size: Size(280.0, 72.0) padding: EdgeInsets(24.0, 0.0, 24.0, 24.0) textDirection: ltr child: _RenderOverflowBar#9e616 relayoutBoundary=up9 NEEDS-PAINT parentData: offset=Offset(24.0, 0.0) (can use size) constraints: BoxConstraints(w=232.0, 0.0<=h<=Infinity) size: Size(232.0, 48.0) spacing: 8.0 overflowAlignment: end textDirection: ltr child 1: RenderSemanticsAnnotations#563d4 relayoutBoundary=up10 NEEDS-PAINT parentData: offset=Offset(157.3, 0.0) (can use size) constraints: BoxConstraints(0.0<=w<=232.0, 0.0<=h<=Infinity) semantic boundary size: Size(74.7, 48.0)
内容的提问来源于stack exchange,提问作者Spartis
相关产品推荐
相关产品推荐

