-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhome_state.dart
36 lines (29 loc) · 920 Bytes
/
home_state.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
part of 'home_bloc.dart';
enum HomeStatus { initial, loading, success, error }
class HomeState extends Equatable {
const HomeState({
this.movies = const <Movie>[],
this.status = HomeStatus.initial,
});
factory HomeState.initialState() => const HomeState();
HomeState copyWith({
List<Movie>? movies,
HomeStatus? status,
}) =>
HomeState(
movies: movies ?? this.movies,
status: status ?? this.status,
);
final List<Movie> movies;
final HomeStatus status;
@override
List<Object> get props => [movies, status];
}
extension HomeStateX on HomeState {
bool get _moviesEmpty => movies.isEmpty;
bool get _error => status == HomeStatus.error;
bool get moviesLoading => status == HomeStatus.loading;
bool get loading => moviesLoading && _moviesEmpty;
bool get error => _error && _moviesEmpty;
bool get errorLoadMoreMovie => _error && !_moviesEmpty;
}