Skip to content

Instantly share code, notes, and snippets.

@samuelematias
Last active March 10, 2021 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelematias/de92102c4b6b1e198160d05a5a52252e to your computer and use it in GitHub Desktop.
Save samuelematias/de92102c4b6b1e198160d05a5a52252e to your computer and use it in GitHub Desktop.
Example of cubit state using const/factory in only one state.
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