초기 커밋
This commit is contained in:
34
lib/shared/providers/auth_provider.dart
Normal file
34
lib/shared/providers/auth_provider.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../features/auth/domain/entities/user.dart';
|
||||
import '../../features/auth/presentation/providers/auth_providers.dart';
|
||||
|
||||
part 'auth_provider.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class AuthState extends _$AuthState {
|
||||
@override
|
||||
FutureOr<User?> build() async {
|
||||
final repository = ref.read(authRepositoryProvider);
|
||||
final isLoggedIn = await repository.isLoggedIn();
|
||||
if (isLoggedIn) {
|
||||
return repository.getCurrentUser();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void setUser(User user) {
|
||||
state = AsyncData(user);
|
||||
}
|
||||
|
||||
void clearUser() {
|
||||
state = const AsyncData(null);
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
final repository = ref.read(authRepositoryProvider);
|
||||
await repository.logout();
|
||||
state = const AsyncData(null);
|
||||
}
|
||||
}
|
||||
14
lib/shared/providers/connectivity_provider.dart
Normal file
14
lib/shared/providers/connectivity_provider.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'connectivity_provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
Stream<bool> connectivityStatus(Ref ref) {
|
||||
return Connectivity().onConnectivityChanged.map(
|
||||
(results) => results.any(
|
||||
(result) => result != ConnectivityResult.none,
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user