showmodalbottomsheet with listView.builder不起作用的动态高度
我正在尝试根据内容大小创建底部表格,但不起作用。在表格中,我使用了以下小部件容器 - > column-> listView Builder。
我尝试了以下选项,但仍未做出任何例外。
isScrollControlled: true,
listView属性:缩水:true,
,并使用 wrap 窗口小部件检查也无法正常工作。
Wrap 没有 listView 的小部件正在工作。
请找到代码:
class BottomStringlistController {
var selectedValue = "";
void showSheet(BuildContext context, List<String> values, String currentTitle, {required Function(String value) onCompletion}){
var bottomSheet = showModalBottomSheet<void>(
// isScrollControlled: true,
backgroundColor: Colors.transparent,
context: context,
builder: (BuildContext context) {
return
Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(15.0),
),
),
child:
Padding(
padding: const EdgeInsets.all(15.0),
child:
SingleChildScrollView(
child: Expanded(
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
currentTitle.toUpperCase(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: getProportionateScreenWidth(14),
fontWeight: FontWeight.bold,
color: kPrimaryColor,
),
),
const Spacer(),
IconButton(onPressed:(){
Navigator.pop(context);
},
icon: const Icon(Icons.close,color: kPrimaryColor,),
),
],
),
const Divider(color: kPrimaryColor,),
SizedBox(height: getProportionateScreenWidth(15),),
ListView.builder(
shrinkWrap: true,
itemCount: values.length,
itemBuilder: (context, index){
return GestureDetector(
onTap: (){
selectedValue = values[index];
Navigator.pop(context);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(values[index].toUpperCase(),
textAlign: TextAlign.start,
style: TextStyle(
fontSize: getProportionateScreenWidth(12),
fontWeight: FontWeight.normal,
color: Colors.black
),
),
const SizedBox(height: 10),
],
),
);
},
),
],
),
),
),
),
);
},
).whenComplete(() {
onCompletion(selectedValue);
});
}
}
ss附件:
我正在学习flutter and Noob。
我的要求如下:
假设我的 sheet 必须根据内容调整大小。如果超过10,则表必须显示默认尺寸带有滚动以剩余数据...我希望您能得到我的问题
I am trying to create BottomSheet based on content size but does not working. In Sheet i have used following widgets Container->Column->ListView Builder.
I tried following options but still not working as excepted.
isScrollControlled: true,
ListView Property : shrinkWrap: true,
and checked With Wrap widget also not working.
Wrap widget without listview is Working.
Please find the code :
class BottomStringlistController {
var selectedValue = "";
void showSheet(BuildContext context, List<String> values, String currentTitle, {required Function(String value) onCompletion}){
var bottomSheet = showModalBottomSheet<void>(
// isScrollControlled: true,
backgroundColor: Colors.transparent,
context: context,
builder: (BuildContext context) {
return
Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(15.0),
),
),
child:
Padding(
padding: const EdgeInsets.all(15.0),
child:
SingleChildScrollView(
child: Expanded(
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
currentTitle.toUpperCase(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: getProportionateScreenWidth(14),
fontWeight: FontWeight.bold,
color: kPrimaryColor,
),
),
const Spacer(),
IconButton(onPressed:(){
Navigator.pop(context);
},
icon: const Icon(Icons.close,color: kPrimaryColor,),
),
],
),
const Divider(color: kPrimaryColor,),
SizedBox(height: getProportionateScreenWidth(15),),
ListView.builder(
shrinkWrap: true,
itemCount: values.length,
itemBuilder: (context, index){
return GestureDetector(
onTap: (){
selectedValue = values[index];
Navigator.pop(context);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(values[index].toUpperCase(),
textAlign: TextAlign.start,
style: TextStyle(
fontSize: getProportionateScreenWidth(12),
fontWeight: FontWeight.normal,
color: Colors.black
),
),
const SizedBox(height: 10),
],
),
);
},
),
],
),
),
),
),
);
},
).whenComplete(() {
onCompletion(selectedValue);
});
}
}
SS Attached :
I am learning flutter and noob at it.
My requirement like below:
Assume that i have less than 10 values Sheet has to adjust its size based on content. If more than 10, Sheet has to show default size with Scroll for remaining data... I hope u got my questions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此示例将帮助您根据项目大小构建ShowModalBottomSheet,用ListView.seprated包装。
This example will help you to build showModalBottomSheet according to items size, Wrap with Listview.seprated
更新的答案
Updated answer