Filter by Widgets


How to create a persistent bottom sheet in Flutter?

This Article is posted by seven.srikanth@gmail.com at 05-06-2019 03:45:02

In this article, I'm going to share an example code for persistent bottom sheet in Flutter.

Before seeing this code, here is the output of this app. 

Key things to note here are that touches on the empty area of the screen don't take away the bottom sheet. 

If you want an alternate behavior where touches on the empty area of the screen should take away the bottom sheet, check this example. https://fluttercentral.com/Articles/Post/1081

Another example, showing how to send data to the model sheet. https://fluttercentral.com/Articles/Post/1110 



Here is the full code of this sample. In order to run this, copy paste this code into main.dart file in your newly created flutter project. 

import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

void _showBottomSheetCallback() {
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Colors.black)),
color: Colors.grey
),
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text('This is a Material persistent bottom sheet. Drag downwards to dismiss it.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24.0,
),
),
),
);
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home:Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: const Text('Persistent bottom sheet')
),
body: Center(
child: RaisedButton(
onPressed: _showBottomSheetCallback,
child: const Text('Show Persistent Bottom Sheet')
)
)
),
);
}
}




Hope this is helpful.

Thanks,
Srikanth

0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.




Recent articles

How to create a persistent bottom sheet in Flutter?

Check out this article on How to create a persistent bottom sheet in Flutter?

Read full post

How to draw a Decorative Horizontal line in Flutter?

Check out this article on How to draw a Decorative Horizontal line in Flutter?

Read full post

How to fetch an Image from Internet in Flutter

Check out this article on How to fetch an Image from Internet in Flutter

Read full post

ListView with Images from the Internet

Check out this article on ListView with Images from the Internet

Read full post

How to show Tooltip in Flutter?

Check out this article on How to show Tooltip in Flutter?

Read full post

How to create BottomNavigationBar in flutter?

Check out this article on How to create BottomNavigationBar in flutter?

Read full post

How to add actions to Appbar?

Check out this article on How to add actions to Appbar?

Read full post

How to open dart devtools in VS code?

Check out this article on How to open dart devtools in VS code?

Read full post

Accessibility features in flutter

Check out this article on Accessibility features in flutter

Read full post

How to create a Slider in Flutter?

Check out this article on How to create a Slider in Flutter?

Read full post

© 2018 - Fluttercentral | Email to me - Seven.srikanth@gmail.com

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License , and code samples are licensed under the BSD License.