refactor: split providers into feature modules

This commit is contained in:
Artem Kokos
2026-04-27 23:21:47 +07:00
parent eed04e9122
commit 872ddf9513
12 changed files with 925 additions and 924 deletions

View File

@@ -0,0 +1,37 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../app/error_message.dart';
import '../../../app/load_state.dart';
import '../../../models/auth_info.dart';
import '../../shared/providers/core_providers.dart';
final authInfoProvider =
NotifierProvider<AuthInfoNotifier, LoadState<AuthInfo?>>(
() => AuthInfoNotifier(),
);
class AuthInfoNotifier extends Notifier<LoadState<AuthInfo?>> {
@override
LoadState<AuthInfo?> build() => const LoadState.idle(null);
Future<AuthInfo?> load({bool failOnError = false}) async {
state = LoadState.loading(state.data);
try {
final api = ref.read(apiProvider);
final res = await api.getAuthMe();
final authInfo = AuthInfo.fromApi(res.data);
state = LoadState.data(authInfo);
return authInfo;
} catch (e) {
state = LoadState.error(null, describeLoadError(e));
if (failOnError) rethrow;
return null;
}
}
void clear() => state = const LoadState.idle(null);
void restore(LoadState<AuthInfo?> restoredState) => state = restoredState;
bool get isAdmin => state.data?.isAdmin == true;
}