Filter by Widgets


How to create a Modal bottom sheet in Flutter?

This Article is posted by seven.srikanth at 05-02-2019 00:48:57


A modal bottom sheet is an alternative to a menu or a dialog and prevents the user from interacting with the rest of the app.
If you are looking out for an example on, How to send data to Modal bottom sheet in Flutter, check this article. https://fluttercentral.com/Articles/Post/1110
Before going further, lets get some basics on bottom sheets.
There are two kinds of bottom sheets in material design: Persistent and Modal. 
In this example, we are going to see Modal type. 
If you want to check out about persistent, check this article here. https://fluttercentral.com/Articles/Post/1149
This is how the final output of this Modal Bottom Sheet example is going to look like. 
Below is an example code of how to create a Modal bottom sheet in Flutter. All we are doing is a calling a function ShowModalBottomSheet and building a widget over there.  This is very simple as shown in the below example.
Code from Main.dart file. In order to run this project locally, all you need to do is to create a Project and copy paste the below code to Lib\main.dart file.
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(home:ModalBottomSheetDemo()));
}
class ModalBottomSheetDemo extends StatefulWidget {
@override
_ModalBottomSheetDemoState createState() => _ModalBottomSheetDemoState();
}
class _ModalBottomSheetDemoState extends State<ModalBottomSheetDemo> {
void _showModalSheet() {
showModalBottomSheet(context: context, builder: (builder) {
return Container(
child: Text('Hello From Modal Bottom Sheet'),
padding: EdgeInsets.all(40.0),
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Modal bottom sheet')
),
body: Center(
child: RaisedButton(
onPressed: _showModalSheet,
child: const Text('Show Modal Bottom Sheet')
)
)
);
}
}
Please let me know if you have any further queries.
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

Error: The name 'RangeSlider' is defined in the libraries 'package:flutter/src/material/range_slider.dart' and 'package:flutter_range_slider/src/flutter_range_slider.dart'.

Check out this article on Error: The name 'RangeSlider' is defined in the libraries 'package:flutter/src/material/range_slider.dart' and 'package:flutter_range_slider/src/flutter_range_slider.dart'.

Read full post

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

© 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.