Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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