Advertisement
Guest User

Testing

a guest
May 18th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.66 KB | None | 0 0
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:mallcomm_cms_flutter/main.dart';
  4. import 'package:mallcomm_cms_flutter/People/all_people.dart';
  5. import 'package:url_launcher/url_launcher.dart';
  6. import 'package:mallcomm_cms_flutter/Profile/user_profiles.dart';
  7.  
  8. class PeopleDetails extends StatefulWidget {
  9.   final String title;
  10.   final Profile profile;
  11.  
  12.   PeopleDetails(this.title, this.profile);
  13.   @override
  14.   _PermissionsState createState()=> new _PermissionsState(profile);
  15. }
  16. class _PermissionsState extends State<PeopleDetails> {
  17.   // Variables to store my switch values
  18.   final Profile profile;
  19.  
  20.   _PermissionsState(this.profile);
  21.  
  22.     // onChanged handles the switch state whether its on or off
  23.   void _onChangedVerified(bool value) {
  24.     setState(() {
  25.       profile.verifiedValue = value;
  26.     });
  27.   }
  28.   void _onChangedApproved(bool value) {
  29.     setState(() {
  30.       profile.approvedValue = value;
  31.     });
  32.   }
  33.   void _onChangedSecurityApproved(bool value) {
  34.     setState(() {
  35.       profile.securityApprovedValue = value;
  36.     });
  37.   }
  38.   void _onChangedBlocked(bool value) {
  39.     setState(() {
  40.       profile.blockedValue = value;
  41.     });
  42.   }
  43.  
  44.   @override
  45.   Widget build(BuildContext context) {
  46.     void _launchDial() async {
  47.       var url = "tel:" + profile.phoneNumber;
  48.       if (await canLaunch(url))
  49.         launch(url);
  50.       else
  51.         print('URL CAN NOT BE LAUNCHED');
  52.     }
  53.  
  54.     void _launchEmail() async {
  55.       var url = "mailto:" + profile.userEmail;
  56.       if (await canLaunch(url))
  57.         launch(url);
  58.       else
  59.         print('URL CAN NOT BE LAUNCHED');
  60.     }
  61.     return Scaffold(appBar: AppBar(
  62.       title: Text("User Permissions"),
  63.     ),
  64.  
  65.       body: Container(
  66.         padding: EdgeInsets.all(8.0),
  67.         child: Column(
  68.           children: <Widget>[
  69.             Row(
  70.               children: <Widget>[
  71.                 Expanded(child: Text("Verified"
  72.                 ),
  73.                 ),
  74.  
  75.             Container(
  76.               //https://www.youtube.com/watch?v=Z5lggEXYNCI
  77.               child: Switch(value: profile.verifiedValue, onChanged: (bool value) {
  78.                 _onChangedVerified(value);
  79.               }),
  80.             ),
  81.           ],
  82.         ),
  83.             Row(
  84.               children: <Widget>[
  85.                 Expanded(
  86.                   child: Text("Approved"),
  87.                 ),
  88.                 Container(
  89.                   // Setting the value of the Switch to null if "profile.blockedValue" is true
  90.                   child: Switch(value: profile.approvedValue,onChanged: profile.blockedValue ? null : (bool value) {
  91.                     setState(() {
  92.                       profile.approvedValue=value;
  93.  
  94.                       if(!profile.blockedValue)
  95.                       {
  96.                         profile.securityApprovedValue=false;
  97.                       }
  98.                     });(value);
  99.                   }),
  100.                 )
  101.               ],
  102.             ),
  103.             Row(
  104.               children: <Widget>[
  105.                 Expanded(
  106.                   child: Text("Security Approved"),
  107.                 ),
  108.                 Container(
  109.                   child: Switch(value: profile.securityApprovedValue, onChanged: profile.blockedValue ? null : (bool value){
  110.                     setState(() {
  111.                       profile.securityApprovedValue=value;
  112.                       if (value && !profile.approvedValue){
  113.                         profile.approvedValue= true;
  114.                     }
  115.                     });
  116.                   }),
  117.                 )
  118.               ],
  119.             ),
  120.             Row(
  121.               children: <Widget>[
  122.                 Expanded(
  123.                   child: Text("Blocked"),
  124.                 ),
  125.                 Container(
  126.                   child: Switch(value: profile.blockedValue, onChanged: (bool value){
  127.                     setState(() {
  128.                       profile.blockedValue=value;
  129.                         // if blockedValue = true then set securityApprovedValue & approvedValue to false
  130.                       if(profile.blockedValue)
  131.                         {
  132.                           profile.securityApprovedValue=false;
  133.                           profile.approvedValue=false;
  134.                         }
  135.                     });(value);
  136.                   }),
  137.                 )
  138.               ],
  139.             ),
  140.             Row(
  141.               mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  142.               children: <Widget>[
  143.                 CustomColumn.buildButtonColumn(Icons.lock_open, 'UNLOCK', Colors.red),
  144.                 InkWell(
  145.                   splashColor: Colors.greenAccent,
  146.                   onTap: _launchEmail, child: CustomColumn.buildButtonColumn(Icons.mail, 'EMAIL', Colors.amber),
  147.                 ),
  148.                 InkWell(
  149.                   splashColor: Colors.yellowAccent,
  150.                   onTap: _launchDial, child: CustomColumn.buildButtonColumn(Icons.call, 'CALL', Colors.green),
  151.                 ),
  152.               ],
  153.             ),
  154.     ],
  155.       ),
  156.       ),
  157.     );
  158.   }
  159. }
  160.  
  161. class CustomColumn {
  162.     // Custom Column
  163.     static Column buildButtonColumn(IconData icon, String label, Color color) {
  164.       return new Column(
  165.         mainAxisSize: MainAxisSize.min,
  166.         mainAxisAlignment: MainAxisAlignment.center,
  167.         children: <Widget>[Icon(icon, color: color, size: 30.0,
  168.         ),
  169.         Container(
  170.           margin: const EdgeInsets.only(top: 8.0),
  171.           child: Text(
  172.             label, style: TextStyle(
  173.             fontSize: 12.0,
  174.             fontWeight: FontWeight.w400,
  175.             ),
  176.             ),
  177.           )
  178.         ],
  179.       );
  180.     }
  181.   }
  182.  
  183. class UserDialog extends StatefulWidget{
  184.   @override
  185.   _addToCMSState createState() => _addToCMSState();
  186. }
  187. enum Answer{AdminUser, StdUser, AuthUser, BasicUser}
  188.  
  189. class _addToCMSState extends State<UserDialog> {
  190.   String _answer = "";
  191.  
  192.   void setUserAuth(String value) {
  193.     setState(() {
  194.       _answer = value;
  195.     });
  196.   }
  197.  
  198.   Future<Null> _askUser() async {
  199.     switch (
  200.     await showDialog(context: context, builder: (BuildContext context) {
  201.       return SimpleDialog(
  202.         title: Text('Choose User Rights'),
  203.         children: <Widget>[
  204.           SimpleDialogOption(
  205.             onPressed: () {
  206.               Navigator.pop(context, Answer.AdminUser);
  207.             },
  208.             child: Text('Admin User'),
  209.           ),
  210.           SimpleDialogOption(
  211.             onPressed: () {
  212.               Navigator.pop(context, Answer.StdUser);
  213.             },
  214.             child: Text('Standard User'),
  215.           ), SimpleDialogOption(
  216.             onPressed: () {
  217.               Navigator.pop(context, Answer.AuthUser);
  218.             },
  219.             child: Text('Author User'),
  220.           ),
  221.           SimpleDialogOption(
  222.             onPressed: () {
  223.               Navigator.pop(context, Answer.BasicUser);
  224.             },
  225.             child: Text('Basic User'),
  226.           ),
  227.         ],
  228.       );
  229.     }
  230.     )) {
  231.       case Answer.AdminUser:
  232.         setUserAuth('Admin User');
  233.         break;
  234.       case Answer.StdUser:
  235.         setUserAuth('Standard User');
  236.         break;
  237.       case Answer.AuthUser:
  238.         setUserAuth('Author User');
  239.         break;
  240.       case Answer.BasicUser:
  241.         setUserAuth('Basic User');
  242.         break;
  243.     }
  244.   }
  245.  
  246.   @override
  247.   Widget build(BuildContext context) {
  248.     return Scaffold(body: Column(children: <Widget>[Padding(
  249.       padding: EdgeInsets.only(top: 20.0),
  250.     ),
  251.     RaisedButton(child: Text('Grant CMS Access'), color: Theme
  252.         .of(context)
  253.         .primaryColor,
  254.       textColor: Colors.white,
  255.       onPressed: () {_askUser();},
  256.  
  257.     ),
  258.     ],
  259.     ),
  260.     );
  261.   }
  262.  
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement