Skip to content

Commit

Permalink
Added auth screen, data entry screen and new text logo
Browse files Browse the repository at this point in the history
  • Loading branch information
noobcoder17 committed Sep 1, 2020
1 parent a0aa12d commit cbba4d3
Show file tree
Hide file tree
Showing 9 changed files with 548 additions and 70 deletions.
Binary file added assets/icons/google.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/big_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions lib/providers/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class AuthProvider extends ChangeNotifier {
}
}

void clearGoogleAccount()async{
await _googleSignIn.signOut();
notifyListeners();
}

void signOut() async {
await _googleSignIn.signOut();
await _firebaseAuth.signOut();
Expand Down
196 changes: 142 additions & 54 deletions lib/screens/auth_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:drinkable/screens/data_entry_screen.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:provider/provider.dart';
import '../widgets/custom_drawer.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_fonts/google_fonts.dart';

class AuthScreen extends StatefulWidget {
static const routeName = 'auth-screen';
Expand All @@ -22,65 +21,154 @@ class _AuthScreenState extends State<AuthScreen> {
});
}

// void checkSignedIn(BuildContext context) async {
// toggleLoading();
// try{
// User user = await FirebaseAuth.instance.currentUser;
// if(user==null){
// print('user not logged in');
// //toggleLoading();
// }else{
// Navigator.of(context).popAndPushNamed(CustomDrawer.routeName);
// return;
// }
// }catch(e){
// print(e);
// }
// }
void selectAccount(BuildContext ctx) async {
toggleLoading();
bool newuser = await Provider.of<AuthProvider>(ctx,listen: false).selectGoogleAcount();
print('new user $newuser');
if(!newuser){
await Provider.of<AuthProvider>(ctx,listen: false).signIn();
}else{
toggleLoading();
}
}

@override
Widget build(BuildContext ctx) {
print('Auth screen');
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Auth screen'),
actions: [
IconButton(
icon: Icon(Icons.account_circle),
onPressed: ()async{
toggleLoading();
bool newuser = await Provider.of<AuthProvider>(ctx,listen: false).selectGoogleAcount();
print('new user $newuser');
if(!newuser){
await Provider.of<AuthProvider>(ctx,listen: false).signIn();
//Navigator.of(context).popAndPushNamed(CustomDrawer.routeName);
}else{
toggleLoading();
}
}
)
],
),
body: Center(
child:_loading ? CircularProgressIndicator() : Consumer<AuthProvider>(
builder: (context, value, child) {
GoogleSignInAccount googleAccount = value.googleAcount;
return googleAccount!=null ? Column(
body: Container(
padding: EdgeInsets.fromLTRB(30, 0, 30, 30),
child: Column(
children: [
Expanded(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset('assets/images/big_logo.png',height: 90,),
SizedBox(height: 10,),
Text(
'drinkable',
style: GoogleFonts.pacifico(
fontWeight: FontWeight.w500,
fontSize: 26,
color: Color.fromARGB(255, 0, 60, 192),
),
),
SizedBox(height: 15,),
Container(
constraints: BoxConstraints(
maxWidth: 250
),
child: Text(
'Drinkable keeps track your daily water intake and reminds you to drink water by sending notification in intervals',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Colors.black.withOpacity(0.60)
),
),
),
],
),
),
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
CircleAvatar(
backgroundImage: NetworkImage(googleAccount.photoUrl),
),
Text(googleAccount.displayName),
Text(googleAccount.email),
RaisedButton(
onPressed: (){
Navigator.of(ctx).pushNamed(DataEntryScreen.routeName);
_loading ? CircularProgressIndicator() : Consumer<AuthProvider>(
builder: (ctx, authProvider, child) {
GoogleSignInAccount googleAccount = authProvider.googleAcount;
return googleAccount!=null ?
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
CircleAvatar(
backgroundImage: NetworkImage(googleAccount.photoUrl),
),
FlatButton(
child: Text('Continue as ${googleAccount.displayName}'),
onPressed: (){
Navigator.of(context).pushNamed(DataEntryScreen.routeName);
},
),
InkWell(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: (){
Provider.of<AuthProvider>(ctx,listen: false).clearGoogleAccount();
},
child: Padding(
padding: EdgeInsets.fromLTRB(10, 10, 0, 10),
child: Icon(Icons.clear),
),
),
],
) : GestureDetector(
onTap: (){
selectAccount(context);
},
child: Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)
),
color: Colors.blueAccent,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
padding: EdgeInsets.all(3),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8)
),
child: Image.asset('assets/icons/google.png',height: 20,)
),
Text(
'Continue with Google',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w500
),
)
],
),
),
),
);

},
),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 0),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
style: TextStyle(
color: Colors.black,
fontSize: 12
),
children: [
TextSpan(
text: 'By signing up you accept the ',
),
TextSpan(
text: 'Terms of Service and Privacy Policy.',
style: TextStyle(
fontWeight: FontWeight.w500
)
)
]
),
)
)
],
) : Text('No account selected');
},
)
)
],
),
),
);
}
Expand Down
Loading

0 comments on commit cbba4d3

Please sign in to comment.