Last active
March 10, 2021 15:20
-
-
Save samuelematias/de92102c4b6b1e198160d05a5a52252e to your computer and use it in GitHub Desktop.
Example of cubit state using const/factory in only one state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
part of 'url_cubit.dart'; | |
enum ErrorType { defaultError, urlAlreadyExists, none } | |
class UrlState extends Equatable { | |
const UrlState({ | |
this.isLoading, | |
this.url, | |
this.urlList, | |
this.hasError, | |
}); | |
/// const way (syntax sugar for factory way) | |
const UrlState.initial() | |
: this( | |
isLoading: false, | |
url: const UrlModel(), | |
urlList: const <UrlShortenerModel>[], | |
hasError: ErrorType.none, | |
); | |
/// Factory way | |
// factory UrlState.initial() => const UrlState( | |
// isLoading: false, | |
// url: UrlModel(), | |
// urlList: <UrlShortenerModel>[], | |
// hasError: ErrorType.none, | |
// ); | |
final bool isLoading; | |
final UrlModel url; | |
final List<UrlShortenerModel> urlList; | |
final ErrorType hasError; | |
@override | |
List<Object> get props => [ | |
isLoading, | |
url, | |
urlList, | |
hasError, | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment