Advertisement
Guest User

Untitled

a guest
May 7th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 9.64 KB | None | 0 0
  1. import 'dart:math';
  2.  
  3. import 'package:firebase_auth/firebase_auth.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/services.dart';
  7. import 'package:page_transition/page_transition.dart';
  8.  
  9.  
  10. import './login.dart';
  11.  
  12. final FirebaseAuth _auth = FirebaseAuth.instance;
  13.  
  14.  
  15. class Register extends StatefulWidget {
  16.   final String title = 'Registration';
  17.  
  18.   @override
  19.   State<StatefulWidget> createState() => RegisterState();
  20. }
  21.  
  22. class RegisterState extends State<Register> {
  23.   final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  24.   final TextEditingController _emailController = TextEditingController();
  25.   final TextEditingController _passwordController = TextEditingController();
  26.  
  27.   bool _success;
  28.   String _userEmail;
  29.   String val;
  30.  
  31.  
  32.   @override
  33.   Widget build(BuildContext context) {
  34.     SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
  35.       statusBarColor: Colors.yellow.shade800,
  36.       ));
  37.  
  38.     return Stack(children: <Widget>[
  39.       Container(color: Color(0xFF18181C)),
  40.  
  41.       Container(
  42.         alignment: Alignment.topCenter,
  43.         color: Color(0xFF232428),
  44.         margin:
  45.         const EdgeInsets.only(left: 0.0, right: 0.0, top: 0.0, bottom: 0.0),
  46.         child: new Image.asset('images/login2.png',
  47.                                    width: 300.0, height: 248.0, alignment: Alignment.center),
  48.         ),
  49.       Container(
  50.         alignment: Alignment.topCenter,
  51.         color: Color(0xFF232428),
  52.         margin: const EdgeInsets.only(
  53.             left: 0.0, right: 0.0, top: 260.0, bottom: 0.0),
  54.         child: new Image.asset('images/login_title_register.png',
  55.                                    width: 58.0, height: 14.0, alignment: Alignment.center),
  56.         ),
  57.  
  58.       Container(
  59.  
  60.           alignment: Alignment.topCenter,
  61.  
  62.           child: Form(
  63.               key: _formKey,
  64.               child: GestureDetector(
  65.                   behavior: HitTestBehavior.opaque,
  66.                   onTap: () {
  67.                     SystemChannels.textInput.invokeMethod('TextInput.hide');
  68. //            FocusScope.of(context).requestFocus(new FocusNode());
  69.                   },
  70.                   child: Card(
  71.                       elevation: 0,
  72.                       margin: const EdgeInsets.only(
  73.                           top: 280.0, bottom: 0.0, right: 0.0, left: 0.0),
  74.  
  75.                       child: Container(
  76.                           padding: const EdgeInsets.all(20.0),
  77.                           height: 243.0,
  78.                           width: 350.0,
  79.                           color: Color(0xFF232428),
  80.                           child: new Column(children: <Widget>[
  81.                             new TextFormField(
  82.                                     cursorColor: Color(0xFFEDAC0B),
  83.                                     style: TextStyle(
  84.                                         color: Color(0xFF606060),
  85.                                         fontWeight: FontWeight.w300),
  86.                                     controller: _emailController,
  87.                                     validator: (String value) {
  88.                                       if (value.isEmpty) {
  89.                                         return 'Please Enter A Valid Email';
  90.                                       }
  91.                                       if(RegExp(r'(\w+@\w+\.\w+)').stringMatch(val) != val)
  92.                                         return 'Please Enter A Valid E-Mail';
  93.                                     },
  94.                                     keyboardType: TextInputType.emailAddress,
  95.                                     decoration: new InputDecoration(
  96.                                       enabledBorder: OutlineInputBorder(
  97.                                         borderRadius:
  98.                                             BorderRadius.circular(10.0),
  99.                                         borderSide: const BorderSide(
  100.                                             color: Color(0xFFEDAC0B),
  101.                                             width: 0.0),
  102.                                       ),
  103.                                       focusedBorder: OutlineInputBorder(
  104.                                         borderRadius:
  105.                                             BorderRadius.circular(10.0),
  106.                                         borderSide: const BorderSide(
  107.                                             color: Color(0xFFEDAC0B)),
  108.                                       ),
  109.                                       labelText: 'Email',
  110.                                       labelStyle: TextStyle(
  111.                                           color: Color(0xFF606060),
  112.                                           fontWeight: FontWeight.w300),
  113.                                       hintStyle: TextStyle(
  114.                                           color: Color(0xFF606060),
  115.                                           fontWeight: FontWeight.w300),
  116.                                       prefixIcon: new Icon(Icons.email,
  117.                                           color: Color(0xFFEDAC0B)),
  118.                                     ),
  119.                                   ),
  120.                                   new Container(
  121.                                     height: 8.0,
  122.                                   ),
  123.                                   new TextFormField(
  124.                                     cursorColor: Color(0xFFEDAC0B),
  125.                                     controller: _passwordController,
  126.                                     validator: (String value) {
  127.                                       if (value.isEmpty) {
  128.                                         return 'Please Enter A Valid Password';
  129.                                       }
  130.                                       if(value.length < 7)
  131.                                         return '6 Characters Min.';
  132.                                     },
  133.                                     style: TextStyle(
  134.                                         color: Color(0xFF606060),
  135.                                         fontWeight: FontWeight.w300),
  136.                                     keyboardType: TextInputType.text,
  137.                                     decoration: new InputDecoration(
  138.                                       enabledBorder: OutlineInputBorder(
  139.                                         borderRadius:
  140.                                             BorderRadius.circular(10.0),
  141.                                         borderSide: const BorderSide(
  142.                                             color: Color(0xFFEDAC0B),
  143.                                             width: 0.0),
  144.                                       ),
  145.                                       focusedBorder: OutlineInputBorder(
  146.                                         borderRadius:
  147.                                             BorderRadius.circular(10.0),
  148.                                         borderSide: const BorderSide(
  149.                                             color: Color(0xFFEDAC0B)),
  150.                                       ),
  151.                                       labelText: 'Password',
  152.                                       labelStyle: TextStyle(
  153.                                           color: Color(0xFF606060),
  154.                                           fontWeight: FontWeight.w300),
  155.                                       hintText: "(6) Characters Min.",
  156.                                       hintStyle: TextStyle(
  157.                                           color: Color(0xFF606060),
  158.                                           fontWeight: FontWeight.w300),
  159.                                       prefixIcon: new Icon(Icons.lock,
  160.                                           color: Color(0xFFEDAC0B)),
  161.                                     ),
  162.                                     obscureText: false,
  163.                               ),
  164.  
  165.  
  166.  
  167.  
  168.                           ]
  169.                                             )
  170.                           )
  171.  
  172.                       )
  173.  
  174.                   ))
  175.  
  176.           ),
  177.  
  178.  
  179.  
  180.  
  181.       new Container(
  182.           alignment: Alignment.bottomRight,
  183.           margin: const EdgeInsets.only(
  184.               left: 0.0, right: 30.0, top: 0.0, bottom: 48.0),
  185.           child: GestureDetector(
  186.             onTap: () async {
  187.     if (_formKey.currentState.validate()) {
  188.     _register();
  189.                                     }
  190.  
  191.  
  192.               print("Finished Registration (back to login) Button Clicked");
  193.             },
  194.             child: Image.asset(
  195.               'images/login_button_redarrow.png',
  196.               width: 40.0,
  197.               height: 40.0,
  198.               ),
  199.             )),
  200.  
  201.  
  202.  
  203.  
  204.       new Container(
  205.           alignment: Alignment.bottomCenter,
  206.           margin: const EdgeInsets.only(
  207.               left: 0.0, right: 00.0, top: 0.0, bottom: 10.0),
  208.  
  209.           child: new Image.asset(
  210.             'images/footer2.png',
  211.             width: 123.0,
  212.             height: 14.0,
  213.             )),
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.     ]);
  221.   }
  222.   @override
  223.   void dispose() {
  224.     // Clean up the controller when the Widget is disposed
  225.     _emailController.dispose();
  226.     _passwordController.dispose();
  227.     super.dispose();
  228.   }
  229.  
  230.   // Example code for registration.
  231.   void _register() async {
  232.     final FirebaseUser user = await _auth.createUserWithEmailAndPassword(
  233.       email: _emailController.text,
  234.       password: _passwordController.text,
  235.       );
  236.     if (user != null) {
  237.       setState(() {
  238.         _success = true;
  239.         Navigator.pop(
  240.             context,
  241.             new MaterialPageRoute(
  242.                 maintainState: true, builder: (context) => new Login()));
  243.  
  244.         _userEmail = user.email;
  245.       });
  246.     } else {
  247.       _success = false;
  248.     }
  249.   }
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement