Skip to content

Commit

Permalink
refactor: apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Nov 29, 2021
1 parent adb523c commit 0d737fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/bloc/lib/src/bloc_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ abstract class Emittable<State extends Object?> {
void emit(State state);
}

/// A [StateStreamable] which must be closed when no longer in use.
abstract class StateStreamableSource<State>
implements StateStreamable<State>, Closable {}

/// An object which must be closed when no longer in use.
abstract class Closable {
/// Closes the current instance.
Expand All @@ -40,7 +44,7 @@ abstract class ErrorSink implements Closable {
/// both [Bloc] and [Cubit].
/// {@endtemplate}
abstract class BlocBase<State>
implements StateStreamable<State>, Emittable<State>, ErrorSink {
implements StateStreamableSource<State>, Emittable<State>, ErrorSink {
/// {@macro bloc_base}
BlocBase(this._state) {
// ignore: invalid_use_of_protected_member
Expand Down
10 changes: 3 additions & 7 deletions packages/flutter_bloc/lib/src/bloc_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mixin BlocProviderSingleChildWidget on SingleChildWidget {}
/// ```
///
/// {@endtemplate}
class BlocProvider<T extends StateStreamable<Object?>>
class BlocProvider<T extends StateStreamableSource<Object?>>
extends SingleChildStatelessWidget with BlocProviderSingleChildWidget {
/// {@macro bloc_provider}
const BlocProvider({
Expand Down Expand Up @@ -92,7 +92,7 @@ class BlocProvider<T extends StateStreamable<Object?>>
/// ```dart
/// BlocProvider.of<BlocA>(context);
/// ```
static T of<T extends StateStreamable<Object?>>(
static T of<T extends StateStreamableSource<Object?>>(
BuildContext context, {
bool listen = false,
}) {
Expand Down Expand Up @@ -129,11 +129,7 @@ class BlocProvider<T extends StateStreamable<Object?>>
)
: InheritedProvider<T>(
create: _create,
dispose: (_, bloc) {
if (bloc is Closable) {
(bloc as Closable).close();
}
},
dispose: (_, bloc) => bloc.close(),
startListening: _startListening,
child: child,
lazy: lazy,
Expand Down

0 comments on commit 0d737fe

Please sign in to comment.