Created
June 27, 2019 15:15
-
-
Save rrousselGit/a0608a7321ed644e566ac8e36ad55149 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlocProvider<Value, Bloc extends _bloc.Bloc<dynamic, Value>> | |
extends ValueDelegateWidget<Bloc> implements SingleChildCloneableWidget { | |
/// Allows to specify parameters to [BlocProvider]. | |
BlocProvider({ | |
Key key, | |
@required ValueBuilder<Bloc> builder, | |
UpdateShouldNotify<Value> updateShouldNotify, | |
UpdateShouldNotify<Value> blocUpdateShouldNotify, | |
Disposer<Bloc> dispose, | |
Widget child, | |
}) : this._( | |
key: key, | |
delegate: BuilderStateDelegate<Bloc>(builder, dispose: dispose), | |
updateShouldNotify: null, | |
child: child, | |
); | |
/// Allows to specify parameters to [BlocProvider]. | |
BlocProvider.value({ | |
Key key, | |
@required Bloc value, | |
UpdateShouldNotify<Value> updateShouldNotify, | |
Widget child, | |
}) : this._( | |
key: key, | |
delegate: SingleValueDelegate<Bloc>(value), | |
updateShouldNotify: updateShouldNotify, | |
child: child, | |
); | |
BlocProvider._({ | |
Key key, | |
@required ValueStateDelegate<Bloc> delegate, | |
this.updateShouldNotify, | |
this.child, | |
}) : super(key: key, delegate: delegate); | |
final UpdateShouldNotify<Value> updateShouldNotify; | |
final Widget child; | |
@override | |
Widget build(BuildContext context) { | |
final bloc = delegate.value; | |
return InheritedProvider<Bloc>( | |
value: bloc, | |
child: StreamProvider<Value>.value( | |
initialData: bloc.initialState, | |
updateShouldNotify: updateShouldNotify, | |
value: bloc.state, | |
child: child, | |
), | |
); | |
} | |
@override | |
BlocProvider<Value, Bloc> cloneWithChild(Widget child) { | |
return BlocProvider._( | |
key: key, | |
delegate: delegate, | |
updateShouldNotify: updateShouldNotify, | |
child: child, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment