Advertisement
Guest User

Untitled

a guest
May 18th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.71 KB | None | 0 0
  1. class UserDialog extends StatefulWidget{
  2.   @override
  3.   _addToCMSState createState() => _addToCMSState();
  4. }
  5. enum Answer{AdminUser, StdUser, AuthUser, BasicUser}
  6.  
  7. class _addToCMSState extends State<UserDialog> {
  8.   String _answer = "";
  9.   void setUserAuth(String value) {
  10.     setState(() {
  11.       _answer = value;
  12.     });
  13.   }
  14.   Future<Null> _askUser() async {
  15.     switch (
  16.     await showDialog(context: context, builder: (BuildContext context) {
  17.       return SimpleDialog(
  18.         title: Text('Choose User Rights'),
  19.         children: <Widget>[
  20.           SimpleDialogOption(
  21.             onPressed: () {
  22.               Navigator.pop(context, Answer.AdminUser);
  23.             },
  24.             child: Text('Admin User'),
  25.           ),
  26.           SimpleDialogOption(
  27.             onPressed: () {
  28.               Navigator.pop(context, Answer.StdUser);
  29.             },
  30.             child: Text('Standard User'),
  31.           ), SimpleDialogOption(
  32.             onPressed: () {
  33.               Navigator.pop(context, Answer.AuthUser);
  34.             },
  35.             child: Text('Author User'),
  36.           ),
  37.           SimpleDialogOption(
  38.             onPressed: () {
  39.               Navigator.pop(context, Answer.BasicUser);
  40.             },
  41.             child: Text('Basic User'),
  42.           ),
  43.         ],
  44.       );
  45.     }
  46.     )) {
  47.       case Answer.AdminUser:
  48.         setUserAuth('Admin User');
  49.         break;
  50.       case Answer.StdUser:
  51.         setUserAuth('Standard User');
  52.         break;
  53.       case Answer.AuthUser:
  54.         setUserAuth('Author User');
  55.         break;
  56.       case Answer.BasicUser:
  57.         setUserAuth('Basic User');
  58.         break;
  59.     }
  60.   }
  61.   noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement