forked from firka/flutter
CupertinoPageScaffold dark mode (#40690)
This commit is contained in:
@@ -372,7 +372,11 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer
|
||||
|
||||
/// True if the navigation bar's background color has no transparency.
|
||||
@override
|
||||
bool get fullObstruction => backgroundColor == null ? null : backgroundColor.alpha == 0xFF;
|
||||
bool shouldFullyObstruct(BuildContext context) {
|
||||
final Color backgroundColor = CupertinoDynamicColor.resolve(this.backgroundColor, context)
|
||||
?? CupertinoTheme.of(context).barBackgroundColor;
|
||||
return backgroundColor.alpha == 0xFF;
|
||||
}
|
||||
|
||||
@override
|
||||
Size get preferredSize {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'colors.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
/// Implements a single iOS application page's layout.
|
||||
@@ -110,8 +111,7 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
|
||||
? existingMediaQuery.viewInsets.copyWith(bottom: 0.0)
|
||||
: existingMediaQuery.viewInsets;
|
||||
|
||||
final bool fullObstruction =
|
||||
widget.navigationBar.fullObstruction ?? CupertinoTheme.of(context).barBackgroundColor.alpha == 0xFF;
|
||||
final bool fullObstruction = widget.navigationBar.shouldFullyObstruct(context);
|
||||
|
||||
// If navigation bar is opaquely obstructing, directly shift the main content
|
||||
// down. If translucent, let main content draw behind navigation bar but hint the
|
||||
@@ -157,7 +157,8 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
|
||||
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: widget.backgroundColor ?? CupertinoTheme.of(context).scaffoldBackgroundColor,
|
||||
color: CupertinoDynamicColor.resolve(widget.backgroundColor, context)
|
||||
?? CupertinoTheme.of(context).scaffoldBackgroundColor,
|
||||
),
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
@@ -204,5 +205,5 @@ abstract class ObstructingPreferredSizeWidget extends PreferredSizeWidget {
|
||||
/// size.
|
||||
///
|
||||
/// If false, this widget partially obstructs.
|
||||
bool get fullObstruction;
|
||||
bool shouldFullyObstruct(BuildContext context);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../painting/mocks_for_image_cache.dart';
|
||||
import '../rendering/mock_canvas.dart';
|
||||
|
||||
/// Integration tests testing both [CupertinoPageScaffold] and [CupertinoTabScaffold].
|
||||
void main() {
|
||||
@@ -53,6 +54,53 @@ void main() {
|
||||
expect(tester.getRect(find.byType(Container)), const Rect.fromLTRB(0, 44, 800, 600));
|
||||
});
|
||||
|
||||
testWidgets('dark mode and obstruction work', (WidgetTester tester) async {
|
||||
const Color dynamicColor = CupertinoDynamicColor.withBrightness(
|
||||
color: Color(0xFFF8F8F8),
|
||||
darkColor: Color(0xEE333333),
|
||||
);
|
||||
|
||||
const CupertinoDynamicColor backgroundColor = CupertinoDynamicColor.withBrightness(
|
||||
color: Color(0xFFFFFFFF),
|
||||
darkColor: Color(0xFF000000),
|
||||
);
|
||||
|
||||
BuildContext childContext;
|
||||
Widget scaffoldWithBrightness(Brightness brightness) {
|
||||
return Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: MediaQuery(
|
||||
data: MediaQueryData(
|
||||
platformBrightness: brightness,
|
||||
viewInsets: const EdgeInsets.only(top: 20),
|
||||
),
|
||||
child: CupertinoPageScaffold(
|
||||
backgroundColor: backgroundColor,
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('Title'),
|
||||
backgroundColor: dynamicColor,
|
||||
),
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
childContext = context;
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
await tester.pumpWidget(scaffoldWithBrightness(Brightness.light));
|
||||
|
||||
expect(MediaQuery.of(childContext).padding.top, 0);
|
||||
expect(find.byType(CupertinoPageScaffold), paints..rect(color: backgroundColor.color));
|
||||
|
||||
await tester.pumpWidget(scaffoldWithBrightness(Brightness.dark));
|
||||
|
||||
expect(MediaQuery.of(childContext).padding.top, greaterThan(0));
|
||||
expect(find.byType(CupertinoPageScaffold), paints..rect(color: backgroundColor.darkColor));
|
||||
});
|
||||
|
||||
testWidgets('Contents padding from viewInsets', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
|
||||
Reference in New Issue
Block a user