refactor(bloc_helper): general code update
This commit is contained in:
parent
58fec4bf48
commit
e00f4f55b7
@ -41,12 +41,10 @@ abstract class BlocBaseConsumerScreen<B extends BlocBase<S>, S extends Object>
|
||||
void onListen(BuildContext context, S state) {}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<B, S>(
|
||||
listenWhen: shouldListenWhen,
|
||||
listener: onListen,
|
||||
buildWhen: shouldBuildWhen,
|
||||
builder: onBuild,
|
||||
);
|
||||
}
|
||||
Widget build(BuildContext context) => BlocConsumer<B, S>(
|
||||
listenWhen: shouldListenWhen,
|
||||
listener: onListen,
|
||||
buildWhen: shouldBuildWhen,
|
||||
builder: onBuild,
|
||||
);
|
||||
}
|
||||
|
@ -28,10 +28,8 @@ abstract class BlocBaseProviderScreen<B extends BlocBase<S>, S extends Object>
|
||||
Widget buildChild(BuildContext context);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<B>(
|
||||
create: (_) => create(context),
|
||||
child: Builder(builder: buildChild),
|
||||
);
|
||||
}
|
||||
Widget build(BuildContext context) => BlocProvider<B>(
|
||||
create: (_) => create(context),
|
||||
child: Builder(builder: buildChild),
|
||||
);
|
||||
}
|
||||
|
@ -26,10 +26,8 @@ abstract class BlocBaseScreen<B extends BlocBase<S>, S extends Object>
|
||||
B create(BuildContext context);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<B>(
|
||||
create: (_) => create(context),
|
||||
child: super.build(context),
|
||||
);
|
||||
}
|
||||
Widget build(BuildContext context) => BlocProvider<B>(
|
||||
create: (_) => create(context),
|
||||
child: super.build(context),
|
||||
);
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
/// [Bloc] and [Cubit] widgets.
|
||||
mixin BlocBaseProviderMixin<B extends BlocBase<Object>> {
|
||||
/// Returns the [BlocBase] used by this [BlocBaseProviderMixin].
|
||||
B bloc(BuildContext context) => BlocProvider.of<B>(context);
|
||||
B bloc(BuildContext context) => context.read<B>();
|
||||
|
||||
/// Returns the [BlocBase] used by this [BlocBaseProviderMixin].
|
||||
R repo<R>(BuildContext context) => RepositoryProvider.of<R>(context);
|
||||
R repo<R>(BuildContext context) => context.read<R>();
|
||||
}
|
||||
|
@ -20,7 +20,5 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
/// [Bloc] specific mixin that provides implementation
|
||||
/// of helper methods for events.
|
||||
mixin BlocProviderMixin<B extends Bloc<E, Object>, E> {
|
||||
void add(BuildContext context, E event) {
|
||||
BlocProvider.of<B>(context).add(event);
|
||||
}
|
||||
void add(BuildContext context, E event) => context.read<B>().add(event);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user