Reputation: 3217
In my flutter application I have a bottom sheet which gets shown with some initial height say 100. I would like to increase the height of the sheet (say may be 500 or go full screen) when user interacts with it (may be a gesture detection or clicking on a button on the sheet)
Is it possible to change the height of the sheet after it is loaded.
My bottomsheet is something like
Widget _bottomSheetContainer(BuildContext context) {
return Container(
height: 100,
decoration: BoxDecoration(
border:
Border(top: BorderSide(color: Theme.of(context).dividerColor))),
child: Row(children: [
Expanded(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text('Some text here!'),
)
),
Expanded(
child: IconButton(
icon: Icon(Icons.arrow_upward),
// color: themeData.primaryColor,
onPressed: () => _onPressed(context)
),
),
]));
}
_onPressed(BuildContext context) {
BottomSheet w = context.widget;
// Can we change the container height (from 100 to 500) that's part of the bottom sheet from here?
}
Upvotes: 1
Views: 7150
Reputation: 14487
You would need to make sure your widget is stateful widget, then you can update it's instance parameters using setState(() => ...)
, and flutter will update the rendered results.
class _WidgetState extends State<Widget> {
double height = 200.0; // starting height value
Widget build() {
<...>
Container(
height: height,
<...>
}
_onPressed(BuildContext context) {
BottomSheet w = context.widget;
// Can we change the container height (from 100 to 500) that's part of the bottom sheet from here?
setState({
height = 300.0; // new height value
})
}
}
Upvotes: 3