import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:photolink_beta/secreens/photolinkmap.dart'; import 'package:photolink_beta/services/Auth/LoginServices.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'CreateTripe.dart'; class loginpage extends StatefulWidget { @override _loginpageState createState() => _loginpageState(); } class _loginpageState extends State { final loginServices authenticatable = loginServices(); TextEditingController _emailController = new TextEditingController(); TextEditingController _passwordController = new TextEditingController(); @override void initState(){ super.initState(); //authGuard(); } // authGuard() async { // // String token = await authenticatable.GetToken(); // if(token!='InvalidToken' && token!=null){ // setState(() { // Navigator.pushReplacement( // context, MaterialPageRoute(builder: (_) => CreateTripe())); // }); // // } // } @override void dispose() { _emailController.dispose(); _passwordController.dispose(); super.dispose(); } Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( title: Text("Login Page"), ), body: SingleChildScrollView( child: Column( children: [ Padding( padding: const EdgeInsets.only(top: 60.0), child: Center( child: Container( width: 200, height: 150, /*decoration: BoxDecoration( color: Colors.red, borderRadius: BorderRadius.circular(50.0)),*/ child: Image.asset('assets/logo.png')), ), ), Padding( //padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0), padding: EdgeInsets.symmetric(horizontal: 15), child: TextField( controller: _emailController, decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'Email', hintText: 'Enter valid email id as abc@gmail.com'), ), ), Padding( padding: const EdgeInsets.only( left: 15.0, right: 15.0, top: 15, bottom: 0), //padding: EdgeInsets.symmetric(horizontal: 15), child: TextField( controller: _passwordController, obscureText: true, decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'Password', hintText: 'Enter secure password'), ), ), FlatButton( onPressed: (){ //TODO FORGOT PASSWORD SCREEN GOES HERE }, child: Text( 'Forgot Password', style: TextStyle(color: Colors.blue, fontSize: 15), ), ), Container( height: 50, width: 250, decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.circular(20)), child: FlatButton( onPressed: () async { try { print(_emailController.text); print(_passwordController.text); loginServices controller = new loginServices(); final authresult = await controller.getToken( _emailController.text, _passwordController.text); if (authresult.statusCode == 200 && authresult.data.access != null) { /*saving the email adress in local storage*/ SharedPreferences myPrefs = await SharedPreferences.getInstance(); myPrefs.setString( 'UserEmail', _emailController.text); /*saving the email adress in local storage*/ Navigator.pushReplacement( context, MaterialPageRoute(builder: (_) => CreateTripe())); } else { throw (authresult.errorMessage); } } catch (e) { //stop loading print(e); showAlertDialog(context); } }, child: Text( 'Login', style: TextStyle(color: Colors.white, fontSize: 25), ), ), ), SizedBox( height: 130, ), Text('New User? Create Account') ], ), ), ); } showAlertDialog(BuildContext context) { // set up the buttons Widget cancelButton = FlatButton( child: Text("Cancel"), onPressed: () {}, ); Widget continueButton = FlatButton( child: Text("Continue"), onPressed: () {}, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("AlertDialog"), content: Text("Error to login please try another account"), actions: [ cancelButton, continueButton, ], ); // show the dialog showDialog( context: context, builder: (BuildContext context) { return alert; }, ); } }