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
return DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: CupertinoPageScaffold(
child: DecoratedBox(
decoration: BoxDecoration(
color: CupertinoTheme.of(context).brightness == Brightness.light
? CupertinoColors.extraLightBackgroundGray
: CupertinoColors.darkBackgroundGray,
),
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: <Widget>[
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<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) {
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: <Widget>[
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<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) {
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(
......
......@@ -46,7 +46,13 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
),
};
int sharedValue = 0;
int currentSegment = 0;
void onValueChanged(int newValue) {
setState(() {
currentSegment = newValue;
});
}
@override
Widget build(BuildContext context) {
......@@ -60,23 +66,28 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
trailing: CupertinoDemoDocumentationButton(CupertinoSegmentedControlDemo.routeName),
),
child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle,
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 13),
child: SafeArea(
child: Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.all(16.0),
),
const Padding(padding: EdgeInsets.all(16.0)),
SizedBox(
width: 500.0,
child: CupertinoSegmentedControl<int>(
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<int>(
children: children,
onValueChanged: onValueChanged,
groupValue: currentSegment,
),
),
),
Expanded(
......@@ -85,36 +96,43 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
vertical: 32.0,
horizontal: 16.0,
),
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 64.0,
horizontal: 16.0,
),
decoration: BoxDecoration(
color: CupertinoTheme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.circular(3.0),
boxShadow: const <BoxShadow>[
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: CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Builder(
builder: (BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(
vertical: 64.0,
horizontal: 16.0,
),
decoration: BoxDecoration(
color: CupertinoTheme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.circular(3.0),
boxShadow: const <BoxShadow>[
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],
);
},
),
child: icons[sharedValue],
),
),
),
......
......@@ -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;
......
......@@ -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;
......
......@@ -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<T> extends PopupRoute<T> {
@override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return builder(context);
return CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Builder(builder: builder),
);
}
@override
......
......@@ -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 {
......
......@@ -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));
......
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