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

Update cupertino demos in gallery (#43841)

parent 76957c9d
...@@ -41,59 +41,53 @@ class _CupertinoRefreshControlDemoState extends State<CupertinoRefreshControlDem ...@@ -41,59 +41,53 @@ 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( child: CustomScrollView(
color: CupertinoTheme.of(context).brightness == Brightness.light // If left unspecified, the [CustomScrollView] appends an
? CupertinoColors.extraLightBackgroundGray // [AlwaysScrollableScrollPhysics]. Behind the scene, the ScrollableState
: CupertinoColors.darkBackgroundGray, // will attach that [AlwaysScrollableScrollPhysics] to the output of
), // [ScrollConfiguration.of] which will be a [ClampingScrollPhysics]
child: CustomScrollView( // on Android.
// If left unspecified, the [CustomScrollView] appends an // To demonstrate the iOS behavior in this demo and to ensure that the list
// [AlwaysScrollableScrollPhysics]. Behind the scene, the ScrollableState // always scrolls, we specifically use a [BouncingScrollPhysics] combined
// will attach that [AlwaysScrollableScrollPhysics] to the output of // with a [AlwaysScrollableScrollPhysics]
// [ScrollConfiguration.of] which will be a [ClampingScrollPhysics] physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
// on Android. slivers: <Widget>[
// To demonstrate the iOS behavior in this demo and to ensure that the list CupertinoSliverNavigationBar(
// always scrolls, we specifically use a [BouncingScrollPhysics] combined largeTitle: const Text('Refresh'),
// with a [AlwaysScrollableScrollPhysics] // We're specifying a back label here because the previous page
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), // is a Material page. CupertinoPageRoutes could auto-populate
slivers: <Widget>[ // these back labels.
CupertinoSliverNavigationBar( previousPageTitle: 'Cupertino',
largeTitle: const Text('Refresh'), trailing: CupertinoDemoDocumentationButton(CupertinoRefreshControlDemo.routeName),
// We're specifying a back label here because the previous page ),
// is a Material page. CupertinoPageRoutes could auto-populate CupertinoSliverRefreshControl(
// these back labels. onRefresh: () {
previousPageTitle: 'Cupertino', return Future<void>.delayed(const Duration(seconds: 2))
trailing: CupertinoDemoDocumentationButton(CupertinoRefreshControlDemo.routeName), ..then<void>((_) {
), if (mounted) {
CupertinoSliverRefreshControl( setState(() => repopulateList());
onRefresh: () { }
return Future<void>.delayed(const Duration(seconds: 2)) });
..then<void>((_) { },
if (mounted) { ),
setState(() => repopulateList()); SliverSafeArea(
} top: false, // Top safe area is consumed by the navigation bar.
}); sliver: SliverList(
}, delegate: SliverChildBuilderDelegate(
), (BuildContext context, int index) {
SliverSafeArea( return _ListItem(
top: false, // Top safe area is consumed by the navigation bar. name: randomizedContacts[index][0],
sliver: SliverList( place: randomizedContacts[index][1],
delegate: SliverChildBuilderDelegate( date: randomizedContacts[index][2],
(BuildContext context, int index) { called: randomizedContacts[index][3] == 'true',
return _ListItem( );
name: randomizedContacts[index][0], },
place: randomizedContacts[index][1], childCount: 20,
date: randomizedContacts[index][2],
called: randomizedContacts[index][3] == 'true',
);
},
childCount: 20,
),
), ),
), ),
], ),
), ],
), ),
), ),
); );
...@@ -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,36 +96,43 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro ...@@ -85,36 +96,43 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
vertical: 32.0, vertical: 32.0,
horizontal: 16.0, horizontal: 16.0,
), ),
child: Container( child: CupertinoUserInterfaceLevel(
padding: const EdgeInsets.symmetric( data: CupertinoUserInterfaceLevelData.elevated,
vertical: 64.0, child: Builder(
horizontal: 16.0, builder: (BuildContext context) {
), return Container(
decoration: BoxDecoration( padding: const EdgeInsets.symmetric(
color: CupertinoTheme.of(context).scaffoldBackgroundColor, vertical: 64.0,
borderRadius: BorderRadius.circular(3.0), horizontal: 16.0,
boxShadow: const <BoxShadow>[ ),
BoxShadow( decoration: BoxDecoration(
offset: Offset(0.0, 3.0), color: CupertinoTheme.of(context).scaffoldBackgroundColor,
blurRadius: 5.0, borderRadius: BorderRadius.circular(3.0),
spreadRadius: -1.0, boxShadow: const <BoxShadow>[
color: _kKeyUmbraOpacity, BoxShadow(
), offset: Offset(0.0, 3.0),
BoxShadow( blurRadius: 5.0,
offset: Offset(0.0, 6.0), spreadRadius: -1.0,
blurRadius: 10.0, color: _kKeyUmbraOpacity,
spreadRadius: 0.0, ),
color: _kKeyPenumbraOpacity, BoxShadow(
), offset: Offset(0.0, 6.0),
BoxShadow( blurRadius: 10.0,
offset: Offset(0.0, 1.0), spreadRadius: 0.0,
blurRadius: 18.0, color: _kKeyPenumbraOpacity,
spreadRadius: 0.0, ),
color: _kAmbientShadowOpacity, BoxShadow(
), offset: Offset(0.0, 1.0),
], blurRadius: 18.0,
spreadRadius: 0.0,
color: _kAmbientShadowOpacity,
),
],
),
child: icons[currentSegment],
);
},
), ),
child: icons[sharedValue],
), ),
), ),
), ),
......
...@@ -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