1
+ import 'package:flutter/foundation.dart' ;
1
2
import 'package:flutter/material.dart' ;
2
3
import 'package:flutter_bloc/flutter_bloc.dart' ;
3
4
import 'package:flutter_test/flutter_test.dart' ;
@@ -53,6 +54,7 @@ class MyThemeAppState extends State<MyThemeApp> {
53
54
key: const Key ('raised_button_2' ),
54
55
child: const SizedBox (),
55
56
onPressed: () {
57
+ // ignore: no_self_assignments
56
58
setState (() => _themeCubit = _themeCubit);
57
59
},
58
60
),
@@ -74,7 +76,6 @@ class ThemeCubit extends Cubit<ThemeData> {
74
76
class DarkThemeCubit extends Cubit <ThemeData > {
75
77
DarkThemeCubit () : super (ThemeData .dark ());
76
78
77
- void setDarkTheme () => emit (ThemeData .dark ());
78
79
void setLightTheme () => emit (ThemeData .light ());
79
80
}
80
81
@@ -132,7 +133,6 @@ class CounterCubit extends Cubit<int> {
132
133
CounterCubit ({int seed = 0 }) : super (seed);
133
134
134
135
void increment () => emit (state + 1 );
135
- void decrement () => emit (state - 1 );
136
136
}
137
137
138
138
void main () {
@@ -518,5 +518,29 @@ void main() {
518
518
519
519
expect (find.text ('Count 101' ), findsOneWidget);
520
520
});
521
+
522
+ testWidgets ('overrides debugFillProperties' , (tester) async {
523
+ final builder = DiagnosticPropertiesBuilder ();
524
+
525
+ BlocBuilder (
526
+ bloc: CounterCubit (),
527
+ builder: (context, state) => const SizedBox (),
528
+ buildWhen: (previous, current) => previous != current,
529
+ ).debugFillProperties (builder);
530
+
531
+ final description = builder.properties
532
+ .where ((node) => ! node.isFiltered (DiagnosticLevel .info))
533
+ .map ((node) => node.toString ())
534
+ .toList ();
535
+
536
+ expect (
537
+ description,
538
+ < String > [
539
+ 'has buildWhen' ,
540
+ "bloc: Instance of 'CounterCubit'" ,
541
+ 'has builder' ,
542
+ ],
543
+ );
544
+ });
521
545
});
522
546
}
0 commit comments