From bbb2a0f83718c58bd366ddaec7ce541a5d23390a Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Mon, 4 Nov 2019 16:31:52 -0800 Subject: [PATCH] Update cupertino demos in gallery (#43841) --- .../cupertino/cupertino_navigation_demo.dart | 232 +++++++++--------- .../demo/cupertino/cupertino_picker_demo.dart | 167 +++++++------ .../cupertino/cupertino_refresh_demo.dart | 98 ++++---- .../cupertino_segmented_control_demo.dart | 98 +++++--- .../flutter/lib/src/cupertino/button.dart | 6 +- .../flutter/lib/src/cupertino/colors.dart | 20 +- packages/flutter/lib/src/cupertino/route.dart | 6 +- .../flutter/test/cupertino/button_test.dart | 40 ++- .../flutter/test/cupertino/dialog_test.dart | 8 +- 9 files changed, 379 insertions(+), 296 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_navigation_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_navigation_demo.dart index 5730c43ad3..a45f7e1f6b 100644 --- a/examples/flutter_gallery/lib/demo/cupertino/cupertino_navigation_demo.dart +++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_navigation_demo.dart @@ -143,6 +143,7 @@ class CupertinoDemoTab1 extends StatelessWidget { @override Widget build(BuildContext context) { return CupertinoPageScaffold( + backgroundColor: CupertinoColors.systemGroupedBackground, child: CustomScrollView( semanticChildCount: _kChildCount, slivers: [ @@ -199,56 +200,59 @@ class Tab1RowItem extends StatelessWidget { ), )); }, - child: SafeArea( - top: false, - bottom: false, - child: Padding( - padding: const EdgeInsets.only(left: 16.0, top: 8.0, bottom: 8.0, right: 8.0), - child: Row( - children: [ - Container( - height: 60.0, - width: 60.0, - decoration: BoxDecoration( - color: color, - borderRadius: BorderRadius.circular(8.0), - ), - ), - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(colorName), - const Padding(padding: EdgeInsets.only(top: 8.0)), - const Text( - 'Buy this cool color', - style: TextStyle( - color: Color(0xFF8E8E93), - fontSize: 13.0, - fontWeight: FontWeight.w300, - ), - ), - ], + child: Container( + color: CupertinoDynamicColor.resolve(CupertinoColors.systemBackground, context), + child: SafeArea( + top: false, + bottom: false, + child: Padding( + padding: const EdgeInsets.only(left: 16.0, top: 8.0, bottom: 8.0, right: 8.0), + child: Row( + children: [ + Container( + height: 60.0, + width: 60.0, + decoration: BoxDecoration( + color: color, + borderRadius: BorderRadius.circular(8.0), ), ), - ), - CupertinoButton( - padding: EdgeInsets.zero, - child: const Icon(CupertinoIcons.plus_circled, - semanticLabel: 'Add', + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 12.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(colorName), + const Padding(padding: EdgeInsets.only(top: 8.0)), + Text( + 'Buy this cool color', + style: TextStyle( + color: CupertinoDynamicColor.resolve(CupertinoColors.secondaryLabel, context), + fontSize: 13.0, + fontWeight: FontWeight.w300, + ), + ), + ], + ), + ), ), - onPressed: () { }, - ), - CupertinoButton( - padding: EdgeInsets.zero, - child: const Icon(CupertinoIcons.share, - semanticLabel: 'Share', + CupertinoButton( + padding: EdgeInsets.zero, + child: const Icon(CupertinoIcons.plus_circled, + semanticLabel: 'Add', + ), + onPressed: () { }, ), - onPressed: () { }, - ), - ], + CupertinoButton( + padding: EdgeInsets.zero, + child: const Icon(CupertinoIcons.share, + semanticLabel: 'Share', + ), + onPressed: () { }, + ), + ], + ), ), ), ), @@ -263,7 +267,7 @@ class Tab1RowItem extends StatelessWidget { row, Container( height: 1.0, - color: const Color(0xFFD9D9D9), + color: CupertinoDynamicColor.resolve(CupertinoColors.separator, context), ), ], ); @@ -336,8 +340,8 @@ class Tab1ItemPageState extends State { const Padding(padding: EdgeInsets.only(top: 6.0)), Text( 'Item number ${widget.index}', - style: const TextStyle( - color: Color(0xFF8E8E93), + style: TextStyle( + color: CupertinoDynamicColor.resolve(CupertinoColors.secondaryLabel, context), fontSize: 16.0, fontWeight: FontWeight.w100, ), @@ -433,7 +437,10 @@ class CupertinoDemoTab2 extends StatelessWidget { child: CupertinoScrollbar( child: ListView( children: [ - Tab2Header(), + CupertinoUserInterfaceLevel( + data: CupertinoUserInterfaceLevelData.elevated, + child: Tab2Header(), + ), ...buildTab2Conversation(), ], ), @@ -456,18 +463,18 @@ class Tab2Header extends StatelessWidget { mainAxisSize: MainAxisSize.min, children: [ Container( - decoration: const BoxDecoration( - color: Color(0xFFE5E5E5), + decoration: BoxDecoration( + color: CupertinoDynamicColor.resolve(CupertinoColors.systemFill, context), ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 18.0, vertical: 12.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: const [ + children: [ Text( 'SUPPORT TICKET', style: TextStyle( - color: Color(0xFF646464), + color: CupertinoDynamicColor.resolve(CupertinoColors.secondaryLabel, context), letterSpacing: -0.9, fontSize: 14.0, fontWeight: FontWeight.w500, @@ -476,7 +483,7 @@ class Tab2Header extends StatelessWidget { Text( 'Show More', style: TextStyle( - color: Color(0xFF646464), + color: CupertinoDynamicColor.resolve(CupertinoColors.secondaryLabel, context), letterSpacing: -0.6, fontSize: 12.0, fontWeight: FontWeight.w500, @@ -487,8 +494,8 @@ class Tab2Header extends StatelessWidget { ), ), Container( - decoration: const BoxDecoration( - color: Color(0xFFF3F3F3), + decoration: BoxDecoration( + color: CupertinoDynamicColor.resolve(CupertinoColors.quaternarySystemFill, context), ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 18.0, vertical: 12.0), @@ -576,21 +583,31 @@ class Tab2ConversationBubble extends StatelessWidget { @override Widget build(BuildContext context) { + Color backgroundColor; + Color foregroundColor; + + switch (color) { + case Tab2ConversationBubbleColor.gray: + backgroundColor = CupertinoDynamicColor.resolve(CupertinoColors.systemFill, context); + foregroundColor = CupertinoDynamicColor.resolve(CupertinoColors.label, context); + break; + case Tab2ConversationBubbleColor.blue: + backgroundColor = CupertinoTheme.of(context).primaryColor; + foregroundColor = CupertinoColors.white; + break; + } + return Container( decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(18.0)), - color: color == Tab2ConversationBubbleColor.blue - ? CupertinoColors.activeBlue - : CupertinoColors.lightBackgroundGray, + color: backgroundColor, ), margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0), padding: const EdgeInsets.symmetric(horizontal: 14.0, vertical: 10.0), child: Text( text, style: TextStyle( - color: color == Tab2ConversationBubbleColor.blue - ? CupertinoColors.white - : CupertinoColors.black, + color: foregroundColor, letterSpacing: -0.4, fontSize: 15.0, fontWeight: FontWeight.w400, @@ -655,11 +672,14 @@ class Tab2ConversationRow extends StatelessWidget { crossAxisAlignment: isSelf ? CrossAxisAlignment.center : CrossAxisAlignment.end, children: [ if (avatar != null) avatar, - Tab2ConversationBubble( - text: text, - color: isSelf + CupertinoUserInterfaceLevel( + data: CupertinoUserInterfaceLevelData.elevated, + child: Tab2ConversationBubble( + text: text, + color: isSelf ? Tab2ConversationBubbleColor.blue : Tab2ConversationBubbleColor.gray, + ), ), ], ), @@ -709,55 +729,47 @@ class CupertinoDemoTab3 extends StatelessWidget { @override Widget build(BuildContext context) { return CupertinoPageScaffold( - navigationBar: CupertinoNavigationBar( - trailing: trailingButtons, - ), - child: DecoratedBox( - decoration: BoxDecoration( - color: CupertinoTheme.of(context).brightness == Brightness.light - ? CupertinoColors.extraLightBackgroundGray - : CupertinoColors.darkBackgroundGray, - ), - child: ListView( - children: [ - const Padding(padding: EdgeInsets.only(top: 32.0)), - GestureDetector( - onTap: () { - Navigator.of(context, rootNavigator: true).push( - CupertinoPageRoute( - fullscreenDialog: true, - builder: (BuildContext context) => Tab3Dialog(), - ), - ); - }, - child: Container( - decoration: BoxDecoration( - color: CupertinoTheme.of(context).scaffoldBackgroundColor, - border: const Border( - top: BorderSide(color: Color(0xFFBCBBC1), width: 0.0), - bottom: BorderSide(color: Color(0xFFBCBBC1), width: 0.0), - ), + navigationBar: CupertinoNavigationBar(trailing: trailingButtons), + backgroundColor: CupertinoColors.systemBackground, + child: ListView( + children: [ + const Padding(padding: EdgeInsets.only(top: 32.0)), + GestureDetector( + onTap: () { + Navigator.of(context, rootNavigator: true).push( + CupertinoPageRoute( + fullscreenDialog: true, + builder: (BuildContext context) => Tab3Dialog(), ), - height: 44.0, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), - child: SafeArea( - top: false, - bottom: false, - child: Row( - children: [ - Text( - 'Sign in', - style: TextStyle(color: CupertinoTheme.of(context).primaryColor), - ), - ], - ), + ); + }, + child: Container( + decoration: BoxDecoration( + color: CupertinoTheme.of(context).scaffoldBackgroundColor, + border: const Border( + top: BorderSide(color: Color(0xFFBCBBC1), width: 0.0), + bottom: BorderSide(color: Color(0xFFBCBBC1), width: 0.0), + ), + ), + height: 44.0, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), + child: SafeArea( + top: false, + bottom: false, + child: Row( + children: [ + Text( + 'Sign in', + style: TextStyle(color: CupertinoTheme.of(context).primaryColor), + ), + ], ), ), ), ), - ], - ), + ), + ], ), ); } diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_picker_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_picker_demo.dart index 3bcc00f1d1..fb3d31213a 100644 --- a/examples/flutter_gallery/lib/demo/cupertino/cupertino_picker_demo.dart +++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_picker_demo.dart @@ -17,21 +17,50 @@ class CupertinoPickerDemo extends StatefulWidget { _CupertinoPickerDemoState createState() => _CupertinoPickerDemoState(); } -class _CupertinoPickerDemoState extends State { - int _selectedColorIndex = 0; +class _BottomPicker extends StatelessWidget { + const _BottomPicker({ + Key key, + @required this.child, + }) : assert(child != null), + super(key: key); - Duration timer = const Duration(); + final Widget child; - // Value that is shown in the date picker in date mode. - DateTime date = DateTime.now(); + @override + Widget build(BuildContext context) { + return Container( + height: _kPickerSheetHeight, + padding: const EdgeInsets.only(top: 6.0), + color: CupertinoColors.systemBackground.resolveFrom(context), + child: DefaultTextStyle( + style: TextStyle( + color: CupertinoColors.label.resolveFrom(context), + fontSize: 22.0, + ), + child: GestureDetector( + // Blocks taps from propagating to the modal sheet and popping. + onTap: () { }, + child: SafeArea( + top: false, + child: child, + ), + ), + ), + ); + } +} - // Value that is shown in the date picker in time mode. - DateTime time = DateTime.now(); +class _Menu extends StatelessWidget { + const _Menu({ + Key key, + @required this.children, + }) : assert(children != null), + super(key: key); - // Value that is shown in the date picker in dateAndTime mode. - DateTime dateTime = DateTime.now(); + final List children; - Widget _buildMenu(List children) { + @override + Widget build(BuildContext context) { return Container( decoration: BoxDecoration( color: CupertinoTheme.of(context).scaffoldBackgroundColor, @@ -54,28 +83,21 @@ class _CupertinoPickerDemoState extends State { ), ); } +} - Widget _buildBottomPicker(Widget picker) { - return Container( - height: _kPickerSheetHeight, - padding: const EdgeInsets.only(top: 6.0), - color: CupertinoColors.white, - child: DefaultTextStyle( - style: const TextStyle( - color: CupertinoColors.black, - fontSize: 22.0, - ), - child: GestureDetector( - // Blocks taps from propagating to the modal sheet and popping. - onTap: () { }, - child: SafeArea( - top: false, - child: picker, - ), - ), - ), - ); - } +class _CupertinoPickerDemoState extends State { + int _selectedColorIndex = 0; + + Duration timer = const Duration(); + + // Value that is shown in the date picker in date mode. + DateTime date = DateTime.now(); + + // Value that is shown in the date picker in time mode. + DateTime time = DateTime.now(); + + // Value that is shown in the date picker in dateAndTime mode. + DateTime dateTime = DateTime.now(); Widget _buildColorPicker(BuildContext context) { final FixedExtentScrollController scrollController = @@ -86,11 +108,11 @@ class _CupertinoPickerDemoState extends State { await showCupertinoModalPopup( context: context, builder: (BuildContext context) { - return _buildBottomPicker( - CupertinoPicker( + return _BottomPicker( + child: CupertinoPicker( scrollController: scrollController, itemExtent: _kPickerItemHeight, - backgroundColor: CupertinoColors.white, + backgroundColor: CupertinoColors.systemBackground.resolveFrom(context), onSelectedItemChanged: (int index) { setState(() => _selectedColorIndex = index); }, @@ -104,14 +126,12 @@ class _CupertinoPickerDemoState extends State { }, ); }, - child: _buildMenu( - [ + child: _Menu( + children: [ const Text('Favorite Color'), Text( coolColorNames[_selectedColorIndex], - style: const TextStyle( - color: CupertinoColors.inactiveGray - ), + style: TextStyle(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)), ), ], ), @@ -124,8 +144,9 @@ class _CupertinoPickerDemoState extends State { showCupertinoModalPopup( context: context, builder: (BuildContext context) { - return _buildBottomPicker( - CupertinoTimerPicker( + return _BottomPicker( + child: CupertinoTimerPicker( + backgroundColor: CupertinoColors.systemBackground.resolveFrom(context), initialTimerDuration: timer, onTimerDurationChanged: (Duration newTimer) { setState(() => timer = newTimer); @@ -135,14 +156,14 @@ class _CupertinoPickerDemoState extends State { }, ); }, - child: _buildMenu( - [ + child: _Menu( + children: [ const Text('Countdown Timer'), Text( '${timer.inHours}:' '${(timer.inMinutes % 60).toString().padLeft(2,'0')}:' '${(timer.inSeconds % 60).toString().padLeft(2,'0')}', - style: const TextStyle(color: CupertinoColors.inactiveGray), + style: TextStyle(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)), ), ], ), @@ -155,8 +176,9 @@ class _CupertinoPickerDemoState extends State { showCupertinoModalPopup( context: context, builder: (BuildContext context) { - return _buildBottomPicker( - CupertinoDatePicker( + return _BottomPicker( + child: CupertinoDatePicker( + backgroundColor: CupertinoColors.systemBackground.resolveFrom(context), mode: CupertinoDatePickerMode.date, initialDateTime: date, onDateTimeChanged: (DateTime newDateTime) { @@ -167,12 +189,12 @@ class _CupertinoPickerDemoState extends State { }, ); }, - child: _buildMenu( - [ + child: _Menu( + children: [ const Text('Date'), Text( DateFormat.yMMMMd().format(date), - style: const TextStyle(color: CupertinoColors.inactiveGray), + style: TextStyle(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)), ), ] ), @@ -185,8 +207,9 @@ class _CupertinoPickerDemoState extends State { showCupertinoModalPopup( context: context, builder: (BuildContext context) { - return _buildBottomPicker( - CupertinoDatePicker( + return _BottomPicker( + child: CupertinoDatePicker( + backgroundColor: CupertinoColors.systemBackground.resolveFrom(context), mode: CupertinoDatePickerMode.time, initialDateTime: time, onDateTimeChanged: (DateTime newDateTime) { @@ -197,12 +220,12 @@ class _CupertinoPickerDemoState extends State { }, ); }, - child: _buildMenu( - [ + child: _Menu( + children: [ const Text('Time'), Text( DateFormat.jm().format(time), - style: const TextStyle(color: CupertinoColors.inactiveGray), + style: TextStyle(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)), ), ], ), @@ -215,8 +238,9 @@ class _CupertinoPickerDemoState extends State { showCupertinoModalPopup( context: context, builder: (BuildContext context) { - return _buildBottomPicker( - CupertinoDatePicker( + return _BottomPicker( + child: CupertinoDatePicker( + backgroundColor: CupertinoColors.systemBackground.resolveFrom(context), mode: CupertinoDatePickerMode.dateAndTime, initialDateTime: dateTime, onDateTimeChanged: (DateTime newDateTime) { @@ -227,12 +251,12 @@ class _CupertinoPickerDemoState extends State { }, ); }, - child: _buildMenu( - [ + child: _Menu( + children: [ const Text('Date and Time'), Text( DateFormat.yMMMd().add_jm().format(dateTime), - style: const TextStyle(color: CupertinoColors.inactiveGray), + style: TextStyle(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)), ), ], ), @@ -252,22 +276,15 @@ class _CupertinoPickerDemoState extends State { ), child: DefaultTextStyle( style: CupertinoTheme.of(context).textTheme.textStyle, - child: DecoratedBox( - decoration: BoxDecoration( - color: CupertinoTheme.of(context).brightness == Brightness.light - ? CupertinoColors.extraLightBackgroundGray - : CupertinoColors.darkBackgroundGray, - ), - child: ListView( - children: [ - const Padding(padding: EdgeInsets.only(top: 32.0)), - _buildColorPicker(context), - _buildCountdownTimerPicker(context), - _buildDatePicker(context), - _buildTimePicker(context), - _buildDateAndTimePicker(context), - ], - ), + child: ListView( + children: [ + const Padding(padding: EdgeInsets.only(top: 32.0)), + _buildColorPicker(context), + _buildCountdownTimerPicker(context), + _buildDatePicker(context), + _buildTimePicker(context), + _buildDateAndTimePicker(context), + ], ), ), ); diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_refresh_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_refresh_demo.dart index 6fa26d03d1..b05fbba077 100644 --- a/examples/flutter_gallery/lib/demo/cupertino/cupertino_refresh_demo.dart +++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_refresh_demo.dart @@ -41,59 +41,53 @@ class _CupertinoRefreshControlDemoState extends State[ - CupertinoSliverNavigationBar( - largeTitle: const Text('Refresh'), - // We're specifying a back label here because the previous page - // is a Material page. CupertinoPageRoutes could auto-populate - // these back labels. - previousPageTitle: 'Cupertino', - trailing: CupertinoDemoDocumentationButton(CupertinoRefreshControlDemo.routeName), - ), - CupertinoSliverRefreshControl( - onRefresh: () { - return Future.delayed(const Duration(seconds: 2)) - ..then((_) { - if (mounted) { - setState(() => repopulateList()); - } - }); - }, - ), - SliverSafeArea( - top: false, // Top safe area is consumed by the navigation bar. - sliver: SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - return _ListItem( - name: randomizedContacts[index][0], - place: randomizedContacts[index][1], - date: randomizedContacts[index][2], - called: randomizedContacts[index][3] == 'true', - ); - }, - childCount: 20, - ), + backgroundColor: CupertinoColors.systemGroupedBackground, + child: CustomScrollView( + // If left unspecified, the [CustomScrollView] appends an + // [AlwaysScrollableScrollPhysics]. Behind the scene, the ScrollableState + // will attach that [AlwaysScrollableScrollPhysics] to the output of + // [ScrollConfiguration.of] which will be a [ClampingScrollPhysics] + // on Android. + // To demonstrate the iOS behavior in this demo and to ensure that the list + // always scrolls, we specifically use a [BouncingScrollPhysics] combined + // with a [AlwaysScrollableScrollPhysics] + physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + slivers: [ + CupertinoSliverNavigationBar( + largeTitle: const Text('Refresh'), + // We're specifying a back label here because the previous page + // is a Material page. CupertinoPageRoutes could auto-populate + // these back labels. + previousPageTitle: 'Cupertino', + trailing: CupertinoDemoDocumentationButton(CupertinoRefreshControlDemo.routeName), + ), + CupertinoSliverRefreshControl( + onRefresh: () { + return Future.delayed(const Duration(seconds: 2)) + ..then((_) { + if (mounted) { + setState(() => repopulateList()); + } + }); + }, + ), + SliverSafeArea( + top: false, // Top safe area is consumed by the navigation bar. + sliver: SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return _ListItem( + name: randomizedContacts[index][0], + place: randomizedContacts[index][1], + date: randomizedContacts[index][2], + called: randomizedContacts[index][3] == 'true', + ); + }, + childCount: 20, ), ), - ], - ), + ), + ], ), ), ); @@ -163,7 +157,7 @@ class _ListItem extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - color: CupertinoTheme.of(context).scaffoldBackgroundColor, + color: CupertinoDynamicColor.resolve(CupertinoColors.systemBackground, context), height: 60.0, padding: const EdgeInsets.only(top: 9.0), child: Row( diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_segmented_control_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_segmented_control_demo.dart index d63cae4dcc..89b3251d6d 100644 --- a/examples/flutter_gallery/lib/demo/cupertino/cupertino_segmented_control_demo.dart +++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_segmented_control_demo.dart @@ -46,7 +46,13 @@ class _CupertinoSegmentedControlDemoState extends State[ - const Padding( - padding: EdgeInsets.all(16.0), - ), + const Padding(padding: EdgeInsets.all(16.0)), SizedBox( width: 500.0, child: CupertinoSegmentedControl( children: children, - onValueChanged: (int newValue) { - setState(() { - sharedValue = newValue; - }); - }, - groupValue: sharedValue, + onValueChanged: onValueChanged, + groupValue: currentSegment, + ), + ), + SizedBox( + width: 500, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: CupertinoSlidingSegmentedControl( + children: children, + onValueChanged: onValueChanged, + groupValue: currentSegment, + ), ), ), Expanded( @@ -85,36 +96,43 @@ class _CupertinoSegmentedControlDemoState extends State[ + BoxShadow( + offset: Offset(0.0, 3.0), + blurRadius: 5.0, + spreadRadius: -1.0, + color: _kKeyUmbraOpacity, + ), + BoxShadow( + offset: Offset(0.0, 6.0), + blurRadius: 10.0, + spreadRadius: 0.0, + color: _kKeyPenumbraOpacity, + ), + BoxShadow( + offset: Offset(0.0, 1.0), + blurRadius: 18.0, + spreadRadius: 0.0, + color: _kAmbientShadowOpacity, + ), + ], + ), + child: icons[currentSegment], + ); + }, ), - decoration: BoxDecoration( - color: CupertinoTheme.of(context).scaffoldBackgroundColor, - borderRadius: BorderRadius.circular(3.0), - boxShadow: const [ - BoxShadow( - offset: Offset(0.0, 3.0), - blurRadius: 5.0, - spreadRadius: -1.0, - color: _kKeyUmbraOpacity, - ), - BoxShadow( - offset: Offset(0.0, 6.0), - blurRadius: 10.0, - spreadRadius: 0.0, - color: _kKeyPenumbraOpacity, - ), - BoxShadow( - offset: Offset(0.0, 1.0), - blurRadius: 18.0, - spreadRadius: 0.0, - color: _kAmbientShadowOpacity, - ), - ], - ), - child: icons[sharedValue], ), ), ), diff --git a/packages/flutter/lib/src/cupertino/button.dart b/packages/flutter/lib/src/cupertino/button.dart index eb748d0b1f..bbb0df504e 100644 --- a/packages/flutter/lib/src/cupertino/button.dart +++ b/packages/flutter/lib/src/cupertino/button.dart @@ -33,7 +33,7 @@ class CupertinoButton extends StatefulWidget { this.color, this.disabledColor = CupertinoColors.quaternarySystemFill, this.minSize = kMinInteractiveDimensionCupertino, - this.pressedOpacity = 0.1, + this.pressedOpacity = 0.4, this.borderRadius = const BorderRadius.all(Radius.circular(8.0)), @required this.onPressed, }) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)), @@ -53,7 +53,7 @@ class CupertinoButton extends StatefulWidget { this.padding, this.disabledColor = CupertinoColors.quaternarySystemFill, this.minSize = kMinInteractiveDimensionCupertino, - this.pressedOpacity = 0.1, + this.pressedOpacity = 0.4, this.borderRadius = const BorderRadius.all(Radius.circular(8.0)), @required this.onPressed, }) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)), @@ -102,7 +102,7 @@ class CupertinoButton extends StatefulWidget { /// The opacity that the button will fade to when it is pressed. /// The button will have an opacity of 1.0 when it is not pressed. /// - /// This defaults to 0.1. If null, opacity will not change on pressed if using + /// This defaults to 0.4. If null, opacity will not change on pressed if using /// your own custom effects is desired. final double pressedOpacity; diff --git a/packages/flutter/lib/src/cupertino/colors.dart b/packages/flutter/lib/src/cupertino/colors.dart index 34b1bcaae8..e369610bcb 100644 --- a/packages/flutter/lib/src/cupertino/colors.dart +++ b/packages/flutter/lib/src/cupertino/colors.dart @@ -304,15 +304,15 @@ class CupertinoColors { /// The color for text labels containing secondary content, equivalent to /// [UIColor.secondaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173136-secondarylabel). static const CupertinoDynamicColor secondaryLabel = CupertinoDynamicColor( - color: Color.fromARGB(255, 0, 0, 0), - darkColor: Color.fromARGB(255, 255, 255, 255), - highContrastColor: Color.fromARGB(255, 0, 0, 0), - darkHighContrastColor: Color.fromARGB(255, 255, 255, 255), - elevatedColor: Color.fromARGB(255, 0, 0, 0), - darkElevatedColor: Color.fromARGB(255, 255, 255, 255), - highContrastElevatedColor: Color.fromARGB(255, 0, 0, 0), - darkHighContrastElevatedColor: Color.fromARGB(255, 255, 255, 255), - ); + color: Color.fromARGB(153, 60, 60, 67), + darkColor: Color.fromARGB(153, 235, 235, 245), + highContrastColor: Color.fromARGB(173, 60, 60, 67), + darkHighContrastColor: Color.fromARGB(173, 235, 235, 245), + elevatedColor: Color.fromARGB(153, 60, 60, 67), + darkElevatedColor: Color.fromARGB(153, 235, 235, 245), + highContrastElevatedColor: Color.fromARGB(173, 60, 60, 67), + darkHighContrastElevatedColor: Color.fromARGB(173, 235, 235, 245), +); /// The color for text labels containing tertiary content, equivalent to /// [UIColor.tertiaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173153-tertiarylabel). @@ -889,7 +889,7 @@ class CupertinoDynamicColor extends Color { /// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base] elevation /// level), unless [nullOk] is set to false, in which case an exception will be /// thrown. - CupertinoDynamicColor resolveFrom(BuildContext context, { bool nullOk = false }) { + CupertinoDynamicColor resolveFrom(BuildContext context, { bool nullOk = true }) { final Brightness brightness = _isPlatformBrightnessDependent ? CupertinoTheme.brightnessOf(context, nullOk: nullOk) ?? Brightness.light : Brightness.light; diff --git a/packages/flutter/lib/src/cupertino/route.dart b/packages/flutter/lib/src/cupertino/route.dart index 3f12c12434..19e3c951cd 100644 --- a/packages/flutter/lib/src/cupertino/route.dart +++ b/packages/flutter/lib/src/cupertino/route.dart @@ -13,6 +13,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter/animation.dart' show Curves; import 'colors.dart'; +import 'interface_level.dart'; const double _kBackGestureWidth = 20.0; const double _kMinFlingVelocity = 1.0; // Screen widths per second. @@ -840,7 +841,10 @@ class _CupertinoModalPopupRoute extends PopupRoute { @override Widget buildPage(BuildContext context, Animation animation, Animation secondaryAnimation) { - return builder(context); + return CupertinoUserInterfaceLevel( + data: CupertinoUserInterfaceLevelData.elevated, + child: Builder(builder: builder), + ); } @override diff --git a/packages/flutter/test/cupertino/button_test.dart b/packages/flutter/test/cupertino/button_test.dart index 69426070eb..2c125ced42 100644 --- a/packages/flutter/test/cupertino/button_test.dart +++ b/packages/flutter/test/cupertino/button_test.dart @@ -63,6 +63,44 @@ void main() { ); }); + // TODO(LongCatIsLoong): Uncomment once https://github.com/flutter/flutter/issues/44115 + // is fixed. + /* + testWidgets( + 'CupertinoButton.filled default color contrast meets guideline', + (WidgetTester tester) async { + // The native color combination systemBlue text over white background fails + // to pass the color contrast guideline. + //await tester.pumpWidget( + // CupertinoTheme( + // data: const CupertinoThemeData(), + // child: Directionality( + // textDirection: TextDirection.ltr, + // child: CupertinoButton.filled( + // child: const Text('Button'), + // onPressed: () {}, + // ), + // ), + // ), + //); + //await expectLater(tester, meetsGuideline(textContrastGuideline)); + + await tester.pumpWidget( + CupertinoApp( + theme: const CupertinoThemeData(brightness: Brightness.dark), + home: CupertinoPageScaffold( + child: CupertinoButton.filled( + child: const Text('Button'), + onPressed: () {}, + ), + ), + ), + ); + + await expectLater(tester, meetsGuideline(textContrastGuideline)); + }); + */ + testWidgets('Button with background is wider', (WidgetTester tester) async { await tester.pumpWidget(boilerplate(child: const CupertinoButton( child: Text('X', style: testStyle), @@ -145,7 +183,7 @@ void main() { of: find.byType(CupertinoButton), matching: find.byType(FadeTransition), )); - expect(opacity.opacity.value, 0.1); + expect(opacity.opacity.value, 0.4); }); testWidgets('pressedOpacity parameter', (WidgetTester tester) async { diff --git a/packages/flutter/test/cupertino/dialog_test.dart b/packages/flutter/test/cupertino/dialog_test.dart index 973c208fa7..002771cbb1 100644 --- a/packages/flutter/test/cupertino/dialog_test.dart +++ b/packages/flutter/test/cupertino/dialog_test.dart @@ -978,19 +978,19 @@ void main() { await tester.pump(const Duration(milliseconds: 25)); transition = tester.firstWidget(find.byType(FadeTransition)); - expect(transition.opacity.value, closeTo(0.10, 0.001)); + expect(transition.opacity.value, closeTo(0.40, 0.001)); await tester.pump(const Duration(milliseconds: 25)); transition = tester.firstWidget(find.byType(FadeTransition)); - expect(transition.opacity.value, closeTo(0.156, 0.001)); + expect(transition.opacity.value, closeTo(0.437, 0.001)); await tester.pump(const Duration(milliseconds: 25)); transition = tester.firstWidget(find.byType(FadeTransition)); - expect(transition.opacity.value, closeTo(0.324, 0.001)); + expect(transition.opacity.value, closeTo(0.55, 0.001)); await tester.pump(const Duration(milliseconds: 25)); transition = tester.firstWidget(find.byType(FadeTransition)); - expect(transition.opacity.value, closeTo(0.606, 0.001)); + expect(transition.opacity.value, closeTo(0.737, 0.001)); await tester.pump(const Duration(milliseconds: 25)); transition = tester.firstWidget(find.byType(FadeTransition));