gpt4 book ai didi

Flutter DraggableScrollableSheet 在按下按钮时不显示

转载 作者:IT王子 更新时间:2023-10-29 06:37:55 31 4
gpt4 key购买 nike

我想在我的应用程序上使用 DraggableScrollableSheet 小部件,当我像下面的代码一样使用它时,可以毫无问题地显示:

class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('DraggableScrollableSheet'),
),
body: SizedBox.expand(
child: DraggableScrollableSheet(
builder: (BuildContext context, ScrollController scrollController) {
return Container(
color: Colors.blue[100],
child: ListView.builder(
controller: scrollController,
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(title: Text('Item $index'));
},
),
);
},
),
),
);
}
}

但是当我想通过按下例如不显示的floatingActionButton来显示

floatingActionButton: GestureDetector(
child: FloatingActionButton(
child: Icon(
Icons.add,
size: 35.0,
),
elevation: 5,
backgroundColor: Colors.deepOrange,
foregroundColor: Colors.white,
onPressed: (){
SizedBox.expand(child: DraggableScrollableSheet(
builder: (BuildContext context, ScrollController scrollController) {
return Container(
color: Colors.blue[100],
child: ListView.builder(
controller: scrollController,
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(title: Text('Item $index'));
},
),
);
},
));
},
),
),

最佳答案

enter image description here


如果你想在 showModalBottomSheet 中使用 DraggableScrollableSheet,你可以简单地调用这个函数。

void _showSheet() {
showModalBottomSheet(
context: context,
isScrollControlled: true, // set this to true
builder: (_) {
return DraggableScrollableSheet(
expand: false,
builder: (_, controller) {
return Container(
color: Colors.blue[500],
child: ListView.builder(
controller: controller, // set this too
itemBuilder: (_, i) => ListTile(title: Text('Item $i')),
),
);
},
);
},
);
}

关于Flutter DraggableScrollableSheet 在按下按钮时不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57233622/

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