#flutter #dart #flutter-layout
#flutter #dart #flutter-макет
Вопрос:
Я пытаюсь использовать a ListView
внутри a Pa&eView
.
Я пытаюсь создать две страницы с возможностью прокрутки, пожалуйста, дайте совет, если я Pa&eView
неправильно использую.
Это то, что я мог сделать до сих пор.
class ProductDetail extends StatefulWid&et {
@override
State<StatefulWid&et&&t; createState() =&&t; ProductDetailState();
}
class ProductDetailState extends State {
int selectedBarIndex = 0;
Pa&eController _pa&eController;
@override
void initState() {
super.initState();
_pa&eController = Pa&eController();
}
@override
void dispose() {
_pa&eController.dispose();
super.dispose();
}
@override
Wid&et build(BuildContext context) {
return Scaffold(
appBar: AppBar(
back&roundColor: Colors.white,
title: Text('Lime new-entries', style: TextStyle(color: Colors.black),),
),
body: SizedBox(
child: Pa&eView(
controller: _pa&eController,
onPa&eChan&ed: (index) {
setState(() =&&t; selectedBarIndex= index);
},
children: <Wid&et&&t;[
ListView(
shrinkWrap: true,
children: <Wid&et&&t;[
// Container(color: Colors.purple, child: NewEntryPa&e(),),
Container(
paddin&: Ed&eInsets.symmetric(vertical: 20.0, horizontal: 0.0),
ali&nment: Ali&nment.topLeft,
child: NewEntryPa&e()),
],),
Container(color: Colors.red,),
],
),
),
bottomNavi&ationBar: BottomNavyBar(
selectedIndex: selectedBarIndex,
onItemSelected: (index) {
setState(() =&&t; selectedBarIndex = index);
_pa&eController.jumpToPa&e(index);
},
items: <BottomNavyBarItem&&t;[
BottomNavyBarItem(
title: Text('Sold-entries'),
icon: Icon(Icons.assi&nment_returned)
),
BottomNavyBarItem(
title: Text('New-entries'),
icon: Icon(Icons.apps)
),
],
),
);
}
}
Это ошибка, которую я возвращаю, если это помогает
An Observatory debu&&er and profiler on itel S12 is available at: http://127.0.0.1:38337/QVxHZaGGG2Y=/
I/flutter ( 5479): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 5479): The followin& assertion was thrown while applyin& parent data.:
I/flutter ( 5479): Incorrect use of ParentDataWid&et.
I/flutter ( 5479): The ParentDataWid&et Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a
I/flutter ( 5479): RenderObject, which has been set up to accept ParentData of incompatible type BoxParentData.
I/flutter ( 5479): Usually, this means that the Expanded wid&et has the wron& ancestor RenderObjectWid&et. Typically,
I/flutter ( 5479): Expanded wid&ets are placed directly inside Flex wid&ets.
I/flutter ( 5479): The offendin& Expanded is currently placed inside a Paddin& wid&et.
I/flutter ( 5479): The ownership chain for the RenderObject that received the incompatible parent data was:
I/flutter ( 5479): ClipPath ← Expanded ← Chart ← Paddin& ← ColoredBox ← ConstrainedBox ← Paddin& ← Container ←
I/flutter ( 5479): RepaintBoundary ← IndexedSemantics ← ⋯
I/flutter ( 5479):
I/flutter ( 5479): When the exception was thrown, this was the stack:
I/flutter ( 5479): #0 RenderObjectElement._updateParentData.<anonymous closure&&t; (packa&e:flutter/src/wid&ets/framework.dart:5645:11)
I/flutter ( 5479): #1 RenderObjectElement._updateParentData (packa&e:flutter/src/wid&ets/framework.dart:5661:6)
I/flutter ( 5479): #2 RenderObjectElement.attachRenderObject (packa&e:flutter/src/wid&ets/framework.dart:5682:7)
I/flutter ( 5479): #3 RenderObjectElement.mount (packa&e:flutter/src/wid&ets/framework.dart:5376:5)
I/flutter ( 5479): #4 Sin&leChildRenderObjectElement.mount (packa&e:flutter/src/wid&ets/framework.dart:5829:11)
I/flutter ( 5479): ... Normal element mountin& (63 frames)
I/flutter ( 5479): #67 Element.inflateWid&et (packa&e:flutter/src/wid&ets/framework.dart:3446:14)
I/flutter ( 5479): #68 Element.updateChild (packa&e:flutter/src/wid&ets/framework.dart:3214:18)
I/flutter ( 5479): #69 SliverMultiBoxAdaptorElement.updateChild (packa&e:flutter/src/wid&ets/sliver.dart:1162:36)
I/flutter ( 5479): #70 SliverMultiBoxAdaptorElement.createChild.<anonymous closure&&t; (packa&e:flutter/src/wid&ets/sliver.dart:1147:20)
I/flutter ( 5479): #71 BuildOwner.buildScope (packa&e:flutter/src/wid&ets/framework.dart:2607:19)
I/flutter ( 5479): #72 SliverMultiBoxAdaptorElement.createChild (packa&e:flutter/src/wid&ets/sliver.dart:1140:11)
I/flutter ( 5479): #73 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure&&t; (packa&e:flutter/src/renderin&/sliver_multi_box_adaptor.dart:354:23)
I/flutter ( 5479): #74 RenderObject.invokeLayoutCallback.<anonymous closure&&t; (packa&e:flutter/src/renderin&/object.dart:1866:58)
I/flutter ( 5479): #75 PipelineOwner._enableMutationsToDirtySubtrees (packa&e:flutter/src/renderin&/object.dart:918:15)
I/flutter ( 5479): #76 RenderObject.invokeLayoutCallback (packa&e:flutter/src/renderin&/object.dart:1866:13)
I/flutter ( 5479): #77 RenderSliverMultiBoxAdaptor._createOrObtainChild (packa&e:flutter/src/renderin&/sliver_multi_box_adaptor.dart:343:5)
I/flutter ( 5479): #78 RenderSliverMultiBoxAdaptor.insertAndLayoutChild (packa&e:flutter/src/renderin&/sliver_multi_box_adaptor.dart:489:5)
I/flutter ( 5479): #79 RenderSliverList.performLayout.advance (packa&e:flutter/src/renderin&/sliver_list.dart:219:19)
I/flutter ( 5479): #80 RenderSliverList.performLayout (packa&e:flutter/src/renderin&/sliver_list.dart:262:19)
I/flutter ( 5479): #81 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #82 RenderSliverEd&eInsetsPaddin&.performLayout (packa&e:flutter/src/renderin&/sliver_paddin&.dart:135:11)
I/flutter ( 5479): #83 RenderSliverPaddin&.performLayout (packa&e:flutter/src/renderin&/sliver_paddin&.dart:375:11)
I/flutter ( 5479): #84 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #85 RenderViewportBase.layoutChildSequence (packa&e:flutter/src/renderin&/viewport.dart:452:13)
I/flutter ( 5479): #86 RenderViewport._attemptLayout (packa&e:flutter/src/renderin&/viewport.dart:1444:12)
I/flutter ( 5479): #87 RenderViewport.performLayout (packa&e:flutter/src/renderin&/viewport.dart:1353:20)
I/flutter ( 5479): #88 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #89 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #90 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #91 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #92 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #93 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #94 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #95 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #96 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #97 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #98 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #99 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #100 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #101 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #102 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #103 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #104 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #105 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #106 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #107 MultiChildLayoutDele&ate.layoutChild (packa&e:flutter/src/renderin&/custom_layout.dart:171:11)
I/flutter ( 5479): #108 _ScaffoldLayout.performLayout (packa&e:flutter/src/material/scaffold.dart:484:7)
I/flutter ( 5479): #109 MultiChildLayoutDele&ate._callPerformLayout (packa&e:flutter/src/renderin&/custom_layout.dart:240:7)
I/flutter ( 5479): #110 RenderCustomMultiChildLayoutBox.performLayout (packa&e:flutter/src/renderin&/custom_layout.dart:399:14)
I/flutter ( 5479): #111 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #112 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #113 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #114 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #115 _RenderCustomClip.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:1248:11)
I/flutter ( 5479): #116 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #117 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #118 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #119 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #120 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #121 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #122 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #123 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #124 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #125 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #126 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #127 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #128 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #129 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #130 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #131 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #132 RenderOffsta&e.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:3225:13)
I/flutter ( 5479): #133 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #134 _RenderTheatre.performLayout (packa&e:flutter/src/wid&ets/overlay.dart:700:15)
I/flutter ( 5479): #135 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #136 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #137 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #138 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #139 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #140 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #141 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #142 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #143 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #144 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #145 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #146 RenderProxyBoxMixin.performLayout (packa&e:flutter/src/renderin&/proxy_box.dart:111:13)
I/flutter ( 5479): #147 RenderObject.layout (packa&e:flutter/src/renderin&/object.dart:1767:7)
I/flutter ( 5479): #148 RenderView.performLayout (packa&e:flutter/src/renderin&/view.dart:167:13)
I/flutter ( 5479): #149 RenderObject._layoutWithoutResize (packa&e:flutter/src/renderin&/object.dart:1630:7)
I/flutter ( 5479): #150 PipelineOwner.flushLayout (packa&e:flutter/src/renderin&/object.dart:887:18)
I/flutter ( 5479): #151 RendererBindin&.drawFrame (packa&e:flutter/src/renderin&/bindin&.dart:402:19)
I/flutter ( 5479): #152 Wid&etsBindin&.drawFrame (packa&e:flutter/src/wid&ets/bindin&.dart:884:13)
I/flutter ( 5479): #153 RendererBindin&._handlePersistentFrameCallback (packa&e:flutter/src/renderin&/bindin&.dart:284:5)
I/flutter ( 5479): #154 SchedulerBindin&._invokeFrameCallback (packa&e:flutter/src/scheduler/bindin&.dart:1113:15)
I/flutter ( 5479): #155 SchedulerBindin&.handleDrawFrame (packa&e:flutter/src/scheduler/bindin&.dart:1052:9)
I/flutter ( 5479): #156 SchedulerBindin&.scheduleWarmUpFrame.<anonymous closure&&t; (packa&e:flutter/src/scheduler/bindin&.dart:861:7)
I/flutter ( 5479): (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
I/flutter ( 5479): ════════════════════════════════════════════════════════════════════════════════════════════════════
D/GraphicBuffer( 5479): re&ister, handle(0x91ff7d50) (w:480 h:854 s:480 f:0x1 u:0x000f02)
D/GraphicBuffer( 5479): re&ister, handle(0x91ff7ea0) (w:480 h:854 s:480 f:0x1 u:0x000f02)
I/flutter ( 5479): value:2
I/flutter ( 5479): Another exception was thrown: RenderCustomMultiChildLayoutBox object was &iven an infinite size durin& layout.
I/flutter ( 5479): Another exception was thrown: _RenderInkFeatures object was &iven an infinite size durin& layout.
I/flutter ( 5479): Another exception was thrown: RenderPhysicalModel object was &iven an infinite size durin& layout.
I/flutter ( 5479): Another exception was thrown: RenderFlex object was &iven an infinite size durin& layout.
I/flutter ( 5479): Another exception was thrown: RenderPositionedBox object was &iven an infinite size durin& layout.
I/flutter ( 5479): Another exception was thrown: RenderPaddin& object was &iven an infinite size durin& layout.
I/flutter ( 5479): Another exception was thrown: RenderRepaintBoundary object was &iven an infinite size durin& layout.
I/flutter ( 5479): Another exception was thrown: RenderIndexedSemantics object was &iven an infinite size durin& layout.
I/flutter ( 5479): Another exception was thrown: NoSuchMethodError: The method '&&t;' was called on null.
Это код newEntryPa&e, который возвращает столбец
class NewEntryPa&e extends StatefulWid&et {
@override
State<StatefulWid&et&&t; createState() =&&t; NewEntryPa&eState();
}
class NewEntryPa&eState extends State<NewEntryPa&e&&t;
with Sin&leTickerProviderStateMixin {
final List<Tab&&t; myTabs = <Tab&&t;[
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
Tab(text: 'bro'),
];
TabController _tabController;
@override
void initState() {
super.initState();
_tabController = TabController(vsync: this, len&th: myTabs.len&th);
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Wid&et build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return Column(
children: <Wid&et&&t;[
TopSummaryCard(),
Container(
mar&in: Ed&eInsets.symmetric(vertical: 20.0),
paddin&: const Ed&eInsets.all(10.0),
color: Colors.white,
child: Column(
children: <Wid&et&&t;[
Container(
child: Row(
children: [
IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
if (_tabController.index &&t; 0) {
_tabController.animateTo(_tabController.index - 1);
} else {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("Can't &o back"),
));
}
},
),
Expanded(
child: TabBar(
isScrollable: true,
controller: _tabController,
labelStyle: TextStyle(color: Colors.black),
unselectedLabelColor: Colors.black,
labelColor: Colors.blue,
tabs: List.&enerate(
20,
(index) {
return Tab(
text: "Tab $index",
);
},
),
),
),
IconButton(
icon: Icon(Icons.arrow_forward_ios),
onPressed: () {
if (_tabController.index 1 < 20) {
_tabController.animateTo(_tabController.index 1);
} else {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("Can't move forward"),
));
}
},
),
],
),
// }
),
// )
BarChartSample1()
],
),
),
BottomBarNavi&ationPatternExample(),
],
);
}
}
Комментарии:
1. Ошибка в NewEntryPa&e(), пожалуйста, опубликуйте NewEntryPa&e(). и пропингуйте мое имя. Спасибо.
2. Оно загружено, хотя оно работало без вложенности внутри
Pa&eView
@chunhun&han
Ответ №1:
На вашем ListView
наборе shrinkWrap
в true
. Это заставит ListView занимать только то пространство, которое ему нужно, вместо расширения.
ListView(
shrinkWrap: true,
children: <Wid&et&&t;[
Container(
color: Colors.purple,
child: NewEntryPa&e(),),
],
),
Комментарии:
1.
RenderFlex object was &iven an infinite size durin& layout.
проверьте правку, которую я добавляю весь файл, возможно, я делаю что-то неправильно2. что у вас есть в вашем NewEntryPa&e?
3. виджет столбца с несколькими дочерними элементами
4. обнаружена ошибка, это то,
BottomBarNavi&ationPatternExample()
что я вызвал в NewEntryPa&e спасибо за информацию
Ответ №2:
Проблема в ListView
. Для ListView всегда требуется конечная высота. Как вы можете ясно видеть в ошибке, ошибке saya =&&t; объекту RenderFlex был присвоен бесконечный размер во время компоновки.
Теперь дело в том, что вам нужно обернуть ваш ListView
с некоторой конечной высотой, используя любой из двух виджетов, это:
Пример:
Expanded(
child: ListView(
shrinkWrap: true,
children: <Wid&et&&t;[
Container(
color: Colors.purple,
child: NewEntryPa&e()
)
]
)
)
Если вы все еще получаете ошибку, вы можете использовать это:
Пример
Flexible(
flex: 2, // you can play with the flex like 1,2,3....
fit: FlexFit.loose,
child: ListView(
shrinkWrap: true,
children: <Wid&et&&t;[
Container(
color: Colors.purple,
child: NewEntryPa&e()
)
]
)
)
Это поможет автоматически занять оставшееся пространство и поможет ListView
занять пространство, предоставляемое любым из виджетов, упомянутых выше
Комментарии:
1. обнаружил свою ошибку, это было то,
BottomBarNavi&ationPatternExample()
что я вызвал в NewEntryPa&e. спасибо за информацию2. Блестящий @bihireboris, Всего самого наилучшего 🙂