Skip to content

Instantly share code, notes, and snippets.

@adityapatnaik
Last active September 24, 2019 10:00
Show Gist options
  • Save adityapatnaik/56bb11ff5b5fd2bc3fc5bcb9fbdea78c to your computer and use it in GitHub Desktop.
Save adityapatnaik/56bb11ff5b5fd2bc3fc5bcb9fbdea78c to your computer and use it in GitHub Desktop.
showModalBottomSheet Widget
import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false, // to remove debug flag
home: Scaffold(
resizeToAvoidBottomPadding: false,
//backgroundColor: Colors.white,
body: SafeArea(
child: MyHome()
), // SafeArea
), // Scaffold
); // MaterialApp
}
}
//BottomSheet
class MyHome extends StatefulWidget {
@override
_MyHomeState createState() => _MyHomeState();
}
class _MyHomeState extends State<MyHome> {
BottomSheetApp modal = new BottomSheetApp();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(child:Text('Hello!',style: TextStyle(fontSize: 72.0,fontWeight: FontWeight.w100 ),))
),
floatingActionButton: FloatingActionButton(
onPressed: () => modal.mainBottomSheet(context),
child: Icon(Icons.message),
),
);
}
}
import 'package:flutter/material.dart';
class BottomSheetApp{
ScrollController _controller = ScrollController();
mainBottomSheet(BuildContext context){
showModalBottomSheet(
//isScrollControlled: true, //bottomsheet goes full screen, if bottomsheet has a scrollable widget such as a listview as a child.
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
context: context,
builder: (BuildContext context){
return
Padding(
padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 10.0),
child: ListView(
reverse: true,
controller: _controller,
scrollDirection: Axis.vertical,
children: <Widget>[
_createTile(context, 'Ok!' , Icons.message , _action1),
_createTile(context, 'Google' , Icons.message , _action1),
_createTile(context, 'Say Hi!' , Icons.message , _action1),
GridView.builder(
itemCount:9,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder:(BuildContext context, int index){
return Card(
color: Colors.blue[(index % 9) * 100],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
child: Container(
height: 20.0,
width: 20.0,
child: Center(child:Text('hello'),),
),
);
},
//padding,
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3,),
),
],
),
);
}
);
}
}
ListTile _createTile(BuildContext context,String name,IconData icon,Function action){
return ListTile(
leading: Icon(icon),
title: Text(name),
onTap: (){
Navigator.pop(context);
action();
},
);
}
_action1(){
print('action 1');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment