Advertisement
Guest User

Untitled

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