Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit e2b3d89

Browse files
authored
Fix CupertinoNavigationBar should create a backward compatible Annota… (#119515)
* Fix CupertinoNavigationBar should create a backward compatible AnnotatedRegion * Remove extra space
1 parent 6a54059 commit e2b3d89

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

packages/flutter/lib/src/cupertino/nav_bar.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,20 @@ Widget _wrapWithBackground({
149149
overlayStyle = SystemUiOverlayStyle.dark;
150150
break;
151151
}
152+
// [SystemUiOverlayStyle.light] and [SystemUiOverlayStyle.dark] set some system
153+
// navigation bar properties,
154+
// Before https://github.com/flutter/flutter/pull/104827 those properties
155+
// had no effect, now they are used if there is no AnnotatedRegion on the
156+
// bottom of the screen.
157+
// For backward compatibility, create a `SystemUiOverlayStyle` without the
158+
// system navigation bar properties.
152159
result = AnnotatedRegion<SystemUiOverlayStyle>(
153-
value: overlayStyle,
160+
value: SystemUiOverlayStyle(
161+
statusBarColor: overlayStyle.statusBarColor,
162+
statusBarBrightness: overlayStyle.statusBarBrightness,
163+
statusBarIconBrightness: overlayStyle.statusBarIconBrightness,
164+
systemStatusBarContrastEnforced: overlayStyle.systemStatusBarContrastEnforced,
165+
),
154166
child: result,
155167
);
156168
}

packages/flutter/test/cupertino/nav_bar_test.dart

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,32 @@ void main() {
173173
expect(tester.getCenter(find.text('Title')).dx, 400.0);
174174
});
175175

176+
// Assert that two SystemUiOverlayStyle instances have the same values for
177+
// status bar properties and that the first instance has no system navigation
178+
// bar properties set.
179+
void expectSameStatusBarStyle(SystemUiOverlayStyle style, SystemUiOverlayStyle expectedStyle) {
180+
expect(style.statusBarColor, expectedStyle.statusBarColor);
181+
expect(style.statusBarBrightness, expectedStyle.statusBarBrightness);
182+
expect(style.statusBarIconBrightness, expectedStyle.statusBarIconBrightness);
183+
expect(style.systemStatusBarContrastEnforced, expectedStyle.systemStatusBarContrastEnforced);
184+
expect(style.systemNavigationBarColor, isNull);
185+
expect(style.systemNavigationBarContrastEnforced, isNull);
186+
expect(style.systemNavigationBarDividerColor, isNull);
187+
expect(style.systemNavigationBarIconBrightness, isNull);
188+
}
189+
190+
// Regression test for https://github.com/flutter/flutter/issues/119270
191+
testWidgets('System navigation bar properties are not overriden', (WidgetTester tester) async {
192+
await tester.pumpWidget(
193+
const CupertinoApp(
194+
home: CupertinoNavigationBar(
195+
backgroundColor: Color(0xF0F9F9F9),
196+
),
197+
),
198+
);
199+
expectSameStatusBarStyle(SystemChrome.latestStyle!, SystemUiOverlayStyle.dark);
200+
});
201+
176202
testWidgets('Can specify custom brightness', (WidgetTester tester) async {
177203
await tester.pumpWidget(
178204
const CupertinoApp(
@@ -182,11 +208,7 @@ void main() {
182208
),
183209
),
184210
);
185-
186-
final AnnotatedRegion<SystemUiOverlayStyle> region1 = tester.allWidgets
187-
.whereType<AnnotatedRegion<SystemUiOverlayStyle>>()
188-
.single;
189-
expect(region1.value, SystemUiOverlayStyle.light);
211+
expectSameStatusBarStyle(SystemChrome.latestStyle!, SystemUiOverlayStyle.light);
190212

191213
await tester.pumpWidget(
192214
const CupertinoApp(
@@ -196,11 +218,7 @@ void main() {
196218
),
197219
),
198220
);
199-
200-
final AnnotatedRegion<SystemUiOverlayStyle> region2 = tester.allWidgets
201-
.whereType<AnnotatedRegion<SystemUiOverlayStyle>>()
202-
.single;
203-
expect(region2.value, SystemUiOverlayStyle.dark);
221+
expectSameStatusBarStyle(SystemChrome.latestStyle!, SystemUiOverlayStyle.dark);
204222

205223
await tester.pumpWidget(
206224
const CupertinoApp(
@@ -215,11 +233,7 @@ void main() {
215233
),
216234
),
217235
);
218-
219-
final AnnotatedRegion<SystemUiOverlayStyle> region3 = tester.allWidgets
220-
.whereType<AnnotatedRegion<SystemUiOverlayStyle>>()
221-
.single;
222-
expect(region3.value, SystemUiOverlayStyle.light);
236+
expectSameStatusBarStyle(SystemChrome.latestStyle!, SystemUiOverlayStyle.light);
223237

224238
await tester.pumpWidget(
225239
const CupertinoApp(
@@ -234,11 +248,7 @@ void main() {
234248
),
235249
),
236250
);
237-
238-
final AnnotatedRegion<SystemUiOverlayStyle> region4 = tester.allWidgets
239-
.whereType<AnnotatedRegion<SystemUiOverlayStyle>>()
240-
.single;
241-
expect(region4.value, SystemUiOverlayStyle.dark);
251+
expectSameStatusBarStyle(SystemChrome.latestStyle!, SystemUiOverlayStyle.dark);
242252
});
243253

244254
testWidgets('Padding works in RTL', (WidgetTester tester) async {
@@ -1021,7 +1031,7 @@ void main() {
10211031
},
10221032
),
10231033
);
1024-
expect(SystemChrome.latestStyle, SystemUiOverlayStyle.light);
1034+
expectSameStatusBarStyle(SystemChrome.latestStyle!, SystemUiOverlayStyle.light);
10251035
});
10261036

10271037
testWidgets('NavBar draws a dark system bar for a light background', (WidgetTester tester) async {
@@ -1041,7 +1051,7 @@ void main() {
10411051
},
10421052
),
10431053
);
1044-
expect(SystemChrome.latestStyle, SystemUiOverlayStyle.dark);
1054+
expectSameStatusBarStyle(SystemChrome.latestStyle!, SystemUiOverlayStyle.dark);
10451055
});
10461056

10471057
testWidgets('CupertinoNavigationBarBackButton shows an error when manually added outside a route', (WidgetTester tester) async {

0 commit comments

Comments
 (0)