Commit 732a83d4 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Add CupertinoSwitch (#7326)

This patch contains a first draft of an iOS-style switch. We'll likely need to
tweak the constants upon closer study, but the basics are here.
parent 500981fe
......@@ -9,6 +9,7 @@
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/animation/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/cassowary/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/cupertino/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/engine/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/examples/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/foundation/packages" />
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// Flutter widgets implementing the current iOS design language.
///
/// To use, import `package:flutter/cupertino.dart`.
library cupertino;
export 'src/cupertino/switch.dart';
This diff is collapsed.
......@@ -290,12 +290,12 @@ class _RenderSwitch extends RenderToggleable {
HorizontalDragGestureRecognizer _drag;
void _handleDragStart(DragStartDetails details) {
if (onChanged != null)
if (isInteractive)
reactionController.forward();
}
void _handleDragUpdate(DragUpdateDetails details) {
if (onChanged != null) {
if (isInteractive) {
position
..curve = null
..reverseCurve = null;
......
......@@ -526,13 +526,20 @@ class BoxShadow {
/// The amount the box should be inflated prior to applying the blur.
final double spreadRadius;
/// The [blurRadius] in sigmas instead of logical pixels.
/// Converts a blur radius in pixels to sigmas.
///
/// See the sigma argument to [MaskFilter.blur].
///
//
// See SkBlurMask::ConvertRadiusToSigma().
// <https://github.com/google/skia/blob/bb5b77db51d2e149ee66db284903572a5aac09be/src/effects/SkBlurMask.cpp#L23>
double get blurSigma => blurRadius * 0.57735 + 0.5;
static double convertRadiusToSigma(double radius) {
return radius * 0.57735 + 0.5;
}
/// The [blurRadius] in sigmas instead of logical pixels.
///
/// See the sigma argument to [MaskFilter.blur].
double get blurSigma => convertRadiusToSigma(blurRadius);
/// Returns a new box shadow with its offset, blurRadius, and spreadRadius scaled by the given factor.
BoxShadow scale(double factor) {
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Switch can toggle on tap', (WidgetTester tester) async {
Key switchKey = new UniqueKey();
bool value = false;
await tester.pumpWidget(
new StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return new Center(
child: new CupertinoSwitch(
key: switchKey,
value: value,
onChanged: (bool newValue) {
setState(() {
value = newValue;
});
},
),
);
},
),
);
expect(value, isFalse);
await tester.tap(find.byKey(switchKey));
expect(value, isTrue);
});
}
......@@ -7,6 +7,21 @@
<excludeFolder url="file://$MODULE_DIR$/bin/packages" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/dart_dependencies_test/good/.pub" />
<excludeFolder url="file://$MODULE_DIR$/test/data/dart_dependencies_test/good/build" />
<excludeFolder url="file://$MODULE_DIR$/test/data/dart_dependencies_test/good/lib/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/dart_dependencies_test/good/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/dart_dependencies_test/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/dart_dependencies_test/syntax_error/.pub" />
<excludeFolder url="file://$MODULE_DIR$/test/data/dart_dependencies_test/syntax_error/build" />
<excludeFolder url="file://$MODULE_DIR$/test/data/dart_dependencies_test/syntax_error/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/intellij/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/intellij/plugins/Dart/lib/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/intellij/plugins/Dart/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/intellij/plugins/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/process_manager/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/data/process_manager/replay/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/src/ios/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/src/packages" />
......
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