// Copyright (C) 2022 WYATT GROUP // Please see the AUTHORS file for details. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . import 'package:flutter_bloc/flutter_bloc.dart' as blocbase; import 'package:wyatt_bloc_helper/src/bloc_base/bloc_base_consumer_screen.dart'; import 'package:wyatt_bloc_helper/src/bloc_base/bloc_base_provider_screen.dart'; import 'package:wyatt_bloc_helper/src/bloc_base/bloc_base_screen.dart'; import 'package:wyatt_bloc_helper/src/mixins/bloc_base_provider_mixin.dart'; import 'package:wyatt_bloc_helper/src/mixins/bloc_provider_mixin.dart'; import 'package:wyatt_bloc_helper/src/mixins/repository_base_provider_mixin.dart'; /// {@template bloc_provider} /// Need to implement a [create] function that is responsible for /// creating the [Bloc] and a [builder] which will return a child /// that have access to the instance via `context.read()`. /// It is used as a dependency injection (DI) widget so that a single instance /// of a [Bloc] can be provided to multiple widgets within a subtree. /// /// It automatically handles closing the instance when used with [create]. /// By default, [create] is called only when the instance is accessed. /// To override this behavior, set [lazy] to `false`. /// /// By default, it provide already provided instance found in the tree. /// To override this behavior, set [smart] to `false`. /// {@endtemplate} abstract class BlocProviderScreen, Event, State extends Object> extends BlocBaseProviderScreen with BlocBaseProviderMixin, RepositoryProviderMixin, BlocProviderMixin { /// {@macro bloc_provider} const BlocProviderScreen({super.key, super.lazy = true, super.smart = true}); } /// {@template bloc_consumer} /// [BlocConsumerScreen] exposes [onBuild] and [onListen] in order react /// to new states. /// /// An optional [shouldBuildWhen] and [shouldListenWhen] can be implemented /// for more granular control over when [onListen] and [onBuild] are called. /// The [shouldListenWhen] and [shouldBuildWhen] will be invoked on /// each [Bloc] or `state` change. /// They each take the previous `state` and current `state` and must return /// a [bool] which determines whether or not the [onBuild] and/or [onListen] /// function will be invoked. /// The previous `state` will be initialized to the `state` of the [Bloc] when /// the BlocConsumer is initialized. /// [shouldListenWhen] and [shouldBuildWhen] are optional and if they /// aren't implemented, they will default to `true`. /// /// An optional [onWrap] can also be implemented. This build a wrapper arround /// the built BlocConsumer that is **not** rebuild on each state. /// {@endtemplate} abstract class BlocConsumerScreen, Event, State extends Object> extends BlocBaseConsumerScreen with BlocBaseProviderMixin, RepositoryProviderMixin, BlocProviderMixin { /// {@macro bloc_consumer} const BlocConsumerScreen({super.key}); } /// {@template bloc_screen} /// Provide AND access to a [Bloc]. /// /// This extends [BlocConsumerScreen] with the methods /// of [BlocBaseScreen]. /// {@endtemplate} abstract class BlocScreen, Event, State extends Object> extends BlocBaseScreen with BlocBaseProviderMixin, RepositoryProviderMixin, BlocProviderMixin { /// {@macro bloc_screen} const BlocScreen({super.key, super.lazy = true, super.smart = true}); }