How to send data to Modal bottom sheet in Flutter?

This Article is posted by seven.srikanth at 3/6/2019 5:28:04 PM



<p id="dcdcaa;](_showModalSheet(_index);" color:="" _index="_index+color:">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. This is how it looks like. ![](https://fluttercentral.com/Uploads/2f3c5778-6182-48b6-ad56-eeee6682a5d2.gifwidth="50%height="auto]( Below is an example code of how to send data to Modal bottom sheet in Flutter. All we are doing is a calling a function ShowModalBottomSheet wrapper inside setState to send data into the function. We are also incrementing the number by one to see how the value increments as we continue to open the Modal sheet. 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. color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre-wrap;](color: #569cd6;](import color: #ce9178;]('package:flutter/material.dart'; color: #569cd6;](void color: #dcdcaa;](main() color: #569cd6;](class color: #4ec9b0;](ModalBottomSheetDemo color: #569cd6;](extends color: #4ec9b0;](StatefulWidget { color: #569cd6;](@override color: #4ec9b0;](_ModalBottomSheetDemoState color: #dcdcaa;](createState() => color: #4ec9b0;](_ModalBottomSheetDemoState();} color: #569cd6;](class color: #4ec9b0;](_ModalBottomSheetDemoState color: #569cd6;](extends color: #4ec9b0;](State { color: #569cd6;](int _index = color: #b5cea8;](0; color: #569cd6;](void color: #dcdcaa;](_showModalSheet(color: #569cd6;](int i) { color: #dcdcaa;](showModalBottomSheet(context: context, builder: (builder) { color: #c586c0;](return color: #4ec9b0;](Container( child: color: #4ec9b0;](Text(color: #ce9178;]('You have opened this Modal $color: #9cdcfe;](icolor: #ce9178;]( times..'), padding: color: #4ec9b0;](EdgeInsets.color: #dcdcaa;](all(color: #b5cea8;](40.0), ); }); } color: #569cd6;](@override color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) { color: #c586c0;](return color: #4ec9b0;](Scaffold( appBar: color: #4ec9b0;](AppBar( title: color: #569cd6;](const color: #4ec9b0;](Text(color: #ce9178;]('Modal bottom sheet') ), body: color: #4ec9b0;](Center( child: color: #4ec9b0;](RaisedButton( onPressed: () { color: #dcdcaa;](setState(() ); }, child: color: #569cd6;](const color: #4ec9b0;](Text(color: #ce9178;]('Show Modal Bottom Sheet') ) ) ); }} Please let me know if you have any further queries. Thanks,Srikanth</p>


Tags: Send data to Modal bottom sheet; setState example;








0 Comments
Login to comment.
Recent Comments