Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'login_t_s.dart';
- import 'package:flutter/cupertino.dart';
- import 'dart:async';
- import 'package:http/http.dart' as http;
- import 'dart:convert';
- class CreateAccountT extends StatefulWidget {
- @override
- _CreateAccountState createState() => new _CreateAccountState();
- }
- class _CreateAccountState extends State<CreateAccountT> {
- final _formKey = GlobalKey<FormState>();
- final _usernameController = TextEditingController();
- final _emailController = TextEditingController();
- final _passwordController = TextEditingController();
- final _passwordReController = TextEditingController();
- int _counter = 0;
- Future _createAccount() async {
- final response = await http.post("http://172.16.46.130/gradoapp_server/grado_trap_email",body:{
- "email": _emailController.text,
- });
- var dataUser = jsonDecode(response.body);
- if(dataUser.length >= 1){
- setState((){
- _counter = 1;
- });
- print(_counter);
- //email already exist
- }
- if(dataUser.length == 0){
- setState((){
- _counter = 0;
- });
- print(_counter);
- await http.post("http://172.16.46.130/gradoapp_server/grado_create_account",body:{
- "username": _usernameController.text,
- "email": _emailController.text,
- "password": _passwordController.text,
- });
- _onClear();
- _neverSatisfied();
- //email does not exist
- }
- }
- _onClear() {
- setState(() {
- _usernameController.text = "";
- _emailController.text = "";
- _passwordController.text = "";
- _passwordReController.text = "";
- });
- }
- @override
- void dispose() {
- // Clean up the controller when the Widget is disposed
- _usernameController.dispose();
- _emailController.dispose();
- _passwordController.dispose();
- _passwordReController.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- final logo = Center(
- child: new Text(
- "Gradome",
- style: TextStyle(color: Colors.black, fontSize: 75, fontFamily: "Billabong"),
- ),
- );
- final username = Padding(
- padding:
- const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
- child: new TextFormField(
- controller: _usernameController,
- validator: (value) {
- if (value.isEmpty) {
- return 'Emty Username';
- }
- return null;
- },
- decoration: InputDecoration(
- labelText: 'Username',
- contentPadding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 20.0),
- border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
- ),
- ),
- );
- final email = Padding(
- padding:
- const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
- child: new TextFormField(
- keyboardType: TextInputType.emailAddress,
- controller: _emailController,
- validator: (value) {
- if (value.isEmpty) {
- return 'Emty Email';
- }
- if('$_counter' == '1'){
- return 'Email already exist';
- }
- return null;
- },
- decoration: InputDecoration(
- labelText: 'Email',
- contentPadding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 20.0),
- border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
- ),
- ),
- );
- final password = Padding(
- padding:
- const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
- child: new TextFormField(
- controller: _passwordController,
- validator: (value) {
- if (value.isEmpty) {
- return 'Emty Password';
- }
- return null;
- },
- obscureText: true,
- decoration: InputDecoration(
- labelText: 'Password',
- contentPadding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 20.0),
- border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
- ),
- ),
- );
- final passwordRe = Padding(
- padding:
- const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
- child: new TextFormField(
- controller: _passwordReController,
- validator: (value) {
- if (value.isEmpty) {
- return 'Emty Password';
- }
- if (value != _passwordController.text) {
- return 'Password do no match';
- }
- return null;
- },
- obscureText: true,
- decoration: InputDecoration(
- labelText: 'Re-type Password',
- contentPadding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 20.0),
- border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
- ),
- ),
- );
- final createAccountButton = Padding(
- padding: const EdgeInsets.only(left: 20.0, right: 5.0, top: 10.0),
- child: new Container(
- height: 60.0,
- child: CupertinoButton(
- child: const Text('Create Account',style: TextStyle(color: Colors.lightBlue),),
- onPressed:(){
- if(_formKey.currentState.validate()) {
- _createAccount();
- }
- },
- ),
- ),
- );
- final backButton = Padding(
- padding: const EdgeInsets.only(left: 20.0, right: 5.0, top: 10.0),
- child: new Container(
- height: 60.0,
- child: CupertinoButton(
- child: const Text('Back',style: TextStyle(color: Colors.lightBlue),),
- onPressed:(){
- Navigator.of(context).pop();
- },
- ),
- ),
- );
- return Container(
- child: Scaffold(
- appBar: AppBar(
- iconTheme: new IconThemeData(color: Colors.black),
- backgroundColor: Colors.white,
- elevation: 1.0,
- centerTitle: true,
- title: Text('Teacher Sign up'),
- textTheme: TextTheme(
- title: TextStyle(
- color: Colors.black,
- fontWeight: FontWeight.bold
- )
- ),
- ),
- backgroundColor: Colors.white,
- body: new Center(
- child: Form(
- key: _formKey,
- child: new ListView(
- physics: new PageScrollPhysics(),
- shrinkWrap: true,
- padding: new EdgeInsets.only(left: 30.0, right: 30.0),
- children: <Widget>[
- SizedBox(height: 0.0),
- logo,
- SizedBox(height: 80.0),
- username,
- SizedBox(height: 8.0),
- email,
- SizedBox(height: 8.0),
- password,
- SizedBox(height: 8.0),
- passwordRe,
- SizedBox(height: 24.0),
- createAccountButton,
- SizedBox(height: 0.0),
- backButton,
- SizedBox(height: 30.0),
- ],
- ),
- ),
- ),
- ),
- );
- }
- Future<void> _neverSatisfied() async {
- return showDialog<void>(
- context: context,
- barrierDismissible: false, // user must tap button!
- builder: (BuildContext context) {
- return AlertDialog(
- title: Text('Account is Ready!'),
- content: SingleChildScrollView(
- child: ListBody(
- children: <Widget>[
- Text(''),
- Text('We\βre taking you to the log in page.'),
- ],
- ),
- ),
- actions: <Widget>[
- FlatButton(
- child: Text('Proceed'),
- onPressed: () {
- Navigator.of(context).pop();
- Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => SignInPage()),
- );
- },
- ),
- ],
- );
- },
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement