fix: compilation issue with flutter 3.16.0 and generics name
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
This commit is contained in:
parent
375bb8f04a
commit
e030375fec
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
* Copyright (C) 2022 WYATT GROUP
|
||||
* Copyright (C) 2023 WYATT GROUP
|
||||
* Please see the AUTHORS file for details.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -26,6 +26,6 @@ subprojects {
|
||||
project.evaluationDependsOn(':app')
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
tasks.register("clean", Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.17.0 <3.0.0"
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
|
||||
# Dependencies specify other packages that your package needs in order to work.
|
||||
# To automatically upgrade your package dependencies to the latest versions
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -24,10 +24,10 @@ 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
|
||||
/// creating the bloc [B] and a [builder] which will return a child
|
||||
/// that have access to the instance via `context.read<Bloc>()`.
|
||||
/// 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.
|
||||
/// of a bloc [B] 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.
|
||||
@ -36,12 +36,12 @@ import 'package:wyatt_bloc_helper/src/mixins/repository_base_provider_mixin.dart
|
||||
/// By default, it provide already provided instance found in the tree.
|
||||
/// To override this behavior, set [smart] to `false`.
|
||||
/// {@endtemplate}
|
||||
abstract class BlocProviderScreen<Bloc extends blocbase.Bloc<Event, State>,
|
||||
Event, State extends Object> extends BlocBaseProviderScreen<Bloc, State>
|
||||
abstract class BlocProviderScreen<B extends blocbase.Bloc<E, S>, E,
|
||||
S extends Object> extends BlocBaseProviderScreen<B, S>
|
||||
with
|
||||
BlocBaseProviderMixin<Bloc>,
|
||||
BlocBaseProviderMixin<B>,
|
||||
RepositoryProviderMixin,
|
||||
BlocProviderMixin<Bloc, Event> {
|
||||
BlocProviderMixin<B, E> {
|
||||
/// {@macro bloc_provider}
|
||||
const BlocProviderScreen({super.key, super.lazy = true, super.smart = true});
|
||||
}
|
||||
@ -53,11 +53,11 @@ abstract class BlocProviderScreen<Bloc extends blocbase.Bloc<Event, State>,
|
||||
/// 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.
|
||||
/// each bloc [B] 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 previous `state` will be initialized to the `state` of the bloc [B] when
|
||||
/// the BlocConsumer is initialized.
|
||||
/// [shouldListenWhen] and [shouldBuildWhen] are optional and if they
|
||||
/// aren't implemented, they will default to `true`.
|
||||
@ -65,28 +65,28 @@ abstract class BlocProviderScreen<Bloc extends blocbase.Bloc<Event, State>,
|
||||
/// 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 BlocConsumerScreen<Bloc extends blocbase.Bloc<Event, State>,
|
||||
Event, State extends Object> extends BlocBaseConsumerScreen<Bloc, State>
|
||||
abstract class BlocConsumerScreen<B extends blocbase.Bloc<E, S>, E,
|
||||
S extends Object> extends BlocBaseConsumerScreen<B, S>
|
||||
with
|
||||
BlocBaseProviderMixin<Bloc>,
|
||||
BlocBaseProviderMixin<B>,
|
||||
RepositoryProviderMixin,
|
||||
BlocProviderMixin<Bloc, Event> {
|
||||
BlocProviderMixin<B, E> {
|
||||
/// {@macro bloc_consumer}
|
||||
const BlocConsumerScreen({super.key});
|
||||
}
|
||||
|
||||
/// {@template bloc_screen}
|
||||
/// Provide AND access to a [Bloc].
|
||||
/// Provide AND access to a bloc [B].
|
||||
///
|
||||
/// This extends [BlocConsumerScreen] with the methods
|
||||
/// of [BlocBaseScreen].
|
||||
/// {@endtemplate}
|
||||
abstract class BlocScreen<Bloc extends blocbase.Bloc<Event, State>, Event,
|
||||
State extends Object> extends BlocBaseScreen<Bloc, State>
|
||||
abstract class BlocScreen<B extends blocbase.Bloc<E, S>, E, S extends Object>
|
||||
extends BlocBaseScreen<B, S>
|
||||
with
|
||||
BlocBaseProviderMixin<Bloc>,
|
||||
BlocBaseProviderMixin<B>,
|
||||
RepositoryProviderMixin,
|
||||
BlocProviderMixin<Bloc, Event> {
|
||||
BlocProviderMixin<B, E> {
|
||||
/// {@macro bloc_screen}
|
||||
const BlocScreen({super.key, super.lazy = true, super.smart = true});
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -24,11 +24,11 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
/// 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.
|
||||
/// each bloc [B] 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 previous `state` will be initialized to the `state` of the bloc [B] when
|
||||
/// the [BlocConsumer] is initialized.
|
||||
/// [shouldListenWhen] and [shouldBuildWhen] are optional and if they
|
||||
/// aren't implemented, they will default to `true`.
|
||||
@ -36,39 +36,39 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
/// 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 BlocBaseConsumerScreen<Bloc extends BlocBase<State>,
|
||||
State extends Object> extends StatelessWidget {
|
||||
abstract class BlocBaseConsumerScreen<B extends BlocBase<S>, S extends Object>
|
||||
extends StatelessWidget {
|
||||
/// {@macro bloc_base_consumer}
|
||||
const BlocBaseConsumerScreen({super.key});
|
||||
|
||||
/// Takes the previous `state` and the current `state` and is responsible for
|
||||
/// returning a [bool] which determines whether or not to trigger
|
||||
/// [onBuild] with the current `state`.
|
||||
bool shouldBuildWhen(State previous, State current) => true;
|
||||
bool shouldBuildWhen(S previous, S current) => true;
|
||||
|
||||
/// Takes the previous `state` and the current `state` and is responsible for
|
||||
/// returning a [bool] which determines whether or not to trigger
|
||||
/// [onListen] with the current `state`.
|
||||
bool shouldListenWhen(State previous, State current) => true;
|
||||
bool shouldListenWhen(S previous, S current) => true;
|
||||
|
||||
/// The [parent] function which will be invoked on build.
|
||||
/// The [parent] takes a `BuildContext` that **doesn't have** access
|
||||
/// to the [Bloc] or [Cubit].
|
||||
/// to the bloc [B] or [Cubit].
|
||||
Widget parent(BuildContext context, Widget child) => child;
|
||||
|
||||
/// The [onBuild] function which will be invoked on each widget build.
|
||||
/// The [onBuild] takes the `BuildContext` and current `state` and
|
||||
/// must return a widget.
|
||||
Widget onBuild(BuildContext context, State state);
|
||||
Widget onBuild(BuildContext context, S state) => const SizedBox.shrink();
|
||||
|
||||
/// Takes the `BuildContext` along with the `state`
|
||||
/// and is responsible for executing in response to `state` changes.
|
||||
void onListen(BuildContext context, State state) {}
|
||||
void onListen(BuildContext context, S state) {}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => parent(
|
||||
context,
|
||||
BlocConsumer<Bloc, State>(
|
||||
BlocConsumer<B, S>(
|
||||
listenWhen: shouldListenWhen,
|
||||
listener: onListen,
|
||||
buildWhen: shouldBuildWhen,
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -20,10 +20,10 @@ import 'package:wyatt_bloc_helper/src/utils/smart_provider.dart';
|
||||
|
||||
/// {@template bloc_base_provider}
|
||||
/// Need to implement a [create] function that is responsible for
|
||||
/// creating the [Bloc] or [Cubit] and a [builder] which will return a child
|
||||
/// creating the bloc or cubit [B] and a [builder] which will return a child
|
||||
/// that have access to the instance via `context.read<Bloc>()`.
|
||||
/// It is used as a dependency injection (DI) widget so that a single instance
|
||||
/// of a [Bloc] or [Cubit] can be provided to multiple widgets within a subtree.
|
||||
/// of a bloc or cubit [B] 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.
|
||||
@ -32,8 +32,8 @@ import 'package:wyatt_bloc_helper/src/utils/smart_provider.dart';
|
||||
/// By default, it provide already provided instance found in the tree.
|
||||
/// To override this behavior, set [smart] to `false`.
|
||||
/// {@endtemplate}
|
||||
abstract class BlocBaseProviderScreen<Bloc extends BlocBase<State>,
|
||||
State extends Object> extends StatelessWidget {
|
||||
abstract class BlocBaseProviderScreen<B extends BlocBase<S>, S extends Object>
|
||||
extends StatelessWidget {
|
||||
/// {@macro bloc_base_provider}
|
||||
const BlocBaseProviderScreen({
|
||||
super.key,
|
||||
@ -41,32 +41,32 @@ abstract class BlocBaseProviderScreen<Bloc extends BlocBase<State>,
|
||||
this.smart = true,
|
||||
});
|
||||
|
||||
/// Whether the [Bloc] or [Cubit] should be created lazily.
|
||||
/// Defaults to `true` which means the [Bloc] or [Cubit] is created only when
|
||||
/// Whether the bloc or cubit [B] should be created lazily.
|
||||
/// Defaults to `true` which means the bloc or cubit [B] is created only when
|
||||
/// accessed the first time, not when provided.
|
||||
final bool lazy;
|
||||
|
||||
/// Whether this uses [SmartProvider].
|
||||
/// Defaults to `true`. But if you want to provide new [Bloc] or [Cubit]
|
||||
/// Defaults to `true`. But if you want to provide new bloc or cubit [B]
|
||||
/// of a same type in a sub-tree you may have to disable this.
|
||||
final bool smart;
|
||||
|
||||
/// Creates the [Bloc] or [Cubit] to be used.
|
||||
Bloc create(BuildContext context);
|
||||
/// Creates the bloc or cubit [B] to be used.
|
||||
B create(BuildContext context);
|
||||
|
||||
/// Initialize the [Bloc] or [Cubit].
|
||||
/// Initialize the bloc or cubit [B].
|
||||
///
|
||||
/// This function is useful when using with [SmartProvider], because
|
||||
/// if you want to pass an initial event to your bloc you can pass it in
|
||||
/// `create` function but if you re-use the bloc below in the tree this event
|
||||
/// will never be re-pass.
|
||||
Bloc init(BuildContext context, Bloc bloc) => bloc;
|
||||
B init(BuildContext context, B bloc) => bloc;
|
||||
|
||||
/// Creates the child [Widget] to be used.
|
||||
Widget builder(BuildContext context);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SmartProvider.bloc<Bloc, State>(
|
||||
Widget build(BuildContext context) => SmartProvider.bloc<B, S>(
|
||||
context,
|
||||
lazy: lazy,
|
||||
enable: smart,
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -20,14 +20,14 @@ import 'package:wyatt_bloc_helper/src/bloc_base/bloc_base_consumer_screen.dart';
|
||||
import 'package:wyatt_bloc_helper/src/utils/smart_provider.dart';
|
||||
|
||||
/// {@template bloc_base_screen}
|
||||
/// Provide AND access to a [Bloc] or [Cubit].
|
||||
/// Provide AND access to a bloc or cubit [B].
|
||||
///
|
||||
/// This extends [BlocBaseConsumerScreen] with the methods
|
||||
// ignore: comment_references
|
||||
/// of [BlocBaseProviderScreen].
|
||||
/// {@endtemplate}
|
||||
abstract class BlocBaseScreen<Bloc extends BlocBase<State>,
|
||||
State extends Object> extends BlocBaseConsumerScreen<Bloc, State> {
|
||||
abstract class BlocBaseScreen<B extends BlocBase<S>, S extends Object>
|
||||
extends BlocBaseConsumerScreen<B, S> {
|
||||
/// {@macro bloc_base_screen}
|
||||
const BlocBaseScreen({
|
||||
super.key,
|
||||
@ -35,8 +35,8 @@ abstract class BlocBaseScreen<Bloc extends BlocBase<State>,
|
||||
this.smart = true,
|
||||
});
|
||||
|
||||
/// Whether the [Bloc] or [Cubit] should be created lazily.
|
||||
/// Defaults to `true` which means the [Bloc] is created only when
|
||||
/// Whether the bloc or cubit [B] should be created lazily.
|
||||
/// Defaults to `true` which means the bloc is created only when
|
||||
/// accessed the first time, not when provided.
|
||||
final bool lazy;
|
||||
|
||||
@ -45,19 +45,19 @@ abstract class BlocBaseScreen<Bloc extends BlocBase<State>,
|
||||
/// in a sub-tree you may have to disable this.
|
||||
final bool smart;
|
||||
|
||||
/// Creates the [Cubit] or [Bloc] to be used.
|
||||
Bloc create(BuildContext context);
|
||||
/// Creates the cubit or bloc to be used.
|
||||
B create(BuildContext context);
|
||||
|
||||
/// Initialize the [Bloc] or [Cubit].
|
||||
/// Initialize the bloc or cubit [B].
|
||||
///
|
||||
/// This function is useful when using with [SmartProvider], because
|
||||
/// if you want to pass an initial event to your bloc you can pass it in
|
||||
/// `create` function but if you re-use the bloc below in the tree this event
|
||||
/// will never be re-pass.
|
||||
Bloc init(BuildContext context, Bloc bloc) => bloc;
|
||||
B init(BuildContext context, B bloc) => bloc;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SmartProvider.bloc<Bloc, State>(
|
||||
Widget build(BuildContext context) => SmartProvider.bloc<B, S>(
|
||||
context,
|
||||
lazy: lazy,
|
||||
enable: smart,
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -23,10 +23,10 @@ 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
|
||||
/// creating the cubit [C] 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.
|
||||
/// of a cubit [C] 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.
|
||||
@ -35,9 +35,9 @@ import 'package:wyatt_bloc_helper/src/mixins/repository_base_provider_mixin.dart
|
||||
/// 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 {
|
||||
abstract class CubitProviderScreen<C extends blocbase.Cubit<S>,
|
||||
S extends Object> extends BlocBaseProviderScreen<C, S>
|
||||
with BlocBaseProviderMixin<C>, RepositoryProviderMixin {
|
||||
/// {@macro cubit_provider}
|
||||
const CubitProviderScreen({super.key, super.lazy = true, super.smart = true});
|
||||
}
|
||||
@ -49,35 +49,35 @@ abstract class CubitProviderScreen<Cubit extends blocbase.Cubit<State>,
|
||||
/// 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.
|
||||
/// each cubit [C] 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.
|
||||
/// The previous `state` will be initialized to the `state` of the cubit [C]
|
||||
/// 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 {
|
||||
abstract class CubitConsumerScreen<C extends blocbase.Cubit<S>,
|
||||
S extends Object> extends BlocBaseConsumerScreen<C, S>
|
||||
with BlocBaseProviderMixin<C>, RepositoryProviderMixin {
|
||||
/// {@macro cubit_consumer}
|
||||
const CubitConsumerScreen({super.key});
|
||||
}
|
||||
|
||||
/// {@template cubit_screen}
|
||||
/// Provide AND access to a [Cubit].
|
||||
/// Provide AND access to a cubit [C].
|
||||
///
|
||||
/// 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 {
|
||||
abstract class CubitScreen<C extends blocbase.Cubit<S>, S extends Object>
|
||||
extends BlocBaseScreen<C, S>
|
||||
with BlocBaseProviderMixin<C>, RepositoryProviderMixin {
|
||||
/// {@macro cubit_screen}
|
||||
const CubitScreen({super.key, super.lazy = true, super.smart = true});
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -18,10 +18,10 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
/// A mixin that provides implementation of helper methods for
|
||||
/// [Bloc] and [Cubit] widgets.
|
||||
mixin BlocBaseProviderMixin<Bloc extends BlocBase<Object>> {
|
||||
/// bloc and cubit [B] widgets.
|
||||
mixin BlocBaseProviderMixin<B extends BlocBase<Object>> {
|
||||
/// Returns the [BlocBase] used by this [BlocBaseProviderMixin].
|
||||
Bloc bloc(BuildContext context) => context.read<Bloc>();
|
||||
B bloc(BuildContext context) => context.read<B>();
|
||||
|
||||
/// Returns another [BlocBase] **not** used by this [BlocBaseProviderMixin].
|
||||
/// Short hand for `context.read<AnotherBloc>();`
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -17,12 +17,11 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart' as blocbase;
|
||||
|
||||
/// [Bloc] specific mixin that provides implementation
|
||||
/// Bloc [B] specific mixin that provides implementation
|
||||
/// of helper methods for events.
|
||||
mixin BlocProviderMixin<Bloc extends blocbase.Bloc<Event, Object>, Event> {
|
||||
/// Add an event to the [Bloc].
|
||||
mixin BlocProviderMixin<B extends blocbase.Bloc<E, Object>, E> {
|
||||
/// Add an event to the [B].
|
||||
///
|
||||
/// Short hand for `context.read<Bloc>().add(event)`.
|
||||
void add(BuildContext context, Event event) =>
|
||||
context.read<Bloc>().add(event);
|
||||
void add(BuildContext context, E event) => context.read<B>().add(event);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -20,7 +20,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
/// A mixin that provides implementation of helper methods for
|
||||
/// Repository widgets.
|
||||
mixin RepositoryProviderMixin {
|
||||
/// Returns the [Repository] used by this [Widget].
|
||||
Repository repo<Repository>(BuildContext context) =>
|
||||
context.read<Repository>();
|
||||
/// Returns the [R] used by this [Widget].
|
||||
R repo<R>(BuildContext context) => context.read<R>();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -19,10 +19,10 @@ import 'package:wyatt_bloc_helper/src/repository/repository_provider_screen.dart
|
||||
|
||||
/// {@template repository_provider}
|
||||
/// Need to implement a [create] function that is responsible for
|
||||
/// creating the [Repository] and a [builder] which will return a child
|
||||
/// creating the [R] and a [builder] which will return a child
|
||||
/// that have access to the instance via `context.read<Repository>()`.
|
||||
/// It is used as a dependency injection (DI) widget so that a single instance
|
||||
/// of a [Repository] can be provided to multiple widgets within a subtree.
|
||||
/// of a [R] 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.
|
||||
@ -31,9 +31,9 @@ import 'package:wyatt_bloc_helper/src/repository/repository_provider_screen.dart
|
||||
/// By default, it provide already provided instance found in the tree.
|
||||
/// To override this behavior, set [smart] to `false`.
|
||||
/// {@endtemplate}
|
||||
abstract class RepositoryProviderScreen<Repository>
|
||||
extends RepositoryBaseProviderScreen<Repository>
|
||||
with RepositoryProviderMixin {
|
||||
abstract class RepositoryProviderScreen<R>
|
||||
extends RepositoryBaseProviderScreen<R> with RepositoryProviderMixin {
|
||||
/// {@macro repository_provider}
|
||||
@Deprecated('Useless provider screen. Use get_it instead.')
|
||||
const RepositoryProviderScreen({super.key});
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -19,10 +19,10 @@ import 'package:wyatt_bloc_helper/src/utils/smart_provider.dart';
|
||||
|
||||
/// {@template repository_base_provider}
|
||||
/// Need to implement a [create] function that is responsible for
|
||||
/// creating the [Repository] and a [builder] which will return a child
|
||||
/// creating the [R] and a [builder] which will return a child
|
||||
/// that have access to the instance via `context.read<Repository>()`.
|
||||
/// It is used as a dependency injection (DI) widget so that a single instance
|
||||
/// of a [Repository] can be provided to multiple widgets within a subtree.
|
||||
/// of a [R] 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.
|
||||
@ -31,8 +31,7 @@ import 'package:wyatt_bloc_helper/src/utils/smart_provider.dart';
|
||||
/// By default, it provide already provided instance found in the tree.
|
||||
/// To override this behavior, set [smart] to `false`.
|
||||
/// {@endtemplate}
|
||||
abstract class RepositoryBaseProviderScreen<Repository>
|
||||
extends StatelessWidget {
|
||||
abstract class RepositoryBaseProviderScreen<R> extends StatelessWidget {
|
||||
/// {@macro repository_base_provider}
|
||||
const RepositoryBaseProviderScreen({
|
||||
super.key,
|
||||
@ -40,32 +39,32 @@ abstract class RepositoryBaseProviderScreen<Repository>
|
||||
this.smart = true,
|
||||
});
|
||||
|
||||
/// Whether the [Repository] should be created lazily.
|
||||
/// Defaults to `true` which means the [Repository] is created only when
|
||||
/// Whether the [R] should be created lazily.
|
||||
/// Defaults to `true` which means the [R] is created only when
|
||||
/// accessed the first time, not when provided.
|
||||
final bool lazy;
|
||||
|
||||
/// Whether this uses [SmartProvider].
|
||||
/// Defaults to `true`. But if you want to provide new [Repository] of a
|
||||
/// Defaults to `true`. But if you want to provide new [R] of a
|
||||
/// same type in a sub-tree you may have to disable this.
|
||||
final bool smart;
|
||||
|
||||
/// Creates the [Repository] to be used.
|
||||
Repository create(BuildContext context);
|
||||
/// Creates the [R] to be used.
|
||||
R create(BuildContext context);
|
||||
|
||||
/// Initialize the [Repository].
|
||||
/// Initialize the [R].
|
||||
///
|
||||
/// This function is useful when using with [SmartProvider], because
|
||||
/// if you want to pass an initial call on your repository you can
|
||||
/// call it in `create` function but if you re-provide the repo below in the
|
||||
/// tree this action will never be call again.
|
||||
Repository init(BuildContext context, Repository repository) => repository;
|
||||
R init(BuildContext context, R repository) => repository;
|
||||
|
||||
/// Creates the child [Widget] to be used.
|
||||
Widget builder(BuildContext context);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SmartProvider.repo<Repository>(
|
||||
Widget build(BuildContext context) => SmartProvider.repo<R>(
|
||||
context,
|
||||
lazy: lazy,
|
||||
enable: smart,
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@ -18,32 +18,31 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
/// A utility class that provides a way to create a [BlocProvider] or
|
||||
/// [RepositoryProvider] with a [Bloc] or Repository that is already
|
||||
/// [RepositoryProvider] with a bloc or Repository that is already
|
||||
/// available in the widget tree.
|
||||
abstract class SmartProvider {
|
||||
/// Creates a [BlocProvider] with a [Bloc] that is possibly already
|
||||
/// Creates a [BlocProvider] with a bloc [B] that is possibly already
|
||||
/// available in the widget tree.
|
||||
static BlocProvider<Bloc>
|
||||
bloc<Bloc extends BlocBase<State>, State extends Object>(
|
||||
static BlocProvider<B> bloc<B extends BlocBase<S>, S extends Object>(
|
||||
BuildContext context, {
|
||||
required Bloc Function(BuildContext) create,
|
||||
required Bloc Function(BuildContext, Bloc) init,
|
||||
required B Function(BuildContext) create,
|
||||
required B Function(BuildContext, B) init,
|
||||
Widget? child,
|
||||
bool lazy = true,
|
||||
bool enable = true,
|
||||
}) {
|
||||
if (enable) {
|
||||
final bloc = context.read<Bloc?>();
|
||||
final bloc = context.read<B?>();
|
||||
if (bloc != null) {
|
||||
final b = bloc;
|
||||
return BlocProvider<Bloc>.value(
|
||||
return BlocProvider<B>.value(
|
||||
value: init(context, b),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return BlocProvider<Bloc>(
|
||||
return BlocProvider<B>(
|
||||
lazy: lazy,
|
||||
create: (_) => init(context, create(context)),
|
||||
child: child,
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2022 WYATT GROUP
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
Loading…
x
Reference in New Issue
Block a user