52 lines
1010 B
Dart
52 lines
1010 B
Dart
|
|
import 'package:meta/meta.dart';
|
|
import 'package:satu/core/models/auth/auth_response.dart';
|
|
|
|
|
|
@immutable
|
|
class UserState {
|
|
final bool isError;
|
|
final bool isLoading;
|
|
final AuthResponse auth;
|
|
|
|
|
|
UserState(
|
|
{this.isError,
|
|
this.isLoading,
|
|
this.auth,
|
|
});
|
|
|
|
factory UserState.initial(UserState payload) => UserState(
|
|
isLoading: false,
|
|
isError: false,
|
|
auth: payload?.auth ?? (AuthResponse()..operation=false),
|
|
);
|
|
|
|
UserState copyWith({
|
|
@required bool isError,
|
|
@required bool isLoading,
|
|
@required AuthResponse auth
|
|
}) {
|
|
return UserState(
|
|
isError: isError ?? this.isError,
|
|
isLoading: isLoading ?? this.isLoading,
|
|
auth: auth ?? this.auth,
|
|
);
|
|
}
|
|
|
|
static UserState fromJson(dynamic json) {
|
|
return json != null
|
|
? UserState(
|
|
auth: AuthResponse.fromMap(json['auth']),
|
|
)
|
|
: null;
|
|
}
|
|
|
|
dynamic toJson() {
|
|
return {
|
|
"auth": auth != null ? auth.toJson() : null,
|
|
};
|
|
}
|
|
}
|
|
|