-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from nimblehq/feature/13-integrate-keep-user-l…
…ogged-in
- Loading branch information
Showing
14 changed files
with
279 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:survey_flutter/usecases/base/base_use_case.dart'; | ||
import 'package:survey_flutter/usecases/check_user_logged_in_use_case.dart'; | ||
|
||
final splashViewModelProvider = | ||
AsyncNotifierProvider.autoDispose<SplashViewModel, bool>( | ||
SplashViewModel.new); | ||
|
||
class SplashViewModel extends AutoDisposeAsyncNotifier<bool> { | ||
@override | ||
FutureOr<bool> build() async { | ||
return _checkUserLoggedIn(); | ||
} | ||
|
||
Future<bool> _checkUserLoggedIn() async { | ||
final checkUserLoggedInUseCase = ref.read(checkUserLoggedInUseCaseProvider); | ||
final result = await checkUserLoggedInUseCase(); | ||
return result is Success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:survey_flutter/api/data_sources/token_data_source.dart'; | ||
import 'package:survey_flutter/usecases/base/base_use_case.dart'; | ||
|
||
final checkUserLoggedInUseCaseProvider = | ||
Provider<CheckUserLoggedInUseCase>((ref) { | ||
return CheckUserLoggedInUseCase(ref.watch(tokenDataSourceProvider)); | ||
}); | ||
|
||
class CheckUserLoggedInUseCase implements NoParamsUseCase<bool> { | ||
final TokenDataSource _tokenDataSource; | ||
|
||
CheckUserLoggedInUseCase(this._tokenDataSource); | ||
@override | ||
Future<Result<bool>> call() async { | ||
try { | ||
final _ = await _tokenDataSource.getToken(); | ||
return Success(true); | ||
} catch (error) { | ||
return Failed(UseCaseException(error)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:survey_flutter/model/api_token.dart'; | ||
import 'package:survey_flutter/utils/serializer/serializable.dart'; | ||
|
||
class ApiTokenSerializer extends Serializer<ApiToken> { | ||
@override | ||
ApiToken serialize(Map<String, dynamic> json) { | ||
return ApiToken.fromJson(json); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
abstract class Serializable {} | ||
|
||
abstract class Serializer<T extends Serializable> { | ||
T serialize(Map<String, dynamic> json); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.