Unverified Commit bbb2a0f8 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Update cupertino demos in gallery (#43841)

parent 76957c9d
...@@ -143,6 +143,7 @@ class CupertinoDemoTab1 extends StatelessWidget { ...@@ -143,6 +143,7 @@ class CupertinoDemoTab1 extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
backgroundColor: CupertinoColors.systemGroupedBackground,
child: CustomScrollView( child: CustomScrollView(
semanticChildCount: _kChildCount, semanticChildCount: _kChildCount,
slivers: <Widget>[ slivers: <Widget>[
...@@ -199,6 +200,8 @@ class Tab1RowItem extends StatelessWidget { ...@@ -199,6 +200,8 @@ class Tab1RowItem extends StatelessWidget {
), ),
)); ));
}, },
child: Container(
color: CupertinoDynamicColor.resolve(CupertinoColors.systemBackground, context),
child: SafeArea( child: SafeArea(
top: false, top: false,
bottom: false, bottom: false,
...@@ -222,10 +225,10 @@ class Tab1RowItem extends StatelessWidget { ...@@ -222,10 +225,10 @@ class Tab1RowItem extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Text(colorName), Text(colorName),
const Padding(padding: EdgeInsets.only(top: 8.0)), const Padding(padding: EdgeInsets.only(top: 8.0)),
const Text( Text(
'Buy this cool color', 'Buy this cool color',
style: TextStyle( style: TextStyle(
color: Color(0xFF8E8E93), color: CupertinoDynamicColor.resolve(CupertinoColors.secondaryLabel, context),
fontSize: 13.0, fontSize: 13.0,
fontWeight: FontWeight.w300, fontWeight: FontWeight.w300,
), ),
...@@ -252,6 +255,7 @@ class Tab1RowItem extends StatelessWidget { ...@@ -252,6 +255,7 @@ class Tab1RowItem extends StatelessWidget {
), ),
), ),
), ),
),
); );
if (lastItem) { if (lastItem) {
...@@ -263,7 +267,7 @@ class Tab1RowItem extends StatelessWidget { ...@@ -263,7 +267,7 @@ class Tab1RowItem extends StatelessWidget {
row, row,
Container( Container(
height: 1.0, height: 1.0,
color: const Color(0xFFD9D9D9), color: CupertinoDynamicColor.resolve(CupertinoColors.separator, context),
), ),
], ],
); );
...@@ -336,8 +340,8 @@ class Tab1ItemPageState extends State<Tab1ItemPage> { ...@@ -336,8 +340,8 @@ class Tab1ItemPageState extends State<Tab1ItemPage> {
const Padding(padding: EdgeInsets.only(top: 6.0)), const Padding(padding: EdgeInsets.only(top: 6.0)),
Text( Text(
'Item number ${widget.index}', 'Item number ${widget.index}',
style: const TextStyle( style: TextStyle(
color: Color(0xFF8E8E93), color: CupertinoDynamicColor.resolve(CupertinoColors.secondaryLabel, context),
fontSize: 16.0, fontSize: 16.0,
fontWeight: FontWeight.w100, fontWeight: FontWeight.w100,
), ),
...@@ -433,7 +437,10 @@ class CupertinoDemoTab2 extends StatelessWidget { ...@@ -433,7 +437,10 @@ class CupertinoDemoTab2 extends StatelessWidget {
child: CupertinoScrollbar( child: CupertinoScrollbar(
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
Tab2Header(), CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Tab2Header(),
),
...buildTab2Conversation(), ...buildTab2Conversation(),
], ],
), ),
...@@ -456,18 +463,18 @@ class Tab2Header extends StatelessWidget { ...@@ -456,18 +463,18 @@ class Tab2Header extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
Container( Container(
decoration: const BoxDecoration( decoration: BoxDecoration(
color: Color(0xFFE5E5E5), color: CupertinoDynamicColor.resolve(CupertinoColors.systemFill, context),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 18.0, vertical: 12.0), padding: const EdgeInsets.symmetric(horizontal: 18.0, vertical: 12.0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const <Widget>[ children: <Widget>[
Text( Text(
'SUPPORT TICKET', 'SUPPORT TICKET',
style: TextStyle( style: TextStyle(
color: Color(0xFF646464), color: CupertinoDynamicColor.resolve(CupertinoColors.secondaryLabel, context),
letterSpacing: -0.9, letterSpacing: -0.9,
fontSize: 14.0, fontSize: 14.0,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
...@@ -476,7 +483,7 @@ class Tab2Header extends StatelessWidget { ...@@ -476,7 +483,7 @@ class Tab2Header extends StatelessWidget {
Text( Text(
'Show More', 'Show More',
style: TextStyle( style: TextStyle(
color: Color(0xFF646464), color: CupertinoDynamicColor.resolve(CupertinoColors.secondaryLabel, context),
letterSpacing: -0.6, letterSpacing: -0.6,
fontSize: 12.0, fontSize: 12.0,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
...@@ -487,8 +494,8 @@ class Tab2Header extends StatelessWidget { ...@@ -487,8 +494,8 @@ class Tab2Header extends StatelessWidget {
), ),
), ),
Container( Container(
decoration: const BoxDecoration( decoration: BoxDecoration(
color: Color(0xFFF3F3F3), color: CupertinoDynamicColor.resolve(CupertinoColors.quaternarySystemFill, context),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 18.0, vertical: 12.0), padding: const EdgeInsets.symmetric(horizontal: 18.0, vertical: 12.0),
...@@ -576,21 +583,31 @@ class Tab2ConversationBubble extends StatelessWidget { ...@@ -576,21 +583,31 @@ class Tab2ConversationBubble extends StatelessWidget {
@override @override
Widget build(BuildContext context) { 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( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(18.0)), borderRadius: const BorderRadius.all(Radius.circular(18.0)),
color: color == Tab2ConversationBubbleColor.blue color: backgroundColor,
? CupertinoColors.activeBlue
: CupertinoColors.lightBackgroundGray,
), ),
margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0), margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
padding: const EdgeInsets.symmetric(horizontal: 14.0, vertical: 10.0), padding: const EdgeInsets.symmetric(horizontal: 14.0, vertical: 10.0),
child: Text( child: Text(
text, text,
style: TextStyle( style: TextStyle(
color: color == Tab2ConversationBubbleColor.blue color: foregroundColor,
? CupertinoColors.white
: CupertinoColors.black,
letterSpacing: -0.4, letterSpacing: -0.4,
fontSize: 15.0, fontSize: 15.0,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
...@@ -655,12 +672,15 @@ class Tab2ConversationRow extends StatelessWidget { ...@@ -655,12 +672,15 @@ class Tab2ConversationRow extends StatelessWidget {
crossAxisAlignment: isSelf ? CrossAxisAlignment.center : CrossAxisAlignment.end, crossAxisAlignment: isSelf ? CrossAxisAlignment.center : CrossAxisAlignment.end,
children: <Widget>[ children: <Widget>[
if (avatar != null) avatar, if (avatar != null) avatar,
Tab2ConversationBubble( CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Tab2ConversationBubble(
text: text, text: text,
color: isSelf color: isSelf
? Tab2ConversationBubbleColor.blue ? Tab2ConversationBubbleColor.blue
: Tab2ConversationBubbleColor.gray, : Tab2ConversationBubbleColor.gray,
), ),
),
], ],
), ),
); );
...@@ -709,15 +729,8 @@ class CupertinoDemoTab3 extends StatelessWidget { ...@@ -709,15 +729,8 @@ class CupertinoDemoTab3 extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(trailing: trailingButtons),
trailing: trailingButtons, backgroundColor: CupertinoColors.systemBackground,
),
child: DecoratedBox(
decoration: BoxDecoration(
color: CupertinoTheme.of(context).brightness == Brightness.light
? CupertinoColors.extraLightBackgroundGray
: CupertinoColors.darkBackgroundGray,
),
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
const Padding(padding: EdgeInsets.only(top: 32.0)), const Padding(padding: EdgeInsets.only(top: 32.0)),
...@@ -758,7 +771,6 @@ class CupertinoDemoTab3 extends StatelessWidget { ...@@ -758,7 +771,6 @@ class CupertinoDemoTab3 extends StatelessWidget {
), ),
], ],
), ),
),
); );
} }
} }
......
...@@ -17,21 +17,50 @@ class CupertinoPickerDemo extends StatefulWidget { ...@@ -17,21 +17,50 @@ class CupertinoPickerDemo extends StatefulWidget {
_CupertinoPickerDemoState createState() => _CupertinoPickerDemoState(); _CupertinoPickerDemoState createState() => _CupertinoPickerDemoState();
} }
class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { class _BottomPicker extends StatelessWidget {
int _selectedColorIndex = 0; 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. @override
DateTime date = DateTime.now(); 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. class _Menu extends StatelessWidget {
DateTime time = DateTime.now(); const _Menu({
Key key,
@required this.children,
}) : assert(children != null),
super(key: key);
// Value that is shown in the date picker in dateAndTime mode. final List<Widget> children;
DateTime dateTime = DateTime.now();
Widget _buildMenu(List<Widget> children) { @override
Widget build(BuildContext context) {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: CupertinoTheme.of(context).scaffoldBackgroundColor, color: CupertinoTheme.of(context).scaffoldBackgroundColor,
...@@ -54,28 +83,21 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -54,28 +83,21 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
), ),
); );
} }
}
Widget _buildBottomPicker(Widget picker) { class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
return Container( int _selectedColorIndex = 0;
height: _kPickerSheetHeight,
padding: const EdgeInsets.only(top: 6.0), Duration timer = const Duration();
color: CupertinoColors.white,
child: DefaultTextStyle( // Value that is shown in the date picker in date mode.
style: const TextStyle( DateTime date = DateTime.now();
color: CupertinoColors.black,
fontSize: 22.0, // Value that is shown in the date picker in time mode.
), DateTime time = DateTime.now();
child: GestureDetector(
// Blocks taps from propagating to the modal sheet and popping. // Value that is shown in the date picker in dateAndTime mode.
onTap: () { }, DateTime dateTime = DateTime.now();
child: SafeArea(
top: false,
child: picker,
),
),
),
);
}
Widget _buildColorPicker(BuildContext context) { Widget _buildColorPicker(BuildContext context) {
final FixedExtentScrollController scrollController = final FixedExtentScrollController scrollController =
...@@ -86,11 +108,11 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -86,11 +108,11 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
await showCupertinoModalPopup<void>( await showCupertinoModalPopup<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return _buildBottomPicker( return _BottomPicker(
CupertinoPicker( child: CupertinoPicker(
scrollController: scrollController, scrollController: scrollController,
itemExtent: _kPickerItemHeight, itemExtent: _kPickerItemHeight,
backgroundColor: CupertinoColors.white, backgroundColor: CupertinoColors.systemBackground.resolveFrom(context),
onSelectedItemChanged: (int index) { onSelectedItemChanged: (int index) {
setState(() => _selectedColorIndex = index); setState(() => _selectedColorIndex = index);
}, },
...@@ -104,14 +126,12 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -104,14 +126,12 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
}, },
); );
}, },
child: _buildMenu( child: _Menu(
<Widget>[ children: <Widget>[
const Text('Favorite Color'), const Text('Favorite Color'),
Text( Text(
coolColorNames[_selectedColorIndex], coolColorNames[_selectedColorIndex],
style: const TextStyle( style: TextStyle(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)),
color: CupertinoColors.inactiveGray
),
), ),
], ],
), ),
...@@ -124,8 +144,9 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -124,8 +144,9 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
showCupertinoModalPopup<void>( showCupertinoModalPopup<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return _buildBottomPicker( return _BottomPicker(
CupertinoTimerPicker( child: CupertinoTimerPicker(
backgroundColor: CupertinoColors.systemBackground.resolveFrom(context),
initialTimerDuration: timer, initialTimerDuration: timer,
onTimerDurationChanged: (Duration newTimer) { onTimerDurationChanged: (Duration newTimer) {
setState(() => timer = newTimer); setState(() => timer = newTimer);
...@@ -135,14 +156,14 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -135,14 +156,14 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
}, },
); );
}, },
child: _buildMenu( child: _Menu(
<Widget>[ children: <Widget>[
const Text('Countdown Timer'), const Text('Countdown Timer'),
Text( Text(
'${timer.inHours}:' '${timer.inHours}:'
'${(timer.inMinutes % 60).toString().padLeft(2,'0')}:' '${(timer.inMinutes % 60).toString().padLeft(2,'0')}:'
'${(timer.inSeconds % 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<CupertinoPickerDemo> { ...@@ -155,8 +176,9 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
showCupertinoModalPopup<void>( showCupertinoModalPopup<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return _buildBottomPicker( return _BottomPicker(
CupertinoDatePicker( child: CupertinoDatePicker(
backgroundColor: CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.date, mode: CupertinoDatePickerMode.date,
initialDateTime: date, initialDateTime: date,
onDateTimeChanged: (DateTime newDateTime) { onDateTimeChanged: (DateTime newDateTime) {
...@@ -167,12 +189,12 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -167,12 +189,12 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
}, },
); );
}, },
child: _buildMenu( child: _Menu(
<Widget>[ children: <Widget>[
const Text('Date'), const Text('Date'),
Text( Text(
DateFormat.yMMMMd().format(date), 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<CupertinoPickerDemo> { ...@@ -185,8 +207,9 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
showCupertinoModalPopup<void>( showCupertinoModalPopup<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return _buildBottomPicker( return _BottomPicker(
CupertinoDatePicker( child: CupertinoDatePicker(
backgroundColor: CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.time, mode: CupertinoDatePickerMode.time,
initialDateTime: time, initialDateTime: time,
onDateTimeChanged: (DateTime newDateTime) { onDateTimeChanged: (DateTime newDateTime) {
...@@ -197,12 +220,12 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -197,12 +220,12 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
}, },
); );
}, },
child: _buildMenu( child: _Menu(
<Widget>[ children: <Widget>[
const Text('Time'), const Text('Time'),
Text( Text(
DateFormat.jm().format(time), 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<CupertinoPickerDemo> { ...@@ -215,8 +238,9 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
showCupertinoModalPopup<void>( showCupertinoModalPopup<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return _buildBottomPicker( return _BottomPicker(
CupertinoDatePicker( child: CupertinoDatePicker(
backgroundColor: CupertinoColors.systemBackground.resolveFrom(context),
mode: CupertinoDatePickerMode.dateAndTime, mode: CupertinoDatePickerMode.dateAndTime,
initialDateTime: dateTime, initialDateTime: dateTime,
onDateTimeChanged: (DateTime newDateTime) { onDateTimeChanged: (DateTime newDateTime) {
...@@ -227,12 +251,12 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -227,12 +251,12 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
}, },
); );
}, },
child: _buildMenu( child: _Menu(
<Widget>[ children: <Widget>[
const Text('Date and Time'), const Text('Date and Time'),
Text( Text(
DateFormat.yMMMd().add_jm().format(dateTime), DateFormat.yMMMd().add_jm().format(dateTime),
style: const TextStyle(color: CupertinoColors.inactiveGray), style: TextStyle(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context)),
), ),
], ],
), ),
...@@ -252,12 +276,6 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -252,12 +276,6 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
), ),
child: DefaultTextStyle( child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle, style: CupertinoTheme.of(context).textTheme.textStyle,
child: DecoratedBox(
decoration: BoxDecoration(
color: CupertinoTheme.of(context).brightness == Brightness.light
? CupertinoColors.extraLightBackgroundGray
: CupertinoColors.darkBackgroundGray,
),
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
const Padding(padding: EdgeInsets.only(top: 32.0)), const Padding(padding: EdgeInsets.only(top: 32.0)),
...@@ -269,7 +287,6 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> { ...@@ -269,7 +287,6 @@ class _CupertinoPickerDemoState extends State<CupertinoPickerDemo> {
], ],
), ),
), ),
),
); );
} }
} }
...@@ -41,12 +41,7 @@ class _CupertinoRefreshControlDemoState extends State<CupertinoRefreshControlDem ...@@ -41,12 +41,7 @@ class _CupertinoRefreshControlDemoState extends State<CupertinoRefreshControlDem
return DefaultTextStyle( return DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle, style: CupertinoTheme.of(context).textTheme.textStyle,
child: CupertinoPageScaffold( child: CupertinoPageScaffold(
child: DecoratedBox( backgroundColor: CupertinoColors.systemGroupedBackground,
decoration: BoxDecoration(
color: CupertinoTheme.of(context).brightness == Brightness.light
? CupertinoColors.extraLightBackgroundGray
: CupertinoColors.darkBackgroundGray,
),
child: CustomScrollView( child: CustomScrollView(
// If left unspecified, the [CustomScrollView] appends an // If left unspecified, the [CustomScrollView] appends an
// [AlwaysScrollableScrollPhysics]. Behind the scene, the ScrollableState // [AlwaysScrollableScrollPhysics]. Behind the scene, the ScrollableState
...@@ -95,7 +90,6 @@ class _CupertinoRefreshControlDemoState extends State<CupertinoRefreshControlDem ...@@ -95,7 +90,6 @@ class _CupertinoRefreshControlDemoState extends State<CupertinoRefreshControlDem
], ],
), ),
), ),
),
); );
} }
} }
...@@ -163,7 +157,7 @@ class _ListItem extends StatelessWidget { ...@@ -163,7 +157,7 @@ class _ListItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
color: CupertinoTheme.of(context).scaffoldBackgroundColor, color: CupertinoDynamicColor.resolve(CupertinoColors.systemBackground, context),
height: 60.0, height: 60.0,
padding: const EdgeInsets.only(top: 9.0), padding: const EdgeInsets.only(top: 9.0),
child: Row( child: Row(
......
...@@ -46,7 +46,13 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro ...@@ -46,7 +46,13 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
), ),
}; };
int sharedValue = 0; int currentSegment = 0;
void onValueChanged(int newValue) {
setState(() {
currentSegment = newValue;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -60,23 +66,28 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro ...@@ -60,23 +66,28 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
trailing: CupertinoDemoDocumentationButton(CupertinoSegmentedControlDemo.routeName), trailing: CupertinoDemoDocumentationButton(CupertinoSegmentedControlDemo.routeName),
), ),
child: DefaultTextStyle( child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle, style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 13),
child: SafeArea( child: SafeArea(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
const Padding( const Padding(padding: EdgeInsets.all(16.0)),
padding: EdgeInsets.all(16.0),
),
SizedBox( SizedBox(
width: 500.0, width: 500.0,
child: CupertinoSegmentedControl<int>( child: CupertinoSegmentedControl<int>(
children: children, children: children,
onValueChanged: (int newValue) { onValueChanged: onValueChanged,
setState(() { groupValue: currentSegment,
sharedValue = newValue; ),
}); ),
}, SizedBox(
groupValue: sharedValue, width: 500,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: CupertinoSlidingSegmentedControl<int>(
children: children,
onValueChanged: onValueChanged,
groupValue: currentSegment,
),
), ),
), ),
Expanded( Expanded(
...@@ -85,7 +96,11 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro ...@@ -85,7 +96,11 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
vertical: 32.0, vertical: 32.0,
horizontal: 16.0, horizontal: 16.0,
), ),
child: Container( child: CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Builder(
builder: (BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 64.0, vertical: 64.0,
horizontal: 16.0, horizontal: 16.0,
...@@ -114,7 +129,10 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro ...@@ -114,7 +129,10 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
), ),
], ],
), ),
child: icons[sharedValue], child: icons[currentSegment],
);
},
),
), ),
), ),
), ),
......
...@@ -33,7 +33,7 @@ class CupertinoButton extends StatefulWidget { ...@@ -33,7 +33,7 @@ class CupertinoButton extends StatefulWidget {
this.color, this.color,
this.disabledColor = CupertinoColors.quaternarySystemFill, this.disabledColor = CupertinoColors.quaternarySystemFill,
this.minSize = kMinInteractiveDimensionCupertino, this.minSize = kMinInteractiveDimensionCupertino,
this.pressedOpacity = 0.1, this.pressedOpacity = 0.4,
this.borderRadius = const BorderRadius.all(Radius.circular(8.0)), this.borderRadius = const BorderRadius.all(Radius.circular(8.0)),
@required this.onPressed, @required this.onPressed,
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)), }) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
...@@ -53,7 +53,7 @@ class CupertinoButton extends StatefulWidget { ...@@ -53,7 +53,7 @@ class CupertinoButton extends StatefulWidget {
this.padding, this.padding,
this.disabledColor = CupertinoColors.quaternarySystemFill, this.disabledColor = CupertinoColors.quaternarySystemFill,
this.minSize = kMinInteractiveDimensionCupertino, this.minSize = kMinInteractiveDimensionCupertino,
this.pressedOpacity = 0.1, this.pressedOpacity = 0.4,
this.borderRadius = const BorderRadius.all(Radius.circular(8.0)), this.borderRadius = const BorderRadius.all(Radius.circular(8.0)),
@required this.onPressed, @required this.onPressed,
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)), }) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
...@@ -102,7 +102,7 @@ class CupertinoButton extends StatefulWidget { ...@@ -102,7 +102,7 @@ class CupertinoButton extends StatefulWidget {
/// The opacity that the button will fade to when it is pressed. /// 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. /// 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. /// your own custom effects is desired.
final double pressedOpacity; final double pressedOpacity;
......
...@@ -304,15 +304,15 @@ class CupertinoColors { ...@@ -304,15 +304,15 @@ class CupertinoColors {
/// The color for text labels containing secondary content, equivalent to /// The color for text labels containing secondary content, equivalent to
/// [UIColor.secondaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173136-secondarylabel). /// [UIColor.secondaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173136-secondarylabel).
static const CupertinoDynamicColor secondaryLabel = CupertinoDynamicColor( static const CupertinoDynamicColor secondaryLabel = CupertinoDynamicColor(
color: Color.fromARGB(255, 0, 0, 0), color: Color.fromARGB(153, 60, 60, 67),
darkColor: Color.fromARGB(255, 255, 255, 255), darkColor: Color.fromARGB(153, 235, 235, 245),
highContrastColor: Color.fromARGB(255, 0, 0, 0), highContrastColor: Color.fromARGB(173, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(255, 255, 255, 255), darkHighContrastColor: Color.fromARGB(173, 235, 235, 245),
elevatedColor: Color.fromARGB(255, 0, 0, 0), elevatedColor: Color.fromARGB(153, 60, 60, 67),
darkElevatedColor: Color.fromARGB(255, 255, 255, 255), darkElevatedColor: Color.fromARGB(153, 235, 235, 245),
highContrastElevatedColor: Color.fromARGB(255, 0, 0, 0), highContrastElevatedColor: Color.fromARGB(173, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(255, 255, 255, 255), darkHighContrastElevatedColor: Color.fromARGB(173, 235, 235, 245),
); );
/// The color for text labels containing tertiary content, equivalent to /// The color for text labels containing tertiary content, equivalent to
/// [UIColor.tertiaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173153-tertiarylabel). /// [UIColor.tertiaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173153-tertiarylabel).
...@@ -889,7 +889,7 @@ class CupertinoDynamicColor extends Color { ...@@ -889,7 +889,7 @@ class CupertinoDynamicColor extends Color {
/// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base] elevation /// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base] elevation
/// level), unless [nullOk] is set to false, in which case an exception will be /// level), unless [nullOk] is set to false, in which case an exception will be
/// thrown. /// thrown.
CupertinoDynamicColor resolveFrom(BuildContext context, { bool nullOk = false }) { CupertinoDynamicColor resolveFrom(BuildContext context, { bool nullOk = true }) {
final Brightness brightness = _isPlatformBrightnessDependent final Brightness brightness = _isPlatformBrightnessDependent
? CupertinoTheme.brightnessOf(context, nullOk: nullOk) ?? Brightness.light ? CupertinoTheme.brightnessOf(context, nullOk: nullOk) ?? Brightness.light
: Brightness.light; : Brightness.light;
......
...@@ -13,6 +13,7 @@ import 'package:flutter/widgets.dart'; ...@@ -13,6 +13,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/animation.dart' show Curves; import 'package:flutter/animation.dart' show Curves;
import 'colors.dart'; import 'colors.dart';
import 'interface_level.dart';
const double _kBackGestureWidth = 20.0; const double _kBackGestureWidth = 20.0;
const double _kMinFlingVelocity = 1.0; // Screen widths per second. const double _kMinFlingVelocity = 1.0; // Screen widths per second.
...@@ -840,7 +841,10 @@ class _CupertinoModalPopupRoute<T> extends PopupRoute<T> { ...@@ -840,7 +841,10 @@ class _CupertinoModalPopupRoute<T> extends PopupRoute<T> {
@override @override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return builder(context); return CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Builder(builder: builder),
);
} }
@override @override
......
...@@ -63,6 +63,44 @@ void main() { ...@@ -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 { testWidgets('Button with background is wider', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(child: const CupertinoButton( await tester.pumpWidget(boilerplate(child: const CupertinoButton(
child: Text('X', style: testStyle), child: Text('X', style: testStyle),
...@@ -145,7 +183,7 @@ void main() { ...@@ -145,7 +183,7 @@ void main() {
of: find.byType(CupertinoButton), of: find.byType(CupertinoButton),
matching: find.byType(FadeTransition), matching: find.byType(FadeTransition),
)); ));
expect(opacity.opacity.value, 0.1); expect(opacity.opacity.value, 0.4);
}); });
testWidgets('pressedOpacity parameter', (WidgetTester tester) async { testWidgets('pressedOpacity parameter', (WidgetTester tester) async {
......
...@@ -978,19 +978,19 @@ void main() { ...@@ -978,19 +978,19 @@ void main() {
await tester.pump(const Duration(milliseconds: 25)); await tester.pump(const Duration(milliseconds: 25));
transition = tester.firstWidget(find.byType(FadeTransition)); 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)); await tester.pump(const Duration(milliseconds: 25));
transition = tester.firstWidget(find.byType(FadeTransition)); 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)); await tester.pump(const Duration(milliseconds: 25));
transition = tester.firstWidget(find.byType(FadeTransition)); 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)); await tester.pump(const Duration(milliseconds: 25));
transition = tester.firstWidget(find.byType(FadeTransition)); 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)); await tester.pump(const Duration(milliseconds: 25));
transition = tester.firstWidget(find.byType(FadeTransition)); transition = tester.firstWidget(find.byType(FadeTransition));
......
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