Skip to content

Instantly share code, notes, and snippets.

@ritvij-saxena
Last active June 26, 2020 20:53
Show Gist options
  • Select an option

  • Save ritvij-saxena/4726b3a834b8aa4afb7305eda2c970da to your computer and use it in GitHub Desktop.

Select an option

Save ritvij-saxena/4726b3a834b8aa4afb7305eda2c970da to your computer and use it in GitHub Desktop.
Programmatically open and close ExpansionTile Widget. [issue-example]
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyWidget(),
);
}
}
class MyWidget extends StatefulWidget{
@override
MyWidgetState createState()=> MyWidgetState();
}
class MyWidgetState extends State<MyWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Container(
width: 375,
height: 100,
child: Card(
elevation: 5.0,
child: Center(
child: ExpansionTile(
title: Text('Directions'),
onExpansionChanged: (val) {
if(val){
expandSheet(context);
}else{
setState((){val=false;});
}
})))),
appBar: AppBar(title: Text('Bottom Modal Sheet')),
body: Container());
}
void expandSheet(context) {
showModalBottomSheet(
context: context,
builder: (context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.white, actions: [
IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(Icons.close, color: Colors.black))
]),
body: ListView(shrinkWrap: true, children:[
SizedBox(height: 20),
Card(
child: ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text('item 1'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(
color: Colors.orange,
onPressed: () {},
child: Text('Accept')),
RaisedButton(onPressed: () {}, child: Text('Reject')),
])
],
))),
Card(
child: ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text('item 2'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(
color: Colors.orange,
onPressed: () {},
child: Text('Accept')),
RaisedButton(onPressed: () {}, child: Text('Reject')),
])
],
))),
Card(
child: ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text('item 3'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(
color: Colors.orange,
onPressed: () {},
child: Text('Accept')),
RaisedButton(onPressed: () {}, child: Text('Reject')),
])
],
))),
Card(
child: ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text('item 4'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(
color: Colors.orange,
onPressed: () {},
child: Text('Accept')),
RaisedButton(onPressed: () {}, child: Text('Reject')),
])
],
))),
Card(
child: ListTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text('item 5'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(
color: Colors.orange,
onPressed: () {},
child: Text('Accept')),
RaisedButton(onPressed: () {}, child: Text('Reject')),
])
],
))),
]));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment