@@ -3,9 +3,11 @@ import 'dart:async';
3
3
import 'package:bloc/bloc.dart' ;
4
4
import 'package:bloc_concurrency/bloc_concurrency.dart' ; // For transformers
5
5
import 'package:equatable/equatable.dart' ;
6
- import 'package:ht_countries_client/ht_countries_client.dart' ; // For Country model and exceptions
7
- import 'package:ht_countries_repository/ht_countries_repository.dart' ;
8
- // For PaginatedResponse
6
+ import 'package:ht_data_repository/ht_data_repository.dart' ; // Generic Data Repository
7
+ import 'package:ht_shared/ht_shared.dart'
8
+ show
9
+ Country,
10
+ HtHttpException; // Shared models, including Country and standardized exceptions
9
11
10
12
part 'countries_filter_event.dart' ;
11
13
part 'countries_filter_state.dart' ;
@@ -14,14 +16,14 @@ part 'countries_filter_state.dart';
14
16
/// Manages the state for fetching and displaying countries for filtering.
15
17
///
16
18
/// Handles initial fetching and pagination of countries using the
17
- /// provided [HtCountriesRepository ] .
19
+ /// provided [HtDataRepository ] .
18
20
/// {@endtemplate}
19
21
class CountriesFilterBloc
20
22
extends Bloc <CountriesFilterEvent , CountriesFilterState > {
21
23
/// {@macro countries_filter_bloc}
22
24
///
23
- /// Requires a [HtCountriesRepository ] to interact with the data layer.
24
- CountriesFilterBloc ({required HtCountriesRepository countriesRepository})
25
+ /// Requires a [HtDataRepository<Country> ] to interact with the data layer.
26
+ CountriesFilterBloc ({required HtDataRepository < Country > countriesRepository})
25
27
: _countriesRepository = countriesRepository,
26
28
super (const CountriesFilterState ()) {
27
29
on < CountriesFilterRequested > (
@@ -34,7 +36,7 @@ class CountriesFilterBloc
34
36
);
35
37
}
36
38
37
- final HtCountriesRepository _countriesRepository;
39
+ final HtDataRepository < Country > _countriesRepository;
38
40
39
41
/// Number of countries to fetch per page.
40
42
static const _countriesLimit = 20 ;
@@ -53,8 +55,7 @@ class CountriesFilterBloc
53
55
emit (state.copyWith (status: CountriesFilterStatus .loading));
54
56
55
57
try {
56
- // Note: Repository uses 'cursor' parameter name here
57
- final response = await _countriesRepository.fetchCountries (
58
+ final response = await _countriesRepository.readAll (
58
59
limit: _countriesLimit,
59
60
);
60
61
emit (
@@ -66,7 +67,7 @@ class CountriesFilterBloc
66
67
clearError: true , // Clear any previous error
67
68
),
68
69
);
69
- } on CountryFetchFailure catch (e) {
70
+ } on HtHttpException catch (e) {
70
71
emit (state.copyWith (status: CountriesFilterStatus .failure, error: e));
71
72
} catch (e) {
72
73
// Catch unexpected errors
@@ -87,10 +88,9 @@ class CountriesFilterBloc
87
88
emit (state.copyWith (status: CountriesFilterStatus .loadingMore));
88
89
89
90
try {
90
- // Note: Repository uses 'cursor' parameter name here
91
- final response = await _countriesRepository.fetchCountries (
91
+ final response = await _countriesRepository.readAll (
92
92
limit: _countriesLimit,
93
- cursor : state.cursor, // Use the cursor from the current state
93
+ startAfterId : state.cursor, // Use the cursor from the current state
94
94
);
95
95
emit (
96
96
state.copyWith (
@@ -101,7 +101,7 @@ class CountriesFilterBloc
101
101
cursor: response.cursor,
102
102
),
103
103
);
104
- } on CountryFetchFailure catch (e) {
104
+ } on HtHttpException catch (e) {
105
105
// Keep existing data but indicate failure
106
106
emit (state.copyWith (status: CountriesFilterStatus .failure, error: e));
107
107
} catch (e) {
0 commit comments