84 lines
3.9 KiB
Dart
84 lines
3.9 KiB
Dart
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
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/repository_base_provider_mixin.dart';
|
|
|
|
/// {@template cubit_provider}
|
|
/// Need to implement a [create] function that is responsible for
|
|
/// creating the [Cubit] and a [builder] which will return a child
|
|
/// that have access to the instance via `context.read<Cubit>()`.
|
|
/// It is used as a dependency injection (DI) widget so that a single instance
|
|
/// of a [Cubit] 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 in found in the tree.
|
|
/// To override this behavior, set [smart] to `false`.
|
|
/// {@endtemplate}
|
|
abstract class CubitProviderScreen<Cubit extends blocbase.Cubit<State>,
|
|
State extends Object> extends BlocBaseProviderScreen<Cubit, State>
|
|
with BlocBaseProviderMixin<Cubit>, RepositoryProviderMixin {
|
|
/// {@macro cubit_provider}
|
|
const CubitProviderScreen({super.key, super.lazy = true, super.smart = true});
|
|
}
|
|
|
|
/// {@template cubit_consumer}
|
|
/// [CubitConsumerScreen] 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 [Cubit] 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 [Cubit] when
|
|
/// the BlocConsumer is initialized.
|
|
/// [shouldListenWhen] and [shouldBuildWhen] are optional and if they
|
|
/// aren't implemented, they will default to `true`.
|
|
///
|
|
/// An optional [parent] can also be implemented. This build a wrapper arround
|
|
/// the built BlocConsumer that is **not** rebuild on each state.
|
|
/// {@endtemplate}
|
|
abstract class CubitConsumerScreen<Cubit extends blocbase.Cubit<State>,
|
|
State extends Object> extends BlocBaseConsumerScreen<Cubit, State>
|
|
with BlocBaseProviderMixin<Cubit>, RepositoryProviderMixin {
|
|
/// {@macro cubit_consumer}
|
|
const CubitConsumerScreen({super.key});
|
|
}
|
|
|
|
/// {@template cubit_screen}
|
|
/// Provide AND access to a [Cubit].
|
|
///
|
|
/// This extends [CubitConsumerScreen] with the methods
|
|
// ignore: comment_references
|
|
/// of [CubitProviderScreen].
|
|
/// {@endtemplate}
|
|
abstract class CubitScreen<Cubit extends blocbase.Cubit<State>,
|
|
State extends Object> extends BlocBaseScreen<Cubit, State>
|
|
with BlocBaseProviderMixin<Cubit>, RepositoryProviderMixin {
|
|
/// {@macro cubit_screen}
|
|
const CubitScreen({super.key, super.lazy = true, super.smart = true});
|
|
}
|