Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.91 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'login_t_s.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'dart:async';
  5. import 'package:http/http.dart' as http;
  6. import 'dart:convert';
  7.  
  8.  
  9.  
  10. class CreateAccountT extends StatefulWidget {
  11.   @override
  12.   _CreateAccountState createState() => new _CreateAccountState();
  13. }
  14. class _CreateAccountState extends State<CreateAccountT> {
  15.  
  16.   final _formKey = GlobalKey<FormState>();
  17.   final _usernameController = TextEditingController();
  18.   final _emailController = TextEditingController();
  19.   final _passwordController = TextEditingController();
  20.   final _passwordReController = TextEditingController();
  21.   int _counter = 0;
  22.   Future _createAccount() async {
  23.  
  24.     final response = await http.post("http://172.16.46.130/gradoapp_server/grado_trap_email",body:{
  25.       "email": _emailController.text,
  26.     });
  27.  
  28.  
  29.     var dataUser = jsonDecode(response.body);
  30.  
  31.     if(dataUser.length >= 1){
  32.       setState((){
  33.         _counter = 1;
  34.       });
  35.         print(_counter);
  36.       //email already exist
  37.     }
  38.     if(dataUser.length == 0){
  39.       setState((){
  40.         _counter = 0;
  41.       });
  42.         print(_counter);
  43.  
  44.  
  45.       await http.post("http://172.16.46.130/gradoapp_server/grado_create_account",body:{
  46.         "username": _usernameController.text,
  47.         "email": _emailController.text,
  48.         "password": _passwordController.text,
  49.       });
  50.       _onClear();
  51.       _neverSatisfied();
  52.       //email does not exist
  53.     }
  54.  
  55.   }
  56.  
  57.   _onClear() {
  58.     setState(() {
  59.       _usernameController.text = "";
  60.       _emailController.text = "";
  61.       _passwordController.text = "";
  62.       _passwordReController.text = "";
  63.     });
  64.   }
  65.  
  66.   @override
  67.   void dispose() {
  68.     // Clean up the controller when the Widget is disposed
  69.     _usernameController.dispose();
  70.     _emailController.dispose();
  71.     _passwordController.dispose();
  72.     _passwordReController.dispose();
  73.     super.dispose();
  74.   }
  75.  
  76.   @override
  77.   Widget build(BuildContext context) {
  78.     final logo = Center(
  79.       child: new Text(
  80.         "Gradome",
  81.         style: TextStyle(color: Colors.black, fontSize: 75, fontFamily: "Billabong"),
  82.       ),
  83.     );
  84.     final username = Padding(
  85.       padding:
  86.       const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  87.       child: new TextFormField(
  88.         controller: _usernameController,
  89.         validator: (value) {
  90.           if (value.isEmpty) {
  91.             return 'Emty Username';
  92.           }
  93.           return null;
  94.         },
  95.         decoration: InputDecoration(
  96.           labelText: 'Username',
  97.           contentPadding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 20.0),
  98.           border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
  99.         ),
  100.       ),
  101.     );
  102.  
  103.     final email = Padding(
  104.       padding:
  105.       const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  106.       child: new TextFormField(
  107.         keyboardType: TextInputType.emailAddress,
  108.         controller: _emailController,
  109.         validator: (value) {
  110.           if (value.isEmpty) {
  111.             return 'Emty Email';
  112.           }
  113.           if('$_counter' == '1'){
  114.             return 'Email already exist';
  115.           }
  116.           return null;
  117.         },
  118.         decoration: InputDecoration(
  119.           labelText: 'Email',
  120.           contentPadding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 20.0),
  121.           border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
  122.         ),
  123.       ),
  124.     );
  125.  
  126.     final password = Padding(
  127.       padding:
  128.       const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  129.       child: new TextFormField(
  130.         controller: _passwordController,
  131.         validator: (value) {
  132.           if (value.isEmpty) {
  133.             return 'Emty Password';
  134.           }
  135.           return null;
  136.         },
  137.         obscureText: true,
  138.         decoration: InputDecoration(
  139.           labelText: 'Password',
  140.           contentPadding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 20.0),
  141.           border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
  142.         ),
  143.       ),
  144.     );
  145.  
  146.     final passwordRe = Padding(
  147.       padding:
  148.       const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  149.       child: new TextFormField(
  150.         controller: _passwordReController,
  151.         validator: (value) {
  152.           if (value.isEmpty) {
  153.             return 'Emty Password';
  154.           }
  155.           if (value != _passwordController.text) {
  156.             return 'Password do no match';
  157.           }
  158.           return null;
  159.         },
  160.         obscureText: true,
  161.         decoration: InputDecoration(
  162.           labelText: 'Re-type Password',
  163.           contentPadding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 20.0),
  164.           border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
  165.         ),
  166.       ),
  167.     );
  168.  
  169.     final createAccountButton = Padding(
  170.       padding: const EdgeInsets.only(left: 20.0, right: 5.0, top: 10.0),
  171.       child: new Container(
  172.         height: 60.0,
  173.         child: CupertinoButton(
  174.           child: const Text('Create Account',style: TextStyle(color: Colors.lightBlue),),
  175.           onPressed:(){
  176.             if(_formKey.currentState.validate()) {
  177.               _createAccount();
  178.  
  179.             }
  180.           },
  181.         ),
  182.       ),
  183.     );
  184.  
  185.     final backButton = Padding(
  186.       padding: const EdgeInsets.only(left: 20.0, right: 5.0, top: 10.0),
  187.       child: new Container(
  188.         height: 60.0,
  189.         child: CupertinoButton(
  190.           child: const Text('Back',style: TextStyle(color: Colors.lightBlue),),
  191.           onPressed:(){
  192.             Navigator.of(context).pop();
  193.           },
  194.         ),
  195.       ),
  196.     );
  197.  
  198.     return Container(
  199.       child: Scaffold(
  200.         appBar: AppBar(
  201.           iconTheme: new IconThemeData(color: Colors.black),
  202.           backgroundColor: Colors.white,
  203.           elevation: 1.0,
  204.           centerTitle: true,
  205.           title: Text('Teacher Sign up'),
  206.           textTheme: TextTheme(
  207.               title: TextStyle(
  208.                   color: Colors.black,
  209.                   fontWeight: FontWeight.bold
  210.               )
  211.           ),
  212.         ),
  213.         backgroundColor: Colors.white,
  214.         body: new Center(
  215.           child: Form(
  216.             key: _formKey,
  217.             child: new ListView(
  218.               physics: new PageScrollPhysics(),
  219.               shrinkWrap: true,
  220.               padding: new EdgeInsets.only(left: 30.0, right: 30.0),
  221.               children: <Widget>[
  222.                 SizedBox(height: 0.0),
  223.                 logo,
  224.                 SizedBox(height: 80.0),
  225.                 username,
  226.                 SizedBox(height: 8.0),
  227.                 email,
  228.                 SizedBox(height: 8.0),
  229.                 password,
  230.                 SizedBox(height: 8.0),
  231.                 passwordRe,
  232.                 SizedBox(height: 24.0),
  233.                 createAccountButton,
  234.                 SizedBox(height: 0.0),
  235.                 backButton,
  236.                 SizedBox(height: 30.0),
  237.               ],
  238.             ),
  239.           ),
  240.         ),
  241.       ),
  242.     );
  243.   }
  244.  
  245.  
  246.   Future<void> _neverSatisfied() async {
  247.     return showDialog<void>(
  248.       context: context,
  249.       barrierDismissible: false, // user must tap button!
  250.       builder: (BuildContext context) {
  251.         return AlertDialog(
  252.           title: Text('Account is Ready!'),
  253.           content: SingleChildScrollView(
  254.             child: ListBody(
  255.               children: <Widget>[
  256.                 Text(''),
  257.                 Text('We\’re  taking you to the log in page.'),
  258.               ],
  259.             ),
  260.           ),
  261.           actions: <Widget>[
  262.             FlatButton(
  263.               child: Text('Proceed'),
  264.               onPressed: () {
  265.  
  266.                 Navigator.of(context).pop();
  267.  
  268.                 Navigator.push(
  269.                   context,
  270.                   MaterialPageRoute(builder: (context) => SignInPage()),
  271.  
  272.                 );
  273.  
  274.               },
  275.             ),
  276.           ],
  277.         );
  278.       },
  279.     );
  280.   }
  281. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement