26 lines
846 B
Dart
26 lines
846 B
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../../core/network/dio_client.dart';
|
|
import '../domain/indian_state.dart';
|
|
|
|
class IndianStatesNotifier extends AsyncNotifier<List<IndianState>> {
|
|
@override
|
|
Future<List<IndianState>> build() async {
|
|
return _fetchStates();
|
|
}
|
|
|
|
Future<List<IndianState>> _fetchStates() async {
|
|
final response = await DioClient().dio.get('/master/states').timeout(
|
|
const Duration(seconds: 5),
|
|
onTimeout: () => throw Exception('Connection timed out'),
|
|
);
|
|
if (response.data == null || response.data.toString().isEmpty) {
|
|
return [];
|
|
}
|
|
return (response.data as List).map((e) => IndianState.fromJson(e)).toList();
|
|
}
|
|
}
|
|
|
|
final indianStatesProvider = AsyncNotifierProvider<IndianStatesNotifier, List<IndianState>>(() {
|
|
return IndianStatesNotifier();
|
|
});
|