Created
May 28, 2021 10:39
-
-
Save IsmailAlamKhan/b5c5278577e16a22a8bf8016a2650787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Material App', | |
home: Home(), | |
); | |
} | |
} | |
class Home extends StatefulWidget { | |
const Home({ | |
Key? key, | |
}) : super(key: key); | |
@override | |
_HomeState createState() => _HomeState(); | |
} | |
class _HomeState extends State<Home> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('hello')), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: [ | |
Button(), | |
Button(), | |
Button(), | |
Button(), | |
Button(), | |
Button(), | |
], | |
), | |
), | |
); | |
} | |
} | |
class Button extends StatefulWidget { | |
const Button({ | |
Key? key, | |
}) : super(key: key); | |
@override | |
_ButtonState createState() => _ButtonState(); | |
} | |
class _ButtonState extends State<Button> { | |
String text = 'set access level'; | |
@override | |
Widget build(BuildContext context) { | |
return ElevatedButton( | |
onPressed: () async { | |
final _data = await showModalBottomSheet<String>( | |
context: context, | |
builder: (context) => Column( | |
mainAxisSize: MainAxisSize.min, | |
children: ['Admin', 'Normal', 'No-one'] | |
.map( | |
(e) => ListTile( | |
title: Text(e), | |
onTap: () => Navigator.pop(context, e), | |
), | |
) | |
.toList(), | |
), | |
); | |
if (_data != null) setState(() => text = _data); | |
}, | |
child: Text(text), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment