Advertisement
Guest User

Untitled

a guest
May 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.99 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.             ),Column(children: <Widget>[Padding(
  154.               padding: EdgeInsets.only(top: 20.0),
  155.             ),
  156.               RaisedButton(child: Text('Grant CMS Access'),color: Theme.of(context).primaryColor,
  157.                 textColor: Colors.white,
  158.                 onPressed: (){// call my simple duialog here}
  159.  
  160.               ),
  161.             ],
  162.             )
  163.     ],
  164.       ),
  165.       ),
  166.     );
  167.  
  168.   }
  169. }
  170.  
  171. class CustomColumn {
  172.     // Custom Column
  173.     static Column buildButtonColumn(IconData icon, String label, Color color) {
  174.       return new Column(
  175.         mainAxisSize: MainAxisSize.min,
  176.         mainAxisAlignment: MainAxisAlignment.center,
  177.         children: <Widget>[Icon(icon, color: color, size: 30.0,
  178.         ),
  179.         Container(
  180.           margin: const EdgeInsets.only(top: 8.0),
  181.           child: Text(
  182.             label, style: TextStyle(
  183.             fontSize: 12.0,
  184.             fontWeight: FontWeight.w400,
  185.             ),
  186.             ),
  187.           )
  188.         ],
  189.       );
  190.     }
  191.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement