所以基本上我希望能够在按下 Button 时更改 DraggableScrollableSheet 的可见高度。就像一个箭头,允许用户向上和向下提升特定高度。
到目前为止,我有以下代码:
return Scaffold(
appBar: AppBar(),
body: Stack(
children: <Widget>[
Placeholder(),
DraggableScrollableSheet(
minChildSize: .1,
initialChildSize: .1,
maxChildSize: .5,
builder: (context, scrollController) {
return Container(
height: size.height / 2,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
child: SingleChildScrollView(
controller: scrollController,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_upward),
onPressed: () {
print('THIS IS WHERE I WANT TO OPEN THE SHEET');
},
),
Container(
height: size.height / 2.75,
child: PageView(
controller: _pageController,
onPageChanged: (int page) {
setState(() {
currentIndex = page;
});
},
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[Text('Page 1')]),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[Text('Page 2')]),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[Text('Page 3')]),
],
),
),
],
),
),
);
},
),
],
),
);
我已经尝试过 scrollController.jumpTo() 和 scrollController.animateTo() 但他们所做的只是移动 IconButton 而不是 DraggableScrollableSheet。
IconButton(
icon: Icon(Icons.arrow_upward),
onPressed: () {
scrollController.jumpTo(20);
scrollController.animateTo(20, duration: null, curve: null);
},
),