fix: compilation issue with flutter 3.16.0 and generics name
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
Hugo Pointcheval 2023-11-18 17:50:27 +01:00
parent 375bb8f04a
commit e030375fec
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC
30 changed files with 127 additions and 131 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
* Copyright (C) 2022 WYATT GROUP * Copyright (C) 2023 WYATT GROUP
* Please see the AUTHORS file for details. * Please see the AUTHORS file for details.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify

View File

@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app') project.evaluationDependsOn(':app')
} }
task clean(type: Delete) { tasks.register("clean", Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 version: 1.0.0+1
environment: 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. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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} /// {@template bloc_provider}
/// Need to implement a [create] function that is responsible for /// 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>()`. /// that have access to the instance via `context.read<Bloc>()`.
/// It is used as a dependency injection (DI) widget so that a single instance /// 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]. /// It automatically handles closing the instance when used with [create].
/// By default, [create] is called only when the instance is accessed. /// 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. /// By default, it provide already provided instance found in the tree.
/// To override this behavior, set [smart] to `false`. /// To override this behavior, set [smart] to `false`.
/// {@endtemplate} /// {@endtemplate}
abstract class BlocProviderScreen<Bloc extends blocbase.Bloc<Event, State>, abstract class BlocProviderScreen<B extends blocbase.Bloc<E, S>, E,
Event, State extends Object> extends BlocBaseProviderScreen<Bloc, State> S extends Object> extends BlocBaseProviderScreen<B, S>
with with
BlocBaseProviderMixin<Bloc>, BlocBaseProviderMixin<B>,
RepositoryProviderMixin, RepositoryProviderMixin,
BlocProviderMixin<Bloc, Event> { BlocProviderMixin<B, E> {
/// {@macro bloc_provider} /// {@macro bloc_provider}
const BlocProviderScreen({super.key, super.lazy = true, super.smart = true}); 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 /// An optional [shouldBuildWhen] and [shouldListenWhen] can be implemented
/// for more granular control over when [onListen] and [onBuild] are called. /// for more granular control over when [onListen] and [onBuild] are called.
/// The [shouldListenWhen] and [shouldBuildWhen] will be invoked on /// 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 /// They each take the previous `state` and current `state` and must return
/// a [bool] which determines whether or not the [onBuild] and/or [onListen] /// a [bool] which determines whether or not the [onBuild] and/or [onListen]
/// function will be invoked. /// 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. /// the BlocConsumer is initialized.
/// [shouldListenWhen] and [shouldBuildWhen] are optional and if they /// [shouldListenWhen] and [shouldBuildWhen] are optional and if they
/// aren't implemented, they will default to `true`. /// 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 /// An optional [parent] can also be implemented. This build a wrapper arround
/// the built BlocConsumer that is **not** rebuild on each state. /// the built BlocConsumer that is **not** rebuild on each state.
/// {@endtemplate} /// {@endtemplate}
abstract class BlocConsumerScreen<Bloc extends blocbase.Bloc<Event, State>, abstract class BlocConsumerScreen<B extends blocbase.Bloc<E, S>, E,
Event, State extends Object> extends BlocBaseConsumerScreen<Bloc, State> S extends Object> extends BlocBaseConsumerScreen<B, S>
with with
BlocBaseProviderMixin<Bloc>, BlocBaseProviderMixin<B>,
RepositoryProviderMixin, RepositoryProviderMixin,
BlocProviderMixin<Bloc, Event> { BlocProviderMixin<B, E> {
/// {@macro bloc_consumer} /// {@macro bloc_consumer}
const BlocConsumerScreen({super.key}); const BlocConsumerScreen({super.key});
} }
/// {@template bloc_screen} /// {@template bloc_screen}
/// Provide AND access to a [Bloc]. /// Provide AND access to a bloc [B].
/// ///
/// This extends [BlocConsumerScreen] with the methods /// This extends [BlocConsumerScreen] with the methods
/// of [BlocBaseScreen]. /// of [BlocBaseScreen].
/// {@endtemplate} /// {@endtemplate}
abstract class BlocScreen<Bloc extends blocbase.Bloc<Event, State>, Event, abstract class BlocScreen<B extends blocbase.Bloc<E, S>, E, S extends Object>
State extends Object> extends BlocBaseScreen<Bloc, State> extends BlocBaseScreen<B, S>
with with
BlocBaseProviderMixin<Bloc>, BlocBaseProviderMixin<B>,
RepositoryProviderMixin, RepositoryProviderMixin,
BlocProviderMixin<Bloc, Event> { BlocProviderMixin<B, E> {
/// {@macro bloc_screen} /// {@macro bloc_screen}
const BlocScreen({super.key, super.lazy = true, super.smart = true}); const BlocScreen({super.key, super.lazy = true, super.smart = true});
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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 /// An optional [shouldBuildWhen] and [shouldListenWhen] can be implemented
/// for more granular control over when [onListen] and [onBuild] are called. /// for more granular control over when [onListen] and [onBuild] are called.
/// The [shouldListenWhen] and [shouldBuildWhen] will be invoked on /// 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 /// They each take the previous `state` and current `state` and must return
/// a [bool] which determines whether or not the [onBuild] and/or [onListen] /// a [bool] which determines whether or not the [onBuild] and/or [onListen]
/// function will be invoked. /// 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. /// the [BlocConsumer] is initialized.
/// [shouldListenWhen] and [shouldBuildWhen] are optional and if they /// [shouldListenWhen] and [shouldBuildWhen] are optional and if they
/// aren't implemented, they will default to `true`. /// 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 /// An optional [parent] can also be implemented. This build a wrapper arround
/// the built [BlocConsumer] that is **not** rebuild on each state. /// the built [BlocConsumer] that is **not** rebuild on each state.
/// {@endtemplate} /// {@endtemplate}
abstract class BlocBaseConsumerScreen<Bloc extends BlocBase<State>, abstract class BlocBaseConsumerScreen<B extends BlocBase<S>, S extends Object>
State extends Object> extends StatelessWidget { extends StatelessWidget {
/// {@macro bloc_base_consumer} /// {@macro bloc_base_consumer}
const BlocBaseConsumerScreen({super.key}); const BlocBaseConsumerScreen({super.key});
/// Takes the previous `state` and the current `state` and is responsible for /// Takes the previous `state` and the current `state` and is responsible for
/// returning a [bool] which determines whether or not to trigger /// returning a [bool] which determines whether or not to trigger
/// [onBuild] with the current `state`. /// [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 /// Takes the previous `state` and the current `state` and is responsible for
/// returning a [bool] which determines whether or not to trigger /// returning a [bool] which determines whether or not to trigger
/// [onListen] with the current `state`. /// [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] function which will be invoked on build.
/// The [parent] takes a `BuildContext` that **doesn't have** access /// 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; Widget parent(BuildContext context, Widget child) => child;
/// The [onBuild] function which will be invoked on each widget build. /// The [onBuild] function which will be invoked on each widget build.
/// The [onBuild] takes the `BuildContext` and current `state` and /// The [onBuild] takes the `BuildContext` and current `state` and
/// must return a widget. /// 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` /// Takes the `BuildContext` along with the `state`
/// and is responsible for executing in response to `state` changes. /// and is responsible for executing in response to `state` changes.
void onListen(BuildContext context, State state) {} void onListen(BuildContext context, S state) {}
@override @override
Widget build(BuildContext context) => parent( Widget build(BuildContext context) => parent(
context, context,
BlocConsumer<Bloc, State>( BlocConsumer<B, S>(
listenWhen: shouldListenWhen, listenWhen: shouldListenWhen,
listener: onListen, listener: onListen,
buildWhen: shouldBuildWhen, buildWhen: shouldBuildWhen,

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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} /// {@template bloc_base_provider}
/// Need to implement a [create] function that is responsible for /// 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>()`. /// that have access to the instance via `context.read<Bloc>()`.
/// It is used as a dependency injection (DI) widget so that a single instance /// 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]. /// It automatically handles closing the instance when used with [create].
/// By default, [create] is called only when the instance is accessed. /// 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. /// By default, it provide already provided instance found in the tree.
/// To override this behavior, set [smart] to `false`. /// To override this behavior, set [smart] to `false`.
/// {@endtemplate} /// {@endtemplate}
abstract class BlocBaseProviderScreen<Bloc extends BlocBase<State>, abstract class BlocBaseProviderScreen<B extends BlocBase<S>, S extends Object>
State extends Object> extends StatelessWidget { extends StatelessWidget {
/// {@macro bloc_base_provider} /// {@macro bloc_base_provider}
const BlocBaseProviderScreen({ const BlocBaseProviderScreen({
super.key, super.key,
@ -41,32 +41,32 @@ abstract class BlocBaseProviderScreen<Bloc extends BlocBase<State>,
this.smart = true, this.smart = true,
}); });
/// Whether the [Bloc] or [Cubit] should be created lazily. /// Whether the bloc or cubit [B] should be created lazily.
/// Defaults to `true` which means the [Bloc] or [Cubit] is created only when /// Defaults to `true` which means the bloc or cubit [B] is created only when
/// accessed the first time, not when provided. /// accessed the first time, not when provided.
final bool lazy; final bool lazy;
/// Whether this uses [SmartProvider]. /// 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. /// of a same type in a sub-tree you may have to disable this.
final bool smart; final bool smart;
/// Creates the [Bloc] or [Cubit] to be used. /// Creates the bloc or cubit [B] to be used.
Bloc create(BuildContext context); B create(BuildContext context);
/// Initialize the [Bloc] or [Cubit]. /// Initialize the bloc or cubit [B].
/// ///
/// This function is useful when using with [SmartProvider], because /// 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 /// 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 /// `create` function but if you re-use the bloc below in the tree this event
/// will never be re-pass. /// 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. /// Creates the child [Widget] to be used.
Widget builder(BuildContext context); Widget builder(BuildContext context);
@override @override
Widget build(BuildContext context) => SmartProvider.bloc<Bloc, State>( Widget build(BuildContext context) => SmartProvider.bloc<B, S>(
context, context,
lazy: lazy, lazy: lazy,
enable: smart, enable: smart,

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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'; import 'package:wyatt_bloc_helper/src/utils/smart_provider.dart';
/// {@template bloc_base_screen} /// {@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 /// This extends [BlocBaseConsumerScreen] with the methods
// ignore: comment_references // ignore: comment_references
/// of [BlocBaseProviderScreen]. /// of [BlocBaseProviderScreen].
/// {@endtemplate} /// {@endtemplate}
abstract class BlocBaseScreen<Bloc extends BlocBase<State>, abstract class BlocBaseScreen<B extends BlocBase<S>, S extends Object>
State extends Object> extends BlocBaseConsumerScreen<Bloc, State> { extends BlocBaseConsumerScreen<B, S> {
/// {@macro bloc_base_screen} /// {@macro bloc_base_screen}
const BlocBaseScreen({ const BlocBaseScreen({
super.key, super.key,
@ -35,8 +35,8 @@ abstract class BlocBaseScreen<Bloc extends BlocBase<State>,
this.smart = true, this.smart = true,
}); });
/// Whether the [Bloc] or [Cubit] should be created lazily. /// Whether the bloc or cubit [B] should be created lazily.
/// Defaults to `true` which means the [Bloc] is created only when /// Defaults to `true` which means the bloc is created only when
/// accessed the first time, not when provided. /// accessed the first time, not when provided.
final bool lazy; final bool lazy;
@ -45,19 +45,19 @@ abstract class BlocBaseScreen<Bloc extends BlocBase<State>,
/// in a sub-tree you may have to disable this. /// in a sub-tree you may have to disable this.
final bool smart; final bool smart;
/// Creates the [Cubit] or [Bloc] to be used. /// Creates the cubit or bloc to be used.
Bloc create(BuildContext context); B create(BuildContext context);
/// Initialize the [Bloc] or [Cubit]. /// Initialize the bloc or cubit [B].
/// ///
/// This function is useful when using with [SmartProvider], because /// 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 /// 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 /// `create` function but if you re-use the bloc below in the tree this event
/// will never be re-pass. /// will never be re-pass.
Bloc init(BuildContext context, Bloc bloc) => bloc; B init(BuildContext context, B bloc) => bloc;
@override @override
Widget build(BuildContext context) => SmartProvider.bloc<Bloc, State>( Widget build(BuildContext context) => SmartProvider.bloc<B, S>(
context, context,
lazy: lazy, lazy: lazy,
enable: smart, enable: smart,

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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} /// {@template cubit_provider}
/// Need to implement a [create] function that is responsible for /// 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>()`. /// that have access to the instance via `context.read<Cubit>()`.
/// It is used as a dependency injection (DI) widget so that a single instance /// 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]. /// It automatically handles closing the instance when used with [create].
/// By default, [create] is called only when the instance is accessed. /// 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. /// By default, it provide already provided instance in found in the tree.
/// To override this behavior, set [smart] to `false`. /// To override this behavior, set [smart] to `false`.
/// {@endtemplate} /// {@endtemplate}
abstract class CubitProviderScreen<Cubit extends blocbase.Cubit<State>, abstract class CubitProviderScreen<C extends blocbase.Cubit<S>,
State extends Object> extends BlocBaseProviderScreen<Cubit, State> S extends Object> extends BlocBaseProviderScreen<C, S>
with BlocBaseProviderMixin<Cubit>, RepositoryProviderMixin { with BlocBaseProviderMixin<C>, RepositoryProviderMixin {
/// {@macro cubit_provider} /// {@macro cubit_provider}
const CubitProviderScreen({super.key, super.lazy = true, super.smart = true}); 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 /// An optional [shouldBuildWhen] and [shouldListenWhen] can be implemented
/// for more granular control over when [onListen] and [onBuild] are called. /// for more granular control over when [onListen] and [onBuild] are called.
/// The [shouldListenWhen] and [shouldBuildWhen] will be invoked on /// 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 /// They each take the previous `state` and current `state` and must return
/// a [bool] which determines whether or not the [onBuild] and/or [onListen] /// a [bool] which determines whether or not the [onBuild] and/or [onListen]
/// function will be invoked. /// function will be invoked.
/// The previous `state` will be initialized to the `state` of the [Cubit] when /// The previous `state` will be initialized to the `state` of the cubit [C]
/// the BlocConsumer is initialized. /// when the BlocConsumer is initialized.
/// [shouldListenWhen] and [shouldBuildWhen] are optional and if they /// [shouldListenWhen] and [shouldBuildWhen] are optional and if they
/// aren't implemented, they will default to `true`. /// aren't implemented, they will default to `true`.
/// ///
/// An optional [parent] can also be implemented. This build a wrapper arround /// An optional [parent] can also be implemented. This build a wrapper arround
/// the built BlocConsumer that is **not** rebuild on each state. /// the built BlocConsumer that is **not** rebuild on each state.
/// {@endtemplate} /// {@endtemplate}
abstract class CubitConsumerScreen<Cubit extends blocbase.Cubit<State>, abstract class CubitConsumerScreen<C extends blocbase.Cubit<S>,
State extends Object> extends BlocBaseConsumerScreen<Cubit, State> S extends Object> extends BlocBaseConsumerScreen<C, S>
with BlocBaseProviderMixin<Cubit>, RepositoryProviderMixin { with BlocBaseProviderMixin<C>, RepositoryProviderMixin {
/// {@macro cubit_consumer} /// {@macro cubit_consumer}
const CubitConsumerScreen({super.key}); const CubitConsumerScreen({super.key});
} }
/// {@template cubit_screen} /// {@template cubit_screen}
/// Provide AND access to a [Cubit]. /// Provide AND access to a cubit [C].
/// ///
/// This extends [CubitConsumerScreen] with the methods /// This extends [CubitConsumerScreen] with the methods
// ignore: comment_references // ignore: comment_references
/// of [CubitProviderScreen]. /// of [CubitProviderScreen].
/// {@endtemplate} /// {@endtemplate}
abstract class CubitScreen<Cubit extends blocbase.Cubit<State>, abstract class CubitScreen<C extends blocbase.Cubit<S>, S extends Object>
State extends Object> extends BlocBaseScreen<Cubit, State> extends BlocBaseScreen<C, S>
with BlocBaseProviderMixin<Cubit>, RepositoryProviderMixin { with BlocBaseProviderMixin<C>, RepositoryProviderMixin {
/// {@macro cubit_screen} /// {@macro cubit_screen}
const CubitScreen({super.key, super.lazy = true, super.smart = true}); const CubitScreen({super.key, super.lazy = true, super.smart = true});
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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'; import 'package:flutter_bloc/flutter_bloc.dart';
/// A mixin that provides implementation of helper methods for /// A mixin that provides implementation of helper methods for
/// [Bloc] and [Cubit] widgets. /// bloc and cubit [B] widgets.
mixin BlocBaseProviderMixin<Bloc extends BlocBase<Object>> { mixin BlocBaseProviderMixin<B extends BlocBase<Object>> {
/// Returns the [BlocBase] used by this [BlocBaseProviderMixin]. /// 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]. /// Returns another [BlocBase] **not** used by this [BlocBaseProviderMixin].
/// Short hand for `context.read<AnotherBloc>();` /// Short hand for `context.read<AnotherBloc>();`

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
@ -17,12 +17,11 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart' as blocbase; 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. /// of helper methods for events.
mixin BlocProviderMixin<Bloc extends blocbase.Bloc<Event, Object>, Event> { mixin BlocProviderMixin<B extends blocbase.Bloc<E, Object>, E> {
/// Add an event to the [Bloc]. /// Add an event to the [B].
/// ///
/// Short hand for `context.read<Bloc>().add(event)`. /// Short hand for `context.read<Bloc>().add(event)`.
void add(BuildContext context, Event event) => void add(BuildContext context, E event) => context.read<B>().add(event);
context.read<Bloc>().add(event);
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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 /// A mixin that provides implementation of helper methods for
/// Repository widgets. /// Repository widgets.
mixin RepositoryProviderMixin { mixin RepositoryProviderMixin {
/// Returns the [Repository] used by this [Widget]. /// Returns the [R] used by this [Widget].
Repository repo<Repository>(BuildContext context) => R repo<R>(BuildContext context) => context.read<R>();
context.read<Repository>();
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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} /// {@template repository_provider}
/// Need to implement a [create] function that is responsible for /// 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>()`. /// that have access to the instance via `context.read<Repository>()`.
/// It is used as a dependency injection (DI) widget so that a single instance /// 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]. /// It automatically handles closing the instance when used with [create].
/// By default, [create] is called only when the instance is accessed. /// 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. /// By default, it provide already provided instance found in the tree.
/// To override this behavior, set [smart] to `false`. /// To override this behavior, set [smart] to `false`.
/// {@endtemplate} /// {@endtemplate}
abstract class RepositoryProviderScreen<Repository> abstract class RepositoryProviderScreen<R>
extends RepositoryBaseProviderScreen<Repository> extends RepositoryBaseProviderScreen<R> with RepositoryProviderMixin {
with RepositoryProviderMixin {
/// {@macro repository_provider} /// {@macro repository_provider}
@Deprecated('Useless provider screen. Use get_it instead.')
const RepositoryProviderScreen({super.key}); const RepositoryProviderScreen({super.key});
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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} /// {@template repository_base_provider}
/// Need to implement a [create] function that is responsible for /// 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>()`. /// that have access to the instance via `context.read<Repository>()`.
/// It is used as a dependency injection (DI) widget so that a single instance /// 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]. /// It automatically handles closing the instance when used with [create].
/// By default, [create] is called only when the instance is accessed. /// 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. /// By default, it provide already provided instance found in the tree.
/// To override this behavior, set [smart] to `false`. /// To override this behavior, set [smart] to `false`.
/// {@endtemplate} /// {@endtemplate}
abstract class RepositoryBaseProviderScreen<Repository> abstract class RepositoryBaseProviderScreen<R> extends StatelessWidget {
extends StatelessWidget {
/// {@macro repository_base_provider} /// {@macro repository_base_provider}
const RepositoryBaseProviderScreen({ const RepositoryBaseProviderScreen({
super.key, super.key,
@ -40,32 +39,32 @@ abstract class RepositoryBaseProviderScreen<Repository>
this.smart = true, this.smart = true,
}); });
/// Whether the [Repository] should be created lazily. /// Whether the [R] should be created lazily.
/// Defaults to `true` which means the [Repository] is created only when /// Defaults to `true` which means the [R] is created only when
/// accessed the first time, not when provided. /// accessed the first time, not when provided.
final bool lazy; final bool lazy;
/// Whether this uses [SmartProvider]. /// 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. /// same type in a sub-tree you may have to disable this.
final bool smart; final bool smart;
/// Creates the [Repository] to be used. /// Creates the [R] to be used.
Repository create(BuildContext context); R create(BuildContext context);
/// Initialize the [Repository]. /// Initialize the [R].
/// ///
/// This function is useful when using with [SmartProvider], because /// This function is useful when using with [SmartProvider], because
/// if you want to pass an initial call on your repository you can /// 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 /// call it in `create` function but if you re-provide the repo below in the
/// tree this action will never be call again. /// 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. /// Creates the child [Widget] to be used.
Widget builder(BuildContext context); Widget builder(BuildContext context);
@override @override
Widget build(BuildContext context) => SmartProvider.repo<Repository>( Widget build(BuildContext context) => SmartProvider.repo<R>(
context, context,
lazy: lazy, lazy: lazy,
enable: smart, enable: smart,

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // 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'; import 'package:flutter_bloc/flutter_bloc.dart';
/// A utility class that provides a way to create a [BlocProvider] or /// 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. /// available in the widget tree.
abstract class SmartProvider { 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. /// available in the widget tree.
static BlocProvider<Bloc> static BlocProvider<B> bloc<B extends BlocBase<S>, S extends Object>(
bloc<Bloc extends BlocBase<State>, State extends Object>(
BuildContext context, { BuildContext context, {
required Bloc Function(BuildContext) create, required B Function(BuildContext) create,
required Bloc Function(BuildContext, Bloc) init, required B Function(BuildContext, B) init,
Widget? child, Widget? child,
bool lazy = true, bool lazy = true,
bool enable = true, bool enable = true,
}) { }) {
if (enable) { if (enable) {
final bloc = context.read<Bloc?>(); final bloc = context.read<B?>();
if (bloc != null) { if (bloc != null) {
final b = bloc; final b = bloc;
return BlocProvider<Bloc>.value( return BlocProvider<B>.value(
value: init(context, b), value: init(context, b),
child: child, child: child,
); );
} }
} }
return BlocProvider<Bloc>( return BlocProvider<B>(
lazy: lazy, lazy: lazy,
create: (_) => init(context, create(context)), create: (_) => init(context, create(context)),
child: child, child: child,

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify