Google sign in and hourglass improved

This commit is contained in:
Sewmina
2022-03-24 05:05:18 +05:30
parent 9f976b1e33
commit 2fe29dcbb8
13 changed files with 560 additions and 307 deletions

View File

@@ -1,7 +1,9 @@
import 'dart:ui';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:tasktracker/googleSignIn.dart';
import 'User.dart' as Users;
import 'package:http/http.dart' as http;
class WelcomePage extends StatefulWidget {
@@ -85,71 +87,71 @@ class SignInPage extends StatefulWidget {
class _SignInPageState extends State<SignInPage> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
color: Colors.deepPurpleAccent,
child: Flex(
direction: Axis.vertical,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 2,
child: Container(
padding: EdgeInsets.fromLTRB(0, 100, 0, 0),
height: 400,
child:
Image(image: AssetImage('images/signin.png'))),
),
Expanded(
return SafeArea(
child: Scaffold(
body: Container(
color: Colors.deepPurpleAccent,
child: Flex(
direction: Axis.vertical,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 2,
child: Container(
padding: EdgeInsets.fromLTRB(0, 100, 0, 0),
height: 400,
child:
Image(image: AssetImage('images/signin.png'))),
),
Expanded(
flex:1,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Sign in to stay connected",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold)),
Divider(),
Text(
"Sign in and enjoy the flawless connection between all your devices. You can track your day from any device and keep it together.")
],
),
)),
Container(
padding: EdgeInsets.all(20),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
const offlineLoginPage()));
},
child: Text('Use Offline',
style: TextStyle(fontSize: 20))),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
const onlineLoginPage()));
},
child: Text('Next',
style: TextStyle(fontSize: 20)))
],
))
]))));
flex:1,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Sign in to stay connected",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold)),
Divider(),
Text(
"Sign in and enjoy the flawless connection between all your devices. You can track your day from any device and keep it together.")
],
),
)),
Container(
padding: EdgeInsets.all(20),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
const offlineLoginPage()));
},
child: Text('Use Offline',
style: TextStyle(fontSize: 20))),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
const onlineLoginPage()));
},
child: Text('Next',
style: TextStyle(fontSize: 20)))
],
))
]))));
}
}
@@ -174,224 +176,238 @@ class _onlineLoginPageState extends State<onlineLoginPage>
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
color: Colors.purpleAccent,
child: Flex(
direction: Axis.vertical,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Container(
// padding: EdgeInsets.all(20),
// alignment: Alignment.centerLeft,
// child: Text(
// 'Sign in online',
// style: TextStyle(
// fontSize: 40, fontWeight: FontWeight.bold),
// textAlign: TextAlign.left,
// ),
// ),
Expanded(
Widget build(BuildContext context) => ChangeNotifierProvider(
create:(context)=>GoogleSignInProvider(),
builder: (context, snapshot) {
return SafeArea(
child: Scaffold(
body: Container(
color: Colors.purpleAccent,
child: Flex(
direction: Axis.vertical,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Container(
// padding: EdgeInsets.all(20),
// alignment: Alignment.centerLeft,
// child: Text(
// 'Sign in online',
// style: TextStyle(
// fontSize: 40, fontWeight: FontWeight.bold),
// textAlign: TextAlign.left,
// ),
// ),
Expanded(
child: Container(
child:
Image(image: AssetImage('images/signin.png'))),
),
Container(
padding: EdgeInsets.all(20),
child: Column(children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.purple),
child: Padding(
padding: EdgeInsets.all(10),
child: TabBar(
controller: _tabController,
indicator: BoxDecoration(
color: Colors.blueAccent,
borderRadius:
BorderRadius.circular(10)),
tabs: [
TabItem('Our Account'),
TabItem('OAuth')
],
))),
Divider(
height: 30,
),
Container(
height: 320,
child: TabBarView(
controller: _tabController,
children: [
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(10),
color: Colors.purple),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.fromLTRB(
10, 10, 10, 0),
child: Text(
'Username',
style:
TextStyle(fontSize: 16),
)),
Expanded(
child: Container(
padding: EdgeInsets.all(15),
child: TextField(
controller: usernameController,
autocorrect: false,
style: TextStyle(
color: Colors.black,
),
decoration: InputDecoration(
hintText: 'Username',
filled: true,
fillColor:
Colors.white,
border: OutlineInputBorder(
borderRadius:
BorderRadius
.circular(
10))),
),
),
),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.fromLTRB(
10, 10, 10, 0),
child: Text(
'Password',
style:
TextStyle(fontSize: 16),
)),
Expanded(
child: Container(
padding: EdgeInsets.all(15),
child: TextField(
controller: passwordController,
obscureText: true,
autocorrect: false,
enableSuggestions: false,
style: TextStyle(
fontWeight:
FontWeight.bold,
color: Colors.black,
),
decoration: InputDecoration(
hintText: 'Password',
filled: true,
fillColor:
Colors.white,
border: OutlineInputBorder(
borderRadius:
BorderRadius
.circular(
10))),
),
),
),
Container(
width: 200,
padding: EdgeInsets.all(20),
child: ElevatedButton(
style: ElevatedButton
.styleFrom(
primary:
Colors.green),
onPressed: () {
login();
},
child: Container(
child:
Image(image: AssetImage('images/signin.png'))),
),
Container(
padding: EdgeInsets.all(20),
child: Column(children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.purple),
child: Padding(
padding: EdgeInsets.all(10),
child: TabBar(
controller: _tabController,
indicator: BoxDecoration(
color: Colors.blueAccent,
borderRadius:
BorderRadius.circular(10)),
tabs: [
TabItem('Our Account'),
TabItem('OAuth')
],
))),
Divider(
height: 30,
),
Container(
height: 320,
child: TabBarView(
controller: _tabController,
children: [
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(10),
color: Colors.purple),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.fromLTRB(
10, 10, 10, 0),
child: Text(
'Login',
style: TextStyle(
fontSize: 20),
)))
])),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(10),
color: Colors.purple),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Container(
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.green,
'Username',
style:
TextStyle(fontSize: 16),
)),
Expanded(
child: Container(
padding: EdgeInsets.all(15),
child: TextField(
controller: usernameController,
autocorrect: false,
style: TextStyle(
color: Colors.black,
),
decoration: InputDecoration(
hintText: 'Username',
filled: true,
fillColor:
Colors.white,
border: OutlineInputBorder(
borderRadius:
BorderRadius
.circular(
10))),
),
),
),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.fromLTRB(
10, 10, 10, 0),
child: Text(
'Password',
style:
TextStyle(fontSize: 16),
)),
Expanded(
child: Container(
padding: EdgeInsets.all(15),
child: TextField(
controller: passwordController,
obscureText: true,
autocorrect: false,
enableSuggestions: false,
style: TextStyle(
fontWeight:
FontWeight.bold,
color: Colors.black,
),
decoration: InputDecoration(
hintText: 'Password',
filled: true,
fillColor:
Colors.white,
border: OutlineInputBorder(
borderRadius:
BorderRadius
.circular(
10))),
),
),
),
Container(
width: 200,
padding: EdgeInsets.all(20),
child: ElevatedButton(
style: ElevatedButton
.styleFrom(
primary:
Colors.green),
onPressed: () {
login();
},
child: Text(
'Login',
style: TextStyle(
fontSize: 20),
)))
])),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(10),
color: Colors.purple),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Container(
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.green,
),
onPressed: (){
final provider = Provider.of<GoogleSignInProvider>(context, listen:false);
provider.googleLogin().then((v){
if(provider.user.id.length > 2){
if(provider.googleAuth!=null){
login(username: provider.user.email,password: provider.user.id);
}
}
});
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.android),
SizedBox(width: 20,),
Text("Sign with Google", style: TextStyle(fontSize: 20))
],)),
),
onPressed: (){}, child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.android),
SizedBox(width: 20,),
Text("Sign with Google", style: TextStyle(fontSize: 20))
],)),
),
Divider(height: 50,),
Container(
padding: EdgeInsets.all(50),
child:Text("New OAuth Sign in methods are on the way...")
)
Divider(height: 50,),
Container(
padding: EdgeInsets.all(50),
child:Text("New OAuth Sign in methods are on the way...")
)
]))
]))
],
),
)
])),
Container(
padding: EdgeInsets.all(20),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red),
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Back',
style: TextStyle(fontSize: 20))),
SizedBox()
],
),
)
])),
Container(
padding: EdgeInsets.all(20),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red),
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Back',
style: TextStyle(fontSize: 20))),
SizedBox()
],
))
]))));
}
))
]))));
}
);
Widget TabItem(String text) {
return Text(text, style: TextStyle(fontSize: 20, color: Colors.white));
}
Future<void> login() async {
if(usernameController.text.length < 3 || passwordController.text.length < 3){
showAlertDialog(context, "Failed", "Please enter a valid username and password");
return;
}
Future<void> login({String? username, String? password}) async {
if ((username??usernameController.text).length < 3 || (password??passwordController.text).length < 3) {
showAlertDialog(context, "Failed", "Please enter a valid username and password");
return;
}
http.Response loginResponse = await Users.login(usernameController.text, passwordController.text);
http.Response loginResponse = await Users.login(username ?? usernameController.text, password??passwordController.text);
print(loginResponse.body);
if(loginResponse.body.toLowerCase().contains("success")){
final prefs = await SharedPreferences.getInstance();
prefs.setString("username", usernameController.text);
prefs.setString("password", passwordController.text);
prefs.setString("username", username ?? usernameController.text);
prefs.setString("password", password?? passwordController.text);
Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false);
}else{
showAlertDialog(context, "Failed to login", "There was an error trying to authorize you in servers.");