Skip to content

Commit

Permalink
Merge pull request #34 from NODO-UH/develop
Browse files Browse the repository at this point in the history
Release v1.1.0
  • Loading branch information
leynier authored Apr 26, 2021
2 parents 3441d92 + 56d4d23 commit 36868ad
Show file tree
Hide file tree
Showing 28 changed files with 531 additions and 131 deletions.
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ analyzer:
- lib/**/*.freezed.dart
strong-mode:
implicit-casts: false
errors:
todo: warning

linter:
rules:
Expand Down
1 change: 1 addition & 0 deletions lib/src/data/enums/home_item_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ enum HomeItemEnum {
ResetPassword,
AboutUs,
HelpfulLinks,
Faqs,
Logout,
}
14 changes: 14 additions & 0 deletions lib/src/data/local/local_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ abstract class ILocalStorage {
});

Future<void> invalidateCredentials();

Future<bool> isFirstTime();

Future<void> useFirstTime();
}

class LocalStorage implements ILocalStorage {
Expand Down Expand Up @@ -111,6 +115,16 @@ class LocalStorage implements ILocalStorage {
sessionData.isLoggedInto = false;
sessionData.rememberMe = false;
}

@override
Future<bool> isFirstTime() async {
return prefs.getBool(APP_FIRST_TIME) ?? true;
}

@override
Future<void> useFirstTime() async {
await prefs.setBool(APP_FIRST_TIME, false);
}
}

class SessionData {
Expand Down
11 changes: 7 additions & 4 deletions lib/src/data/models/status.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import 'package:gestionuh/src/data/models/base_model.dart';
import 'package:json_annotation/json_annotation.dart';

part 'status.g.dart';

@JsonSerializable()
class Status extends BaseModel {
bool? status;

Status({this.status});

factory Status.fromJson(Map<String, dynamic> json) => _$StatusFromJson(json);

@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
}
Map<String, dynamic> toJson() => _$StatusToJson(this);
}
17 changes: 17 additions & 0 deletions lib/src/data/models/status.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class DependencyInjection {
I.registerFactory<LoginBloc>(
() => LoginBloc(
authRepository: I(),
localStorage: I(),
),
);

Expand Down
1 change: 1 addition & 0 deletions lib/src/presentation/blocs/home_bloc/home_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
if (profile.hasEmail ?? false) HomeItemEnum.MailQuota,
HomeItemEnum.ResetPassword,
HomeItemEnum.HelpfulLinks,
HomeItemEnum.Faqs,
HomeItemEnum.AboutUs,
HomeItemEnum.Separator,
HomeItemEnum.Logout,
Expand Down
13 changes: 12 additions & 1 deletion lib/src/presentation/blocs/login_bloc/login_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:gestionuh/src/data/local/local_storage.dart';
import 'package:gestionuh/src/data/repositories/repositories.dart';
import 'package:gestionuh/src/utils/constants/constants.dart';

part 'login_bloc.freezed.dart';
part 'login_event.dart';
part 'login_state.dart';
part 'login_bloc.freezed.dart';

class LoginBloc extends Bloc<LoginEvent, LoginState> {
final AuthRepository authRepository;
final ILocalStorage localStorage;

LoginBloc({
required this.authRepository,
required this.localStorage,
}) : super(const LoginState.initial());

@override
Stream<LoginState> mapEventToState(LoginEvent event) async* {
yield* event.map(
start: loginStart,
loginAttempted: loginAttemptedHandler,
);
}

Stream<LoginState> loginStart(_$LoginStart event) async* {
if (await localStorage.isFirstTime()) {
await localStorage.useFirstTime();
yield const LoginState.firstTime();
}
}

Stream<LoginState> loginAttemptedHandler(_$LoginAttempted event) async* {
yield const LoginState.inProgress();
final result = await authRepository.login(
Expand Down
Loading

0 comments on commit 36868ad

Please sign in to comment.