Unverified Commit 390ef609 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

CupertinoNavigationBar Dark Mode(#40189)

parent 67e35d61
49f8198b72f6e12c65fe1db2e46162de0204e671
ae7615ce466a548b41a0f7b9860ec453646f73e9
......@@ -11,6 +11,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'button.dart';
import 'colors.dart';
import 'constants.dart';
import 'icons.dart';
import 'page_scaffold.dart';
......@@ -37,7 +38,7 @@ const double _kNavBarBackButtonTapWidth = 50.0;
/// Title text transfer fade.
const Duration _kNavBarTitleFadeDuration = Duration(milliseconds: 150);
const Color _kDefaultNavBarBorderColor = Color(0x4C000000);
const Color _kDefaultNavBarBorderColor = Color(0x4D000000);
const Border _kDefaultNavBarBorder = Border(
bottom: BorderSide(
......@@ -399,7 +400,7 @@ class _CupertinoNavigationBarState extends State<CupertinoNavigationBar> {
@override
Widget build(BuildContext context) {
final Color backgroundColor =
widget.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor;
CupertinoDynamicColor.resolve(widget.backgroundColor, context) ?? CupertinoTheme.of(context).barBackgroundColor;
final _NavigationBarStaticComponents components = _NavigationBarStaticComponents(
keys: keys,
......@@ -427,14 +428,18 @@ class _CupertinoNavigationBarState extends State<CupertinoNavigationBar> {
),
);
final Color actionsForegroundColor = CupertinoDynamicColor.resolve(
widget.actionsForegroundColor, // ignore: deprecated_member_use_from_same_package
context,
);
if (!widget.transitionBetweenRoutes || !_isTransitionable(context)) {
// Lint ignore to maintain backward compatibility.
return _wrapActiveColor(widget.actionsForegroundColor, context, navBar); // ignore: deprecated_member_use_from_same_package
return _wrapActiveColor(actionsForegroundColor, context, navBar);
}
return _wrapActiveColor(
// Lint ignore to maintain backward compatibility.
widget.actionsForegroundColor, // ignore: deprecated_member_use_from_same_package
actionsForegroundColor,
context,
Builder(
// Get the context that might have a possibly changed CupertinoTheme.
......@@ -648,7 +653,8 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
@override
Widget build(BuildContext context) {
// Lint ignore to maintain backward compatibility.
final Color actionsForegroundColor = widget.actionsForegroundColor ?? CupertinoTheme.of(context).primaryColor; // ignore: deprecated_member_use_from_same_package
final Color actionsForegroundColor = CupertinoDynamicColor.resolve(widget.actionsForegroundColor, context) // ignore: deprecated_member_use_from_same_package
?? CupertinoTheme.of(context).primaryColor;
final _NavigationBarStaticComponents components = _NavigationBarStaticComponents(
keys: keys,
......@@ -666,7 +672,7 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
return _wrapActiveColor(
// Lint ignore to maintain backward compatibility.
widget.actionsForegroundColor, // ignore: deprecated_member_use_from_same_package
actionsForegroundColor,
context,
MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
......@@ -676,7 +682,7 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
keys: keys,
components: components,
userMiddle: widget.middle,
backgroundColor: widget.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor,
backgroundColor: CupertinoDynamicColor.resolve(widget.backgroundColor, context) ?? CupertinoTheme.of(context).barBackgroundColor,
border: widget.border,
padding: widget.padding,
actionsForegroundColor: actionsForegroundColor,
......@@ -742,7 +748,7 @@ class _LargeTitleNavigationBarSliverDelegate
final Widget navBar = _wrapWithBackground(
border: border,
backgroundColor: backgroundColor,
backgroundColor: CupertinoDynamicColor.resolve(backgroundColor, context),
child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: Stack(
......@@ -815,7 +821,7 @@ class _LargeTitleNavigationBarSliverDelegate
// needs to wrap the top level RenderBox rather than a RenderSliver.
child: _TransitionableNavigationBar(
componentsKeys: keys,
backgroundColor: backgroundColor,
backgroundColor: CupertinoDynamicColor.resolve(backgroundColor, context),
backButtonTextStyle: CupertinoTheme.of(context).textTheme.navActionTextStyle,
titleTextStyle: CupertinoTheme.of(context).textTheme.navTitleTextStyle,
largeTitleTextStyle: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle,
......@@ -1274,7 +1280,7 @@ class CupertinoNavigationBarBackButton extends StatelessWidget {
TextStyle actionTextStyle = CupertinoTheme.of(context).textTheme.navActionTextStyle;
if (color != null) {
actionTextStyle = actionTextStyle.copyWith(color: color);
actionTextStyle = actionTextStyle.copyWith(color: CupertinoDynamicColor.resolve(color, context));
}
return CupertinoButton(
......
......@@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
int count = 0;
......@@ -50,16 +51,35 @@ void main() {
expect(tester.getCenter(find.text('Page 2')).dx, 400.0);
});
testWidgets('Opaque background does not add blur effects', (WidgetTester tester) async {
testWidgets('Opaque background does not add blur effects, non-opaque background adds blur effects', (WidgetTester tester) async {
const CupertinoDynamicColor background = CupertinoDynamicColor.withBrightness(
color: Color(0xFFE5E5E5),
darkColor: Color(0xF3E5E5E5),
);
await tester.pumpWidget(
const CupertinoApp(
theme: CupertinoThemeData(brightness: Brightness.light),
home: CupertinoNavigationBar(
middle: Text('Title'),
backgroundColor: Color(0xFFE5E5E5),
backgroundColor: background,
),
),
);
expect(find.byType(BackdropFilter), findsNothing);
expect(find.byType(CupertinoNavigationBar), paints..rect(color: background.color));
await tester.pumpWidget(
const CupertinoApp(
theme: CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoNavigationBar(
middle: Text('Title'),
backgroundColor: background,
),
),
);
expect(find.byType(BackdropFilter), findsOneWidget);
expect(find.byType(CupertinoNavigationBar), paints..rect(color: background.darkColor));
});
testWidgets('Non-opaque background adds blur effects', (WidgetTester tester) async {
......@@ -801,7 +821,7 @@ void main() {
find.byType(RepaintBoundary).last,
matchesGoldenFile(
'nav_bar_test.standard_title.png',
version: 1,
version: 2,
),
);
},
......@@ -835,7 +855,7 @@ void main() {
find.byType(RepaintBoundary).last,
matchesGoldenFile(
'nav_bar_test.large_title.png',
version: 1,
version: 2,
),
);
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment