Skip to content

Commit

Permalink
refactor: BlocObserver instances to use const constructors (#3713)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinVignal committed Feb 6, 2023
1 parent c4500b6 commit 2577838
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 15 deletions.
6 changes: 4 additions & 2 deletions examples/angular_counter/web/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:angular/angular.dart';
import 'package:bloc/bloc.dart';
import 'package:angular_counter/app_component.template.dart' as ng;
import 'package:bloc/bloc.dart';

class SimpleBlocObserver extends BlocObserver {
const SimpleBlocObserver();

@override
void onEvent(Bloc bloc, Object? event) {
print(event);
Expand All @@ -23,6 +25,6 @@ class SimpleBlocObserver extends BlocObserver {
}

void main() {
Bloc.observer = SimpleBlocObserver();
Bloc.observer = const SimpleBlocObserver();
runApp(ng.AppComponentNgFactory);
}
2 changes: 1 addition & 1 deletion examples/flutter_complex_list/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import 'package:flutter_complex_list/repository.dart';
import 'package:flutter_complex_list/simple_bloc_observer.dart';

void main() {
Bloc.observer = SimpleBlocObserver();
Bloc.observer = const SimpleBlocObserver();
runApp(App(repository: Repository()));
}
2 changes: 2 additions & 0 deletions examples/flutter_complex_list/lib/simple_bloc_observer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:bloc/bloc.dart';

class SimpleBlocObserver extends BlocObserver {
const SimpleBlocObserver();

@override
void onError(BlocBase<dynamic> bloc, Object error, StackTrace stackTrace) {
// ignore: avoid_print
Expand Down
3 changes: 3 additions & 0 deletions examples/flutter_counter/lib/counter_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'package:bloc/bloc.dart';
/// observes all state changes.
/// {@endtemplate}
class CounterObserver extends BlocObserver {
/// {@macro counter_observer}
const CounterObserver();

@override
void onChange(BlocBase<dynamic> bloc, Change<dynamic> change) {
super.onChange(bloc, change);
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_counter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import 'package:flutter_counter/app.dart';
import 'package:flutter_counter/counter_observer.dart';

void main() {
Bloc.observer = CounterObserver();
Bloc.observer = const CounterObserver();
runApp(const CounterApp());
}
2 changes: 2 additions & 0 deletions examples/flutter_firebase_login/lib/app/bloc_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import 'package:bloc/bloc.dart';

class AppBlocObserver extends BlocObserver {
const AppBlocObserver();

@override
void onEvent(Bloc<dynamic, dynamic> bloc, Object? event) {
super.onEvent(bloc, event);
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_firebase_login/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter_firebase_login/app/app.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
Bloc.observer = AppBlocObserver();
Bloc.observer = const AppBlocObserver();

await Firebase.initializeApp();

Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_infinite_list/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import 'package:flutter_infinite_list/app.dart';
import 'package:flutter_infinite_list/simple_bloc_observer.dart';

void main() {
Bloc.observer = SimpleBlocObserver();
Bloc.observer = const SimpleBlocObserver();
runApp(const App());
}
2 changes: 2 additions & 0 deletions examples/flutter_infinite_list/lib/simple_bloc_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import 'package:bloc/bloc.dart';

class SimpleBlocObserver extends BlocObserver {
const SimpleBlocObserver();

@override
void onTransition(
Bloc<dynamic, dynamic> bloc,
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_shopping_cart/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import 'package:flutter_shopping_cart/shopping_repository.dart';
import 'package:flutter_shopping_cart/simple_bloc_observer.dart';

void main() {
Bloc.observer = SimpleBlocObserver();
Bloc.observer = const SimpleBlocObserver();
runApp(App(shoppingRepository: ShoppingRepository()));
}
2 changes: 2 additions & 0 deletions examples/flutter_shopping_cart/lib/simple_bloc_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:developer';
import 'package:bloc/bloc.dart';

class SimpleBlocObserver extends BlocObserver {
const SimpleBlocObserver();

@override
void onEvent(Bloc<dynamic, dynamic> bloc, Object? event) {
super.onEvent(bloc, event);
Expand Down
2 changes: 2 additions & 0 deletions examples/flutter_todos/lib/app/app_bloc_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:developer';
import 'package:bloc/bloc.dart';

class AppBlocObserver extends BlocObserver {
const AppBlocObserver();

@override
void onChange(BlocBase<dynamic> bloc, Change<dynamic> change) {
super.onChange(bloc, change);
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_todos/lib/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void bootstrap({required TodosApi todosApi}) {
log(details.exceptionAsString(), stackTrace: details.stack);
};

Bloc.observer = AppBlocObserver();
Bloc.observer = const AppBlocObserver();

final todosRepository = TodosRepository(todosApi: todosApi);

Expand Down
4 changes: 2 additions & 2 deletions examples/flutter_todos/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: "direct main"
description:
name: bloc
sha256: bd4f8027bfa60d96c8046dec5ce74c463b2c918dce1b0d36593575995344534a
sha256: "658a5ae59edcf1e58aac98b000a71c762ad8f46f1394c34a52050cafb3e11a80"
url: "https://pub.dev"
source: hosted
version: "8.1.0"
version: "8.1.1"
bloc_test:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_todos/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: ">=2.19.0 <3.0.0"

dependencies:
bloc: ^8.1.0
bloc: ^8.1.1
equatable: ^2.0.5
flutter:
sdk: flutter
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_weather/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:weather_repository/weather_repository.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Bloc.observer = WeatherBlocObserver();
Bloc.observer = const WeatherBlocObserver();
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: kIsWeb
? HydratedStorage.webStorageDirectory
Expand Down
2 changes: 2 additions & 0 deletions examples/flutter_weather/lib/weather_bloc_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:developer';
import 'package:bloc/bloc.dart';

class WeatherBlocObserver extends BlocObserver {
const WeatherBlocObserver();

@override
void onEvent(Bloc<dynamic, dynamic> bloc, Object? event) {
super.onEvent(bloc, event);
Expand Down
2 changes: 1 addition & 1 deletion packages/bloc_test/lib/src/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Alternatively, consider using Matchers in the expect of the blocTest rather than
}

class _TestBlocObserver extends BlocObserver {
_TestBlocObserver(this._localObserver, this._onError);
const _TestBlocObserver(this._localObserver, this._onError);

final BlocObserver _localObserver;
final void Function(Object error) _onError;
Expand Down
7 changes: 6 additions & 1 deletion packages/flutter_bloc/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

void main() {
Bloc.observer = AppBlocObserver();
Bloc.observer = const AppBlocObserver();
runApp(const App());
}

/// {@template app_bloc_observer}
/// Custom [BlocObserver] that observes all bloc and cubit state changes.
/// {@endtemplate}
class AppBlocObserver extends BlocObserver {
/// {@macro app_bloc_observer}
const AppBlocObserver();

@override
void onChange(BlocBase bloc, Change change) {
super.onChange(bloc, change);
Expand Down
7 changes: 6 additions & 1 deletion packages/replay_bloc/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:replay_bloc/replay_bloc.dart';

void main() {
Bloc.observer = AppBlocObserver();
Bloc.observer = const AppBlocObserver();
runApp(const App());
}

/// {@template app_bloc_observer}
/// Custom [BlocObserver] that observes all bloc and cubit state changes.
/// {@endtemplate}
class AppBlocObserver extends BlocObserver {
/// {@macro app_bloc_observer}
const AppBlocObserver();

@override
void onChange(BlocBase bloc, Change change) {
super.onChange(bloc, change);
Expand Down

0 comments on commit 2577838

Please sign in to comment.