Navigation Menu

Skip to content

Commit

Permalink
General updates and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
funwithflutter committed Sep 17, 2019
1 parent dde17d3 commit 7f00d74
Show file tree
Hide file tree
Showing 57 changed files with 1,423 additions and 634 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,13 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart"
}
]
}
Binary file added assets/OpenSans-Regular.ttf
Binary file not shown.
Binary file added assets/WorkSans-Regular.ttf
Binary file not shown.
Binary file added assets/confetti.gif
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/fun_with_flutter_grey_icon.png
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/fun_with_flutter_icon.png
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/icons/CustomIcons.ttf
Binary file not shown.
5 changes: 2 additions & 3 deletions lib/blocs/login/login_bloc.dart
Expand Up @@ -35,7 +35,6 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {

@override
Stream<LoginState> mapEventToState(LoginEvent event) async* {
print('here');
if (event is EmailChanged) {
yield* _mapEmailChangedToState(event.email);
} else if (event is PasswordChanged) {
Expand Down Expand Up @@ -67,7 +66,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
await _userRepository.signInWithGoogle().then((onValue) {
state = LoginState.success();
}).catchError((onError) {
state = LoginState.failure();
state = LoginState.failure(onError);
});
yield state;
}
Expand All @@ -83,7 +82,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
.then((onValue) {
state = LoginState.success();
}).catchError((onError) {
state = LoginState.failure();
state = LoginState.failure(onError);
});
yield state;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/blocs/login/login_event.dart
Expand Up @@ -43,14 +43,14 @@ class LoginWithGooglePressed extends LoginEvent {
}

class LoginWithCredentialsPressed extends LoginEvent {
final String email;
final String password;

LoginWithCredentialsPressed({@required this.email, @required this.password})
: super([email, password]);

final String email;
final String password;

@override
String toString() {
return 'LoginWithCredentialsPressed { email: $email, password: $password }';
}
}
}
10 changes: 8 additions & 2 deletions lib/blocs/login/login_state.dart
Expand Up @@ -7,6 +7,7 @@ class LoginState {
final bool isSubmitting;
final bool isSuccess;
final bool isFailure;
final String errorMessage;

bool get isFormValid => isEmailValid && isPasswordValid;

Expand All @@ -16,6 +17,7 @@ class LoginState {
@required this.isSubmitting,
@required this.isSuccess,
@required this.isFailure,
this.errorMessage = '',
});

factory LoginState.empty() {
Expand All @@ -38,13 +40,14 @@ class LoginState {
);
}

factory LoginState.failure() {
factory LoginState.failure(String errorMessage) {
return LoginState(
isEmailValid: true,
isPasswordValid: true,
isSubmitting: false,
isSuccess: false,
isFailure: true,
errorMessage: errorMessage,
);
}

Expand Down Expand Up @@ -78,13 +81,15 @@ class LoginState {
bool isSubmitting,
bool isSuccess,
bool isFailure,
String errorMessage,
}) {
return LoginState(
isEmailValid: isEmailValid ?? this.isEmailValid,
isPasswordValid: isPasswordValid ?? this.isPasswordValid,
isSubmitting: isSubmitting ?? this.isSubmitting,
isSuccess: isSuccess ?? this.isSuccess,
isFailure: isFailure ?? this.isFailure,
errorMessage: errorMessage ?? this.errorMessage,
);
}

Expand All @@ -96,6 +101,7 @@ class LoginState {
isSubmitting: $isSubmitting,
isSuccess: $isSuccess,
isFailure: $isFailure,
errorMessage: $errorMessage,
}''';
}
}
}
2 changes: 1 addition & 1 deletion lib/blocs/page/page_state.dart
@@ -1 +1 @@
enum PageState { customWidgets, about, home, tagsFilter }
enum PageState { packages, about, home, blog }
31 changes: 20 additions & 11 deletions lib/blocs/register/register_bloc.dart
Expand Up @@ -28,7 +28,8 @@ class RegisterBloc extends Bloc<RegisterEvent, RegisterState> {
final debounceStream = observableStream.where((event) {
return (event is EmailChanged || event is PasswordChanged);
}).debounceTime(Duration(milliseconds: 300));
return super.transformEvents(nonDebounceStream.mergeWith([debounceStream]), next);
return super
.transformEvents(nonDebounceStream.mergeWith([debounceStream]), next);
}

@override
Expand Down Expand Up @@ -60,15 +61,23 @@ class RegisterBloc extends Bloc<RegisterEvent, RegisterState> {
String email,
String password,
) async* {
RegisterState state;
yield RegisterState.loading();
try {
await _userRepository.signUp(
email: email,
password: password,
);
yield RegisterState.success();
} catch (_) {
yield RegisterState.failure();
}
await _userRepository
.signUp(
email: email,
password: password,
)
.then(
(onValue) {
state = RegisterState.success();
},
).catchError(
(onError) {
print(onError);
state = RegisterState.failure(onError);
},
);
yield state;
}
}
}
10 changes: 8 additions & 2 deletions lib/blocs/register/register_state.dart
Expand Up @@ -7,6 +7,7 @@ class RegisterState {
final bool isSubmitting;
final bool isSuccess;
final bool isFailure;
final String errorMessage;

bool get isFormValid => isEmailValid && isPasswordValid;

Expand All @@ -16,6 +17,7 @@ class RegisterState {
@required this.isSubmitting,
@required this.isSuccess,
@required this.isFailure,
this.errorMessage = '',
});

factory RegisterState.empty() {
Expand All @@ -38,13 +40,14 @@ class RegisterState {
);
}

factory RegisterState.failure() {
factory RegisterState.failure(String error) {
return RegisterState(
isEmailValid: true,
isPasswordValid: true,
isSubmitting: false,
isSuccess: false,
isFailure: true,
errorMessage: error,
);
}

Expand Down Expand Up @@ -78,13 +81,15 @@ class RegisterState {
bool isSubmitting,
bool isSuccess,
bool isFailure,
String errorMessage,
}) {
return RegisterState(
isEmailValid: isEmailValid ?? this.isEmailValid,
isPasswordValid: isPasswordValid ?? this.isPasswordValid,
isSubmitting: isSubmitting ?? this.isSubmitting,
isSuccess: isSuccess ?? this.isSuccess,
isFailure: isFailure ?? this.isFailure,
errorMessage: errorMessage ?? this.errorMessage,
);
}

Expand All @@ -96,6 +101,7 @@ class RegisterState {
isSubmitting: $isSubmitting,
isSuccess: $isSuccess,
isFailure: $isFailure,
errorMessage: $errorMessage,
}''';
}
}
}
1 change: 0 additions & 1 deletion lib/repository/blog_repository.dart
Expand Up @@ -14,7 +14,6 @@ class BlogRepository {
final data = await _blogApi.fetchData();
return Blog.fromJson(data);
} catch (e) {
print(e);
return e;
}
}
Expand Down
31 changes: 20 additions & 11 deletions lib/repository/user_repository.dart
Expand Up @@ -10,12 +10,12 @@ class UserRepository {
final Auth _firebaseAuth;
final GoogleAuthProvider _googleSignIn;

Future<void> signInWithGoogle() async {
Future<UserCredential> signInWithGoogle() async {
try {
await _firebaseAuth.signInWithPopup(_googleSignIn);
return await _firebaseAuth.signInWithPopup(_googleSignIn);
} catch (e) {
print('Error in sign in with google: $e');
return e;
throw '$e';
}
}

Expand All @@ -25,26 +25,35 @@ class UserRepository {
return await _firebaseAuth.signInWithEmailAndPassword(email, password);
} catch (e) {
print('Error in sign in with credentials: $e');
return e;
// return e;
throw '$e';
}
}

Future<void> signUp({String email, String password}) async {
Future<UserCredential> signUp({String email, String password}) async {
try {
return await _firebaseAuth.createUserWithEmailAndPassword(
email,
password,
);
} catch (e) {
print ('Error in sign up with credentials: $e');
return e;
print('Error siging in with credentials: $e');
throw '$e';
// throw Error('Error signing up with credentials: $e');
// return e;
}
}

Future<void> signOut() async {
return Future.wait([
_firebaseAuth.signOut(),
]);
Future<dynamic> signOut() async {
try {
return Future.wait([
_firebaseAuth.signOut(),
]);
} catch (e) {
print ('Error signin out: $e');
// return e;
throw '$e';
}
}

Future<bool> isSignedIn() async {
Expand Down
28 changes: 15 additions & 13 deletions lib/themes.dart
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';

class AppTheme {
static const Color primaryColor = Colors.black;
static const Color accentColor = Colors.pink;
static const Color fadedBlackColor = Color.fromRGBO(32, 33, 36, 100);
static const Color primaryColor = Color.fromRGBO(84, 197, 248, 1);
static const Color secondaryColor = Color.fromRGBO(1, 87, 155, 1);
static const Color accentColor = Color.fromRGBO(255, 86, 120, 1);
static const Color alternateColor = Color.fromRGBO(255, 224, 116, 1);
static const Color fadedBlackColor = Color.fromRGBO(32, 33, 36, 1);
static Color errorColor = Colors.red[300];

static const fontFamilyWorkSans = 'WorkSans';
Expand All @@ -22,19 +24,19 @@ class AppTheme {
static ThemeData theme() {
return ThemeData(
primaryColor: primaryColor,

accentColor: accentColor.withOpacity(0.8),
accentColor: accentColor,
buttonTheme: const ButtonThemeData(textTheme: ButtonTextTheme.normal),
dividerColor: accentColor,
errorColor: errorColor,
// scaffoldBackgroundColor: Colors.grey[100],
textTheme: const TextTheme(
display1: TextStyle(
fontSize: 28,
fontFamily: fontFamilyWorkSans,
),
title: TextStyle(
fontSize: fontSizeMedium,
),
// display1: TextStyle(
// fontSize: 28,
// fontFamily: fontFamilyWorkSans,
// ),
// title: TextStyle(
// fontFamily: fontFamilyWorkSans
// ),
body1: TextStyle(
fontSize: fontSizeMedium,
),
Expand All @@ -55,7 +57,7 @@ class AppTheme {
size: 30,
),
iconTheme: const IconThemeData(
color: Colors.pink,
color: accentColor,
size: 30,
),
);
Expand Down

0 comments on commit 7f00d74

Please sign in to comment.