Skip to content

Commit

Permalink
Added Input Type
Browse files Browse the repository at this point in the history
Added Gravatar
Added User Page
Fixed User Auth State Logic
  • Loading branch information
ryanhossain9797 committed Oct 28, 2019
1 parent 771f576 commit 52ffb6b
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 58 deletions.
Binary file added images/gravatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:pc_build_assistant/screens/user_screen.dart';

import 'screens/home_screen.dart';
import 'screens/login_screen.dart';
Expand Down Expand Up @@ -40,6 +41,7 @@ class MyApp extends StatelessWidget {
RegistrationScreen.id: (context) => RegistrationScreen(),
HomeScreen.id: (context) => HomeScreen(),
ResetScreen.id: (context) => ResetScreen(),
UserScreen.id: (context) => UserScreen(),
},
initialRoute: WelcomeScreen.id,
);
Expand Down
43 changes: 24 additions & 19 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:pc_build_assistant/components/pc_component.dart';
import 'package:pc_build_assistant/components/rounded_button.dart';
import 'package:pc_build_assistant/constants.dart';
import 'package:pc_build_assistant/screens/login_screen.dart';
import 'package:pc_build_assistant/screens/user_screen.dart';
import 'package:simple_gravatar/simple_gravatar.dart';

class HomeScreen extends StatefulWidget {
static String id = "/homeScreenId";
Expand All @@ -17,7 +19,6 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
final FirebaseAuth _auth = FirebaseAuth.instance;
FirebaseUser _currentUser;
String _userName;
int _index = 0;

GlobalKey _componentsKey = GlobalKey();
Expand All @@ -32,6 +33,7 @@ class _HomeScreenState extends State<HomeScreen> {
void initState() {
getCurrentUser();
super.initState();

WidgetsBinding.instance.addPostFrameCallback((_) => initialSize());
}

Expand All @@ -52,12 +54,9 @@ class _HomeScreenState extends State<HomeScreen> {
FirebaseUser user;
try {
user = await _auth.currentUser();
if (user != null) {
setState(() {
_currentUser = user;
_userName = _currentUser.email;
});
}
setState(() {
_currentUser = user;
});
} catch (excp) {
print("error occured $excp");
}
Expand All @@ -82,21 +81,27 @@ class _HomeScreenState extends State<HomeScreen> {
onTap: () async {
if (_currentUser == null) {
await Navigator.pushNamed(context, LoginScreen.id);
getCurrentUser();
} else {
await Navigator.pushNamed(context, UserScreen.id);
}
getCurrentUser();
},
child: CircleAvatar(
backgroundColor: kContinueButtonColor,
child: _userName != null
? Text(
_userName.substring(0, 1).toUpperCase(),
style: TextStyle(fontSize: 20, color: Colors.white),
)
: Icon(
Icons.person,
color: Colors.white,
child: _currentUser != null
? CircleAvatar(
child: ClipOval(
child: Image.network(
Gravatar(_currentUser.email).imageUrl(
defaultImage: GravatarImage.retro,
fileExtension: true,
),
),
),
),
)
: CircleAvatar(
backgroundColor: kLoginButtonColor,
foregroundColor: Color(0xFFFFFFFF),
child: Icon(Icons.person),
),
),
)
],
Expand Down
34 changes: 22 additions & 12 deletions lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -40,18 +41,27 @@ class _LoginScreenState extends State<LoginScreen> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Login",
style: TextStyle(fontFamily: "Rodin"),
),
centerTitle: true,
return ModalProgressHUD(
progressIndicator: TyperAnimatedTextKit(
isRepeatingAnimation: false,
duration: Duration(milliseconds: 600),
text: ["Loading"],
textStyle: ThemeData.fallback()
.accentTextTheme
.display1
.copyWith(color: Colors.white, fontFamily: "Rodin", fontSize: 20),
),
body: ModalProgressHUD(
color: kLoginButtonColor,
inAsyncCall: _busy,
child: Padding(
color: kLoginButtonColor,
inAsyncCall: _busy,
child: Scaffold(
appBar: AppBar(
title: Text(
"Login",
style: TextStyle(fontFamily: "Rodin"),
),
centerTitle: true,
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -78,6 +88,7 @@ class _LoginScreenState extends State<LoginScreen> {
Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: TextField(
keyboardType: TextInputType.emailAddress,
controller: _emailController,
decoration: kLoginTextFieldDecoration.copyWith(
hintText: "Your Email"),
Expand Down Expand Up @@ -117,7 +128,6 @@ class _LoginScreenState extends State<LoginScreen> {
_busy = false;
});
Navigator.popUntil(context, (route) {
print(route.settings.name);
if (route.settings.name == WelcomeScreen.id) {
Navigator.pushNamed(context, HomeScreen.id);
return true;
Expand Down
34 changes: 22 additions & 12 deletions lib/screens/registration_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -44,19 +45,27 @@ class _RegistrationScreenState extends State<RegistrationScreen> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Register",
style: TextStyle(fontFamily: "Rodin"),
),
centerTitle: true,
return ModalProgressHUD(
progressIndicator: TyperAnimatedTextKit(
isRepeatingAnimation: false,
duration: Duration(milliseconds: 600),
text: ["Registering"],
textStyle: ThemeData.fallback()
.accentTextTheme
.display1
.copyWith(color: Colors.white, fontFamily: "Rodin", fontSize: 20),
),
body: ModalProgressHUD(
// Encapsulates The Entire Body With a Progress Indicator
color: kRegisterButtonColor,
inAsyncCall: _busy,
child: Padding(
color: kLoginButtonColor,
inAsyncCall: _busy,
child: Scaffold(
appBar: AppBar(
title: Text(
"Register",
style: TextStyle(fontFamily: "Rodin"),
),
centerTitle: true,
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -83,6 +92,7 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: TextField(
keyboardType: TextInputType.emailAddress,
controller: _emailController,
decoration: kRegisterTextFieldDecoration.copyWith(
hintText: "Your Email"),
Expand Down
41 changes: 28 additions & 13 deletions lib/screens/reset_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -36,20 +37,29 @@ class _ResetScreenState extends State<ResetScreen> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Reset Password",
style: TextStyle(fontFamily: "Rodin"),
),
centerTitle: true,
backgroundColor: Colors.transparent,
elevation: 0.0,
return ModalProgressHUD(
progressIndicator: TyperAnimatedTextKit(
isRepeatingAnimation: false,
duration: Duration(milliseconds: 300),
text: ["Checking"],
textStyle: ThemeData.fallback()
.accentTextTheme
.display1
.copyWith(color: Colors.white, fontFamily: "Rodin", fontSize: 20),
),
body: ModalProgressHUD(
color: kLoginButtonColor,
inAsyncCall: _busy,
child: Padding(
color: kLoginButtonColor,
inAsyncCall: _busy,
child: Scaffold(
appBar: AppBar(
title: Text(
"Reset Password",
style: TextStyle(fontFamily: "Rodin"),
),
centerTitle: true,
backgroundColor: Colors.transparent,
elevation: 0.0,
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -76,6 +86,7 @@ class _ResetScreenState extends State<ResetScreen> {
Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: TextField(
keyboardType: TextInputType.emailAddress,
controller: _emailController,
decoration: kResetTextFieldDecoration.copyWith(
hintText: "Your Email"),
Expand Down Expand Up @@ -122,6 +133,10 @@ class _ResetScreenState extends State<ResetScreen> {
_message = "Something went wrong";
});
}
} else if (e.code == kWrongEmail) {
setState(() {
_message = "User does not exist";
});
} else {
setState(() {
_message = "Something went wrong";
Expand Down
Loading

0 comments on commit 52ffb6b

Please sign in to comment.