gpt4 book ai didi

flutter - 如何使showBottomSheet的特定部分可滚动

转载 作者:行者123 更新时间:2023-12-03 04:45:41 26 4
gpt4 key购买 nike

我在单击按钮时打开bottomSheet,我希望将其分为三个不同的部分,最后一部分应该是可滚动的。
下面是我的代码,但我溢出了错误

 onTap: (){
scaffoldKey.currentState
.showBottomSheet((context) => Container(
height: MediaQuery.of(context).size.height,
color: Colors.red,

child: Column(
children: <Widget>[
Container(
height: 100,
color: Colors.black,
),
Container(
height: 120,
color: Colors.green,
),
Container(
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: <Widget>[
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'), <---------I added all
these textfield just
for demo(copy-paste).
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('2'),
SizedBox(height: 10,),
Text('3'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,), Text('1'),
SizedBox(height: 10,),
Text('5'),
SizedBox(height: 10,),





],
),
),
)
],
),
));
},

enter image description here

我也尝试过使用SingleChildScrollable Widget作为第三部分,而没有将其包装在容器中,但这也不起作用。

最佳答案

在您希望可滚动的最后一部分中,将SingleChildScrollView用扩展的小部件而不是容器包装,如下所示:

onTap: (){

scaffoldKey.currentState
.showBottomSheet((context) => Container(
height: MediaQuery.of(context).size.height,
color: Colors.red,

child: Column(
children: <Widget>[
Container(
height: 100,
color: Colors.black,
),
Container(
height: 120,
color: Colors.green,
),
Expanded(
/// I removed the height value you set as that is no longer needed
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: <Widget>[
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('2'),
SizedBox(height: 10,),
Text('3'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,),
Text('1'),
SizedBox(height: 10,), Text('1'),
SizedBox(height: 10,),
Text('5'),
SizedBox(height: 10,),
],
),
),
)
],
),
));
},

现在应该工作! :)

关于flutter - 如何使showBottomSheet的特定部分可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62365668/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com