Flutter 如何在颤振中动态调整底板的高度?
在我的Flutter 如何在颤振中动态调整底板的高度?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,在我的showModalBottomSheet中,我有一个DraggableScrollableSheet,其中包含内容。当我向上滚动时,我希望内容动态向上滚动,直到有内容为止 但当我向上滚动时,默认情况下,内容会在屏幕的一半左右被切断,我会继续滚动: 但是,当我添加isScrollControlled:false时,内容会一直到顶部,在下面留下空白,这不是我想要的: 以下是不包括默认卡的代码: void _showSettingsPanel() { showModalBottomS
showModalBottomSheet
中,我有一个DraggableScrollableSheet
,其中包含内容。当我向上滚动时,我希望内容动态向上滚动,直到有内容为止
但当我向上滚动时,默认情况下,内容会在屏幕的一半左右被切断,我会继续滚动:
但是,当我添加isScrollControlled:false
时,内容会一直到顶部,在下面留下空白,这不是我想要的:
以下是不包括默认卡的代码:
void _showSettingsPanel() {
showModalBottomSheet<dynamic>(isScrollControlled: false, backgroundColor: Colors.transparent, context: context, builder: (context) {
return DraggableScrollableSheet(
builder: (BuildContext context, ScrollController scrollController) {
return Container(
color: Colors.blue[100],
child: ListView(
controller: scrollController,
children: const <Widget>[
//here would be the cards
],
),
);
},
);
});
}
void\u showSettingsPanel(){
showModalBottomSheet(isScrollControlled:false,backgroundColor:Colors.transparent,context:context,builder:(context){
返回DragableScrollableSheet(
生成器:(BuildContext上下文,ScrollController ScrollController){
返回容器(
颜色:颜色。蓝色[100],
子:ListView(
控制器:滚动控制器,
儿童:康斯特[
//这是卡片
],
),
);
},
);
});
}
包括卡片
void _showSettingsPanel() {
showModalBottomSheet<dynamic>(isScrollControlled: false, backgroundColor: Colors.transparent, context: context, builder: (context) {
return DraggableScrollableSheet(
builder: (BuildContext context, ScrollController scrollController) {
return Container(
color: Colors.blue[100],
child: ListView(
controller: scrollController,
children: const <Widget>[
Card(child: ListTile(title: Text('One-line ListTile'))),
Card(
child: ListTile(
leading: FlutterLogo(),
title: Text('One-line with leading widget'),
),
),
Card(
child: ListTile(
title: Text('One-line with trailing widget'),
trailing: Icon(Icons.more_vert),
),
),
Card(
child: ListTile(
leading: FlutterLogo(),
title: Text('One-line with both widgets'),
trailing: Icon(Icons.more_vert),
),
),
Card(
child: ListTile(
title: Text('One-line dense ListTile'),
dense: true,
),
),
Card(
child: ListTile(
leading: FlutterLogo(size: 56.0),
title: Text('Two-line ListTile'),
subtitle: Text('Here is a second line'),
trailing: Icon(Icons.more_vert),
),
),
Card(
child: ListTile(
leading: FlutterLogo(size: 72.0),
title: Text('Three-line ListTile'),
subtitle: Text(
'A sufficiently long subtitle warrants three lines.'
),
trailing: Icon(Icons.more_vert),
isThreeLine: true,
),
),
],
),
);
},
);
});
}
void\u showSettingsPanel(){
showModalBottomSheet(isScrollControlled:false,backgroundColor:Colors.transparent,context:context,builder:(context){
返回DragableScrollableSheet(
生成器:(BuildContext上下文,ScrollController ScrollController){
返回容器(
颜色:颜色。蓝色[100],
子:ListView(
控制器:滚动控制器,
儿童:康斯特[
卡片(子项:ListTile(标题:Text(‘单行ListTile’)),
卡片(
孩子:ListTile(
前导:flatterlogo(),
标题:文本(“带前导小部件的单行”),
),
),
卡片(
孩子:ListTile(
标题:文本(“带尾随小部件的单行”),
尾随:图标(图标。更多垂直),
),
),
卡片(
孩子:ListTile(
前导:flatterlogo(),
标题:文本(“两个窗口小部件的单行”),
尾随:图标(图标。更多垂直),
),
),
卡片(
孩子:ListTile(
标题:文本(“单行密集列表块”),
是的,
),
),
卡片(
孩子:ListTile(
领先:标志(尺寸:56.0),
标题:文本(“两行列表”),
副标题:文本(“这是第二行”),
尾随:图标(图标。更多垂直),
),
),
卡片(
孩子:ListTile(
领先:标志(尺寸:72.0),
标题:文本(“三行列表”),
字幕:文本(
“足够长的副标题需要三行。”
),
尾随:图标(图标。更多垂直),
伊斯特里琳:是的,
),
),
],
),
);
},
);
});
}
再说一次,有没有办法让DraggableScrollableSheet
动态扩展到有内容的地方
谢谢底部纸张的默认高度是屏幕的一半 要使其动态,只需将
bottomshet
父窗口小部件与wrap()
窗口小部件包装在一起即可
例如:
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
builder: (context) {
//Wrap will set hight dynamicaly
return Wrap(children: [
Container(),
Container(),
Container(),
]);
});