Fix both platform system chrome definitions (#18808)

This commit is contained in:
Jonah Williams 2018-06-26 17:01:46 -07:00 committed by GitHub
parent 43e6372128
commit 472bbccf75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 10 deletions

View File

@ -184,7 +184,7 @@ class ContactsDemoState extends State<ContactsDemo> {
new SliverList( new SliverList(
delegate: new SliverChildListDelegate(<Widget>[ delegate: new SliverChildListDelegate(<Widget>[
new AnnotatedRegion<SystemUiOverlayStyle>( new AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light, value: SystemUiOverlayStyle.dark,
child: new _ContactCategory( child: new _ContactCategory(
icon: Icons.call, icon: Icons.call,
children: <Widget>[ children: <Widget>[

View File

@ -402,7 +402,7 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
} }
home = new AnnotatedRegion<SystemUiOverlayStyle>( home = new AnnotatedRegion<SystemUiOverlayStyle>(
child: home, child: home,
value: SystemUiOverlayStyle.dark value: SystemUiOverlayStyle.light
); );
return home; return home;

View File

@ -478,8 +478,8 @@ class _AppBarState extends State<AppBar> {
} }
final Brightness brightness = widget.brightness ?? themeData.primaryColorBrightness; final Brightness brightness = widget.brightness ?? themeData.primaryColorBrightness;
final SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark final SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
? SystemUiOverlayStyle.dark ? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.light; : SystemUiOverlayStyle.dark;
return new Semantics( return new Semantics(
container: true, container: true,

View File

@ -100,12 +100,12 @@ class SystemUiOverlayStyle {
/// System overlays should be drawn with a light color. Intended for /// System overlays should be drawn with a light color. Intended for
/// applications with a dark background. /// applications with a dark background.
static const SystemUiOverlayStyle light = const SystemUiOverlayStyle( static const SystemUiOverlayStyle light = const SystemUiOverlayStyle(
systemNavigationBarColor: const Color(0xFFFFFFFF), systemNavigationBarColor: const Color(0xFF000000),
systemNavigationBarDividerColor: null, systemNavigationBarDividerColor: null,
statusBarColor: null, statusBarColor: null,
systemNavigationBarIconBrightness: Brightness.dark, systemNavigationBarIconBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark, statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.light, statusBarBrightness: Brightness.dark,
); );
/// System overlays should be drawn with a dark color. Intended for /// System overlays should be drawn with a dark color. Intended for
@ -115,8 +115,8 @@ class SystemUiOverlayStyle {
systemNavigationBarDividerColor: null, systemNavigationBarDividerColor: null,
statusBarColor: null, statusBarColor: null,
systemNavigationBarIconBrightness: Brightness.light, systemNavigationBarIconBrightness: Brightness.light,
statusBarIconBrightness: Brightness.light, statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.dark, statusBarBrightness: Brightness.light,
); );
/// Creates a new [SystemUiOverlayStyle]. /// Creates a new [SystemUiOverlayStyle].
@ -330,5 +330,9 @@ class SystemChrome {
} }
static SystemUiOverlayStyle _pendingStyle; static SystemUiOverlayStyle _pendingStyle;
/// The last style that was set using [SystemChrome.setSystemUIOverlayStyle].
@visibleForTesting
static SystemUiOverlayStyle get latestStyle => _latestStyle;
static SystemUiOverlayStyle _latestStyle; static SystemUiOverlayStyle _latestStyle;
} }

View File

@ -6,6 +6,7 @@ import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
@ -752,6 +753,47 @@ void main() {
// is fixed. // is fixed.
skip: !Platform.isLinux, skip: !Platform.isLinux,
); );
testWidgets('NavBar draws a light system bar for a dark background', (WidgetTester tester) async {
await tester.pumpWidget(
new WidgetsApp(
color: const Color(0xFFFFFFFF),
onGenerateRoute: (RouteSettings settings) {
return new CupertinoPageRoute<void>(
settings: settings,
builder: (BuildContext context) {
return const CupertinoNavigationBar(
middle: const Text('Test'),
backgroundColor: const Color(0xFF000000),
);
},
);
},
),
);
expect(SystemChrome.latestStyle, SystemUiOverlayStyle.light);
});
testWidgets('NavBar draws a dark system bar for a light background', (WidgetTester tester) async {
await tester.pumpWidget(
new WidgetsApp(
color: const Color(0xFFFFFFFF),
onGenerateRoute: (RouteSettings settings) {
return new CupertinoPageRoute<void>(
settings: settings,
builder: (BuildContext context) {
return const CupertinoNavigationBar(
middle: const Text('Test'),
backgroundColor: const Color(0xFFFFFFFF),
);
},
);
},
),
);
expect(SystemChrome.latestStyle, SystemUiOverlayStyle.dark);
});
} }
class _ExpectStyles extends StatelessWidget { class _ExpectStyles extends StatelessWidget {

View File

@ -4,6 +4,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
@ -1340,4 +1341,36 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('AppBar draws a light system bar for a dark background', (WidgetTester tester) async {
final ThemeData darkTheme = new ThemeData.dark();
await tester.pumpWidget(new MaterialApp(
theme: darkTheme,
home: Scaffold(
appBar: new AppBar(title: const Text('test'))
),
));
expect(darkTheme.primaryColorBrightness, Brightness.dark);
expect(SystemChrome.latestStyle, const SystemUiOverlayStyle(
statusBarBrightness: Brightness.dark,
statusBarIconBrightness: Brightness.light,
));
});
testWidgets('AppBar draws a dark system bar for a light background', (WidgetTester tester) async {
final ThemeData lightTheme = new ThemeData(primaryColor: Colors.white);
await tester.pumpWidget(new MaterialApp(
theme: lightTheme,
home: Scaffold(
appBar: new AppBar(title: const Text('test'))
),
));
expect(lightTheme.primaryColorBrightness, Brightness.light);
expect(SystemChrome.latestStyle, const SystemUiOverlayStyle(
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
));
});
} }