From e00f4f55b7e8cdd361e8b8a644c02d369860ead9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Thu, 14 Jul 2022 11:11:02 +0100 Subject: [PATCH] refactor(bloc_helper): general code update --- .../src/bloc_base/bloc_base_consumer_screen.dart | 14 ++++++-------- .../src/bloc_base/bloc_base_provider_screen.dart | 10 ++++------ .../lib/src/bloc_base/bloc_base_screen.dart | 10 ++++------ .../lib/src/mixins/bloc_base_provider_mixin.dart | 4 ++-- .../lib/src/mixins/bloc_provider_mixin.dart | 12 +++++------- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_consumer_screen.dart b/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_consumer_screen.dart index 5e04275a..0d5e3e96 100644 --- a/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_consumer_screen.dart +++ b/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_consumer_screen.dart @@ -41,12 +41,10 @@ abstract class BlocBaseConsumerScreen, S extends Object> void onListen(BuildContext context, S state) {} @override - Widget build(BuildContext context) { - return BlocConsumer( - listenWhen: shouldListenWhen, - listener: onListen, - buildWhen: shouldBuildWhen, - builder: onBuild, - ); - } + Widget build(BuildContext context) => BlocConsumer( + listenWhen: shouldListenWhen, + listener: onListen, + buildWhen: shouldBuildWhen, + builder: onBuild, + ); } diff --git a/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_provider_screen.dart b/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_provider_screen.dart index ca8b9f3e..3a9bae5f 100644 --- a/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_provider_screen.dart +++ b/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_provider_screen.dart @@ -28,10 +28,8 @@ abstract class BlocBaseProviderScreen, S extends Object> Widget buildChild(BuildContext context); @override - Widget build(BuildContext context) { - return BlocProvider( - create: (_) => create(context), - child: Builder(builder: buildChild), - ); - } + Widget build(BuildContext context) => BlocProvider( + create: (_) => create(context), + child: Builder(builder: buildChild), + ); } diff --git a/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_screen.dart b/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_screen.dart index 2452ce7c..4916b725 100644 --- a/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_screen.dart +++ b/packages/wyatt_bloc_helper/lib/src/bloc_base/bloc_base_screen.dart @@ -26,10 +26,8 @@ abstract class BlocBaseScreen, S extends Object> B create(BuildContext context); @override - Widget build(BuildContext context) { - return BlocProvider( - create: (_) => create(context), - child: super.build(context), - ); - } + Widget build(BuildContext context) => BlocProvider( + create: (_) => create(context), + child: super.build(context), + ); } diff --git a/packages/wyatt_bloc_helper/lib/src/mixins/bloc_base_provider_mixin.dart b/packages/wyatt_bloc_helper/lib/src/mixins/bloc_base_provider_mixin.dart index 0622f0ba..3ae13e26 100644 --- a/packages/wyatt_bloc_helper/lib/src/mixins/bloc_base_provider_mixin.dart +++ b/packages/wyatt_bloc_helper/lib/src/mixins/bloc_base_provider_mixin.dart @@ -21,8 +21,8 @@ import 'package:flutter_bloc/flutter_bloc.dart'; /// [Bloc] and [Cubit] widgets. mixin BlocBaseProviderMixin> { /// Returns the [BlocBase] used by this [BlocBaseProviderMixin]. - B bloc(BuildContext context) => BlocProvider.of(context); + B bloc(BuildContext context) => context.read(); /// Returns the [BlocBase] used by this [BlocBaseProviderMixin]. - R repo(BuildContext context) => RepositoryProvider.of(context); + R repo(BuildContext context) => context.read(); } diff --git a/packages/wyatt_bloc_helper/lib/src/mixins/bloc_provider_mixin.dart b/packages/wyatt_bloc_helper/lib/src/mixins/bloc_provider_mixin.dart index bcb7d15a..547dd6ca 100644 --- a/packages/wyatt_bloc_helper/lib/src/mixins/bloc_provider_mixin.dart +++ b/packages/wyatt_bloc_helper/lib/src/mixins/bloc_provider_mixin.dart @@ -1,26 +1,24 @@ // 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/widgets.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -/// [Bloc] specific mixin that provides implementation +/// [Bloc] specific mixin that provides implementation /// of helper methods for events. mixin BlocProviderMixin, E> { - void add(BuildContext context, E event) { - BlocProvider.of(context).add(event); - } + void add(BuildContext context, E event) => context.read().add(event); }