diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c76b87..f1677b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.0-beta.6 (2023-08-22) + +- adds parameter to `onTap` ([#41](https://github.com/splashbyte/animated_toggle_switch/issues/41)) + ## 0.8.0-beta.5 (2023-08-18) - fixes `AnimationType.onHover` diff --git a/example/lib/crazy_switch.dart b/example/lib/crazy_switch.dart index 1fe3d35..063d40b 100644 --- a/example/lib/crazy_switch.dart +++ b/example/lib/crazy_switch.dart @@ -28,7 +28,7 @@ class _CrazySwitchState extends State { animationDuration: const Duration(milliseconds: 350), animationCurve: Curves.bounceOut, iconBuilder: (context, local, global) => const SizedBox(), - onTap: () => setState(() => current = !current), + onTap: (_) => setState(() => current = !current), iconsTappable: false, onChanged: (b) => setState(() => current = b), height: height, diff --git a/example/lib/main.dart b/example/lib/main.dart index a7b5a37..cbd04e1 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -154,9 +154,9 @@ class _MyHomePageState extends State { colors: [green, Colors.red[800]!], stops: [ global.position - - (1 - 2 * max(0, global.position - 0.5)) * 0.2, + (1 - 2 * max(0, global.position - 0.5)) * 0.7, global.position + - max(0, 2 * (global.position - 0.5)) * 0.2, + max(0, 2 * (global.position - 0.5)) * 0.7, ], )); }, @@ -269,7 +269,7 @@ class _MyHomePageState extends State { Padding( padding: const EdgeInsets.all(8.0), child: Text( - 'Switch inspired by package lite_rolling_switch', + 'Switch similar to package lite_rolling_switch', textAlign: TextAlign.center, ), ), @@ -300,10 +300,7 @@ class _MyHomePageState extends State { CupertinoActivityIndicator( color: Color.lerp( Colors.red[800], green, global.position)), - onChanged: (b) { - setState(() => positive = b); - return Future.delayed(Duration(seconds: 2)); - }, + onChanged: (b) => setState(() => positive = b), iconBuilder: (value) => value ? Icon(Icons.power_outlined, color: green, size: 32.0) : Icon(Icons.power_settings_new_rounded, @@ -375,6 +372,7 @@ class _MyHomePageState extends State { active: false, current: value, values: const [0, 1, 2, 3], + indicatorIconScale: sqrt2, onChanged: (i) { setState(() { value = i; @@ -423,6 +421,7 @@ class _MyHomePageState extends State { ) ], ), + indicatorIconScale: sqrt2, iconBuilder: coloredRollingIconBuilder, borderWidth: 3.0, styleAnimationType: AnimationType.onHover, @@ -457,7 +456,11 @@ class _MyHomePageState extends State { current: nullableValue, allowUnlistedValues: true, values: const [0, 1, 2, 3], - onTap: () => setState(() => nullableValue = null), + onTap: (info) { + if (nullableValue == info.tapped?.value) { + setState(() => nullableValue = null); + } + }, onChanged: (i) => setState(() => nullableValue = i), iconBuilder: rollingIconBuilder, borderWidth: 4.5, @@ -490,7 +493,7 @@ class _MyHomePageState extends State { return const SizedBox(); }, cursors: ToggleCursors(defaultCursor: SystemMouseCursors.click), - onTap: () => setState(() => positive = !positive), + onTap: (_) => setState(() => positive = !positive), iconsTappable: false, wrapperBuilder: (context, global, child) { return Stack( @@ -703,6 +706,7 @@ class _MyHomePageState extends State { current: value, values: const [0, 1, 2, 3], iconOpacity: 1.0, + selectedIconScale: 1.0, indicatorSize: const Size.fromWidth(25), foregroundIndicatorIconBuilder: (context, global) { double pos = global.position; diff --git a/lib/animated_toggle_switch.dart b/lib/animated_toggle_switch.dart index 5eca8b4..fe0c859 100644 --- a/lib/animated_toggle_switch.dart +++ b/lib/animated_toggle_switch.dart @@ -8,11 +8,12 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; -part 'src/animation_type_builder.dart'; +part 'src/animations.dart'; part 'src/properties.dart'; part 'src/style.dart'; part 'src/tweens.dart'; part 'src/cursors.dart'; +part 'src/widgets/animation_type_builder.dart'; part 'src/foreground_indicator_transition.dart'; part 'src/widgets/animated_toggle_switch.dart'; part 'src/widgets/custom_animated_toggle_switch.dart'; diff --git a/lib/src/animations.dart b/lib/src/animations.dart new file mode 100644 index 0000000..20529a1 --- /dev/null +++ b/lib/src/animations.dart @@ -0,0 +1,36 @@ +part of 'package:animated_toggle_switch/animated_toggle_switch.dart'; + +// this Animation is not covered because it does not contain logic but +// forwards all methods to its parent Animation. +// coverage:ignore-start +/// This class is a proxy for another animation. +/// +/// It is used for passing animations in builders without exposing the real +/// animation to the user. +class _PrivateAnimation extends Animation { + final Animation _parent; + + _PrivateAnimation(this._parent); + + @override + void addListener(VoidCallback listener) => _parent.addListener(listener); + + @override + void addStatusListener(AnimationStatusListener listener) => + _parent.addStatusListener(listener); + + @override + void removeListener(VoidCallback listener) => + _parent.removeListener(listener); + + @override + void removeStatusListener(AnimationStatusListener listener) => + _parent.removeStatusListener(listener); + + @override + AnimationStatus get status => _parent.status; + + @override + T get value => _parent.value; +} +// coverage:ignore-end diff --git a/lib/src/properties.dart b/lib/src/properties.dart index 773280f..b77298f 100644 --- a/lib/src/properties.dart +++ b/lib/src/properties.dart @@ -1,6 +1,17 @@ // coverage:ignore-file part of 'package:animated_toggle_switch/animated_toggle_switch.dart'; +class ValueHolder { + final T value; + + /// The index of [value] in [values]. + /// + /// If [values] does not contain [value], this value is set to [-1]. + final int index; + + ValueHolder({required this.value, required this.index}); +} + class GlobalToggleProperties { /// The position of the indicator relative to the indices of the values. final double position; @@ -13,7 +24,7 @@ class GlobalToggleProperties { /// The index of [current] in [values]. /// - /// If [values] does not contain [current], this value is set to [-1]. + /// If [values] does not contain [current], [currentIndex] is set to [-1]. final int currentIndex; /// This value indicates if [values] does contain [current]. @@ -44,6 +55,17 @@ class GlobalToggleProperties { final bool active; + /// This animation indicates whether the indicator is currently visible. + /// + /// [0.0] means it is not visible. + /// + /// [1.0] means it is fully visible. + /// + /// Depending on the curve of the animation, the value can also be below 0.0 or above 1.0. + /// + /// This will be publicly accessible in future releases. + final Animation _indicatorAppearingAnimation; + const GlobalToggleProperties({ required this.position, required this.current, @@ -55,7 +77,8 @@ class GlobalToggleProperties { required this.mode, required this.loadingAnimationValue, required this.active, - }); + required Animation indicatorAppearingAnimation, + }) : _indicatorAppearingAnimation = indicatorAppearingAnimation; } class DetailedGlobalToggleProperties extends GlobalToggleProperties { @@ -88,6 +111,7 @@ class DetailedGlobalToggleProperties extends GlobalToggleProperties { required super.mode, required super.loadingAnimationValue, required super.active, + required super.indicatorAppearingAnimation, }); } @@ -97,7 +121,7 @@ class LocalToggleProperties { /// The index of [value]. /// - /// If [values] does not contain [value], this value is set to [-1]. + /// If [values] does not contain [value], this [index] is set to [-1]. final int index; /// This value indicates if [values] does contain [value]. @@ -181,3 +205,46 @@ class SeparatorProperties { required this.index, }); } + +class TapProperties { + /// Information about the point on which the user has tapped. + /// + /// This value can be [null] if the user taps on the border of an + /// [AnimatedToggleSwitch] or on the wrapper of a + /// [CustomAnimatedToggleSwitch]. + final TapInfo? tapped; + + /// The values which are given to the switch. + /// + /// Helpful if the list is generated e.g. + /// when the switch constructor is called. + final List values; + + const TapProperties({ + required this.tapped, + required this.values, + }); +} + +class TapInfo { + /// The value that the user has tapped. + final T value; + + /// The index of [value] in [values]. + /// + /// [index == position.round()] should always be [true]. + final int index; + + /// The tapped position relative to the indices of the values. + /// + /// [position] can be in the interval from [-0.5] to [values.length - 0.5]. + /// + /// [position.round() == index] should always be [true]. + final double position; + + TapInfo({ + required this.value, + required this.index, + required this.position, + }); +} diff --git a/lib/src/widgets/animated_toggle_switch.dart b/lib/src/widgets/animated_toggle_switch.dart index 10dd4ee..253cb88 100644 --- a/lib/src/widgets/animated_toggle_switch.dart +++ b/lib/src/widgets/animated_toggle_switch.dart @@ -72,7 +72,8 @@ abstract class _AnimatedToggleSwitchParent extends StatelessWidget { /// If you want to implement a completely custom switch, /// you should use [CustomAnimatedToggleSwitch], which is used by /// [AnimatedToggleSwitch] in the background. -class AnimatedToggleSwitch extends _AnimatedToggleSwitchParent { +class AnimatedToggleSwitch + extends _AnimatedToggleSwitchParent { /// The currently selected value. It has to be set at [onChanged] or whenever for animating to this value. /// /// [current] has to be in [values] for working correctly if [allowUnlistedValues] is false. @@ -168,7 +169,7 @@ class AnimatedToggleSwitch extends _AnimatedToggleSwitchParent { final AnimationType indicatorAnimationType; /// Callback for tapping anywhere on the widget. - final TapCallback? onTap; + final TapCallback? onTap; final IconArrangement _iconArrangement; @@ -864,7 +865,7 @@ class AnimatedToggleSwitch extends _AnimatedToggleSwitchParent { this.styleAnimationType = AnimationType.onHover, this.indicatorAnimationType = AnimationType.onHover, this.fittingMode = FittingMode.preventHorizontalOverlapping, - Function()? onTap, + TapCallback? onTap, this.minTouchTargetSize = 48.0, this.textDirection, this.cursors = const ToggleCursors(defaultCursor: SystemMouseCursors.click), @@ -923,9 +924,9 @@ class AnimatedToggleSwitch extends _AnimatedToggleSwitchParent { iconList: null, ); - static Function() _dualOnTap( + static TapCallback _dualOnTap( ChangeCallback? onChanged, List values, T? current) { - return () => + return (info) => onChanged?.call(values.firstWhere((element) => element != current)); } diff --git a/lib/src/animation_type_builder.dart b/lib/src/widgets/animation_type_builder.dart similarity index 81% rename from lib/src/animation_type_builder.dart rename to lib/src/widgets/animation_type_builder.dart index 0448da2..a26f611 100644 --- a/lib/src/animation_type_builder.dart +++ b/lib/src/widgets/animation_type_builder.dart @@ -53,7 +53,6 @@ class _AnimationTypeHoverBuilderState final values = widget.properties.values; final index1 = pos.floor(); final index2 = pos.ceil(); - final isListed = widget.properties.isCurrentListed; V listedValueFunction() => widget.lerp( widget.valueProvider( StyledToggleProperties(value: values[index1], index: index1)), @@ -61,13 +60,13 @@ class _AnimationTypeHoverBuilderState StyledToggleProperties(value: values[index2], index: index2)), pos - pos.floor(), ); - final unlistedDoubleValue = isListed ? 0.0 : 1.0; - return TweenAnimationBuilder( - duration: widget.indicatorAppearingDuration, - curve: widget.indicatorAppearingCurve, - tween: Tween(begin: unlistedDoubleValue, end: unlistedDoubleValue), - builder: (context, unlistedDoubleValue, _) { - if (unlistedDoubleValue == 0.0) { + final indicatorAppearingAnimation = + widget.properties._indicatorAppearingAnimation; + return AnimatedBuilder( + animation: indicatorAppearingAnimation, + builder: (context, _) { + final appearingValue = indicatorAppearingAnimation.value; + if (appearingValue >= 1.0) { return _EmptyWidget( key: _builderKey, child: widget.builder(listedValueFunction())); } @@ -81,10 +80,10 @@ class _AnimationTypeHoverBuilderState builder: (context, unlistedValue, _) { return _EmptyWidget( key: _builderKey, - child: widget.builder(unlistedDoubleValue == 1.0 + child: widget.builder(appearingValue <= 0.0 ? unlistedValue - : widget.lerp(listedValueFunction(), unlistedValue, - unlistedDoubleValue)), + : widget.lerp( + unlistedValue, listedValueFunction(), appearingValue)), ); }); }, diff --git a/lib/src/widgets/custom_animated_toggle_switch.dart b/lib/src/widgets/custom_animated_toggle_switch.dart index 51a80cb..84aef89 100644 --- a/lib/src/widgets/custom_animated_toggle_switch.dart +++ b/lib/src/widgets/custom_animated_toggle_switch.dart @@ -26,7 +26,7 @@ typedef IndicatorAppearingBuilder = Widget Function( typedef ChangeCallback = FutureOr Function(T value); -typedef TapCallback = FutureOr Function(); +typedef TapCallback = FutureOr Function(TapProperties props); enum ToggleMode { animating, dragged, none } @@ -59,7 +59,7 @@ enum IconArrangement { /// /// For pre-made switches, please use the constructors of [AnimatedToggleSwitch] /// instead. -class CustomAnimatedToggleSwitch extends StatefulWidget { +class CustomAnimatedToggleSwitch extends StatefulWidget { /// The currently selected value. It has to be set at [onChanged] or whenever for animating to this value. /// /// [current] has to be in [values] for working correctly if [allowUnlistedValues] is false. @@ -127,7 +127,7 @@ class CustomAnimatedToggleSwitch extends StatefulWidget { final CustomSeparatorBuilder? separatorBuilder; /// Callback for tapping anywhere on the widget. - final TapCallback? onTap; + final TapCallback? onTap; /// Indicates if [onChanged] is called when an icon is tapped. /// @@ -317,19 +317,12 @@ class _CustomAnimatedToggleSwitchState void didUpdateWidget(covariant CustomAnimatedToggleSwitch oldWidget) { super.didUpdateWidget(oldWidget); _checkForUnlistedValue(); - if (oldWidget.indicatorAppearingDuration != - widget.indicatorAppearingDuration) { - _appearingController.duration = widget.indicatorAppearingDuration; - } - if (oldWidget.indicatorAppearingCurve != widget.indicatorAppearingCurve) { - _appearingAnimation.curve = widget.indicatorAppearingCurve; - } - if (oldWidget.animationDuration != widget.animationDuration) { - _controller.duration = widget.animationDuration; - } - if (oldWidget.animationCurve != widget.animationCurve) { - _animation.curve = widget.animationCurve; - } + + _appearingController.duration = widget.indicatorAppearingDuration; + _appearingAnimation.curve = widget.indicatorAppearingCurve; + _controller.duration = widget.animationDuration; + _animation.curve = widget.animationCurve; + if (oldWidget.active && !widget.active) { _cancelDrag(); } @@ -364,9 +357,9 @@ class _CustomAnimatedToggleSwitchState /// This method is called in two [GestureDetector]s because only one /// [GestureDetector.onTapUp] will be triggered. - void _onTap() { + void _onTap(TapProperties info) { if (!_isActive) return; - final result = widget.onTap?.call(); + final result = widget.onTap?.call(info); if (result is Future) { _addLoadingFuture(result); } @@ -384,8 +377,8 @@ class _CustomAnimatedToggleSwitchState /// IMPORTANT: This must be called in [didUpdateWidget] because it updates /// [_currentIndex] also. void _checkValuePosition() { - if (_animationInfo.toggleMode == ToggleMode.dragged) return; _currentIndex = widget.values.indexOf(widget.current); + if (_animationInfo.toggleMode == ToggleMode.dragged) return; if (_currentIndex >= 0) { _animateTo(_currentIndex); } else { @@ -409,17 +402,17 @@ class _CustomAnimatedToggleSwitchState return result; } - /// Returns the value index by the local position of the cursor. + /// Returns the [TapInfo] by the local position of the cursor. /// It is mainly intended as a helper function for the build method. - int _indexFromPosition( + TapInfo _tapInfoFromPosition( double x, DetailedGlobalToggleProperties properties) { - return _doubleFromPosition(x, properties).round(); - } - - /// Returns the value by the local position of the cursor. - /// It is mainly intended as a helper function for the build method. - T _valueFromPosition(double x, DetailedGlobalToggleProperties properties) { - return widget.values[_indexFromPosition(x, properties)]; + final position = _doubleFromPosition(x, properties); + final index = position.round(); + return TapInfo( + value: widget.values[index], + index: index, + position: position, + ); } @override @@ -427,6 +420,8 @@ class _CustomAnimatedToggleSwitchState double spacing = widget.spacing; final textDirection = _textDirectionOf(context); final loadingValue = _animationInfo.loading ? 1.0 : 0.0; + final privateIndicatorAppearingAnimation = + _PrivateAnimation(_appearingAnimation); final defaultCursor = !_isActive ? (_animationInfo.loading @@ -440,9 +435,14 @@ class _CustomAnimatedToggleSwitchState return SizedBox( height: widget.height, child: MouseRegion( + hitTestBehavior: HitTestBehavior.deferToChild, cursor: defaultCursor, child: GestureDetector( - onTapUp: (_) => _onTap(), + behavior: HitTestBehavior.deferToChild, + onTapUp: (_) => _onTap(TapProperties( + tapped: null, + values: widget.values, + )), child: TweenAnimationBuilder( duration: widget.loadingAnimationDuration ?? widget.animationDuration, @@ -468,6 +468,8 @@ class _CustomAnimatedToggleSwitchState mode: _animationInfo.toggleMode, loadingAnimationValue: loadingValue, active: widget.active, + indicatorAppearingAnimation: + privateIndicatorAppearingAnimation, ); Widget child = Padding( padding: widget.padding, @@ -579,6 +581,8 @@ class _CustomAnimatedToggleSwitchState mode: _animationInfo.toggleMode, loadingAnimationValue: loadingValue, active: widget.active, + indicatorAppearingAnimation: + privateIndicatorAppearingAnimation, ); List stack = [ @@ -647,12 +651,17 @@ class _CustomAnimatedToggleSwitchState behavior: HitTestBehavior.translucent, dragStartBehavior: DragStartBehavior.down, onTapUp: (details) { - _onTap(); - if (!widget.iconsTappable) return; - T newValue = _valueFromPosition( + final tapInfo = _tapInfoFromPosition( details.localPosition.dx, properties); - if (newValue == widget.current) return; - _onChanged(newValue); + _onTap(TapProperties( + tapped: tapInfo, + values: widget.values, + )); + if (!widget.iconsTappable) return; + if (tapInfo.value == widget.current) { + return; + } + _onChanged(tapInfo.value); }, onHorizontalDragStart: (details) { if (!isHoveringIndicator( diff --git a/pubspec.lock b/pubspec.lock index 798dcf2..1804eb8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -223,10 +223,10 @@ packages: dependency: "direct dev" description: name: mocktail - sha256: "80a996cd9a69284b3dc521ce185ffe9150cde69767c2d3a0720147d93c0cef53" + sha256: "9503969a7c2c78c7292022c70c0289ed6241df7a9ba720010c0b215af29a5a58" url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "1.0.0" node_preamble: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 8af5fa4..affbd2c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: animated_toggle_switch description: Fully customizable, draggable and animated switch with multiple choices and smooth loading animation. It has prebuilt constructors for rolling and size animations. -version: 0.8.0-beta.5 +version: 0.8.0-beta.6 repository: https://github.com/SplashByte/animated_toggle_switch issue_tracker: https://github.com/SplashByte/animated_toggle_switch/issues @@ -16,7 +16,7 @@ dev_dependencies: flutter_lints: ^2.0.2 flutter_test: sdk: flutter - mocktail: ^0.3.0 + mocktail: ^1.0.0 flutter: @@ -27,3 +27,10 @@ funding: screenshots: - description: 'This image shows three examples of AnimatedToggleSwitch.' path: screenshots/preview.webp + +topics: + - ui + - switch + - toggle + - widget + - widgets diff --git a/test/gesture_test.dart b/test/gesture_test.dart index f87553b..1d84bd3 100644 --- a/test/gesture_test.dart +++ b/test/gesture_test.dart @@ -21,17 +21,29 @@ void main() { onChanged: changedFunction, ), )); - verifyNever(() => tapFunction.call()); + verifyNever(() => tapFunction.call(any())); final currentFinder = find.byKey(iconKey(current)); final nextFinder = find.byKey(iconKey(next)); + final switchFinder = find.byType(AnimatedToggleSwitch); await tester.tap(currentFinder, warnIfMissed: false); - verify(() => tapFunction()).called(1); + verify(() => tapFunction(any( + that: isA>().having( + (i) => i.tapped?.value, 'tapped.value', current)))).called(1); await tester.tap(nextFinder, warnIfMissed: false); verify(() => changedFunction(next)).called(1); - verify(() => tapFunction()).called(1); + verify(() => tapFunction(any( + that: isA>() + .having((i) => i.tapped?.value, 'tapped.value', next)))).called(1); + // tap on the border of the switch + await tester.tapAt(tester.getRect(switchFinder).centerLeft); + verify(() => tapFunction(any( + that: isA>() + .having((i) => i.tapped, 'tapped', null)))).called(1); + + verifyNoMoreInteractions(tapFunction); verifyNoMoreInteractions(changedFunction); }, testDual: false); @@ -109,15 +121,15 @@ void main() { iconsTappable: false, ), )); - verifyNever(() => tapFunction.call()); + verifyNever(() => tapFunction.call(any())); final currentFinder = find.byKey(iconKey(current)); final nextFinder = find.byKey(iconKey(next)); await tester.tap(currentFinder, warnIfMissed: false); - verify(() => tapFunction()).called(1); + verify(() => tapFunction(any())).called(1); await tester.tap(nextFinder, warnIfMissed: false); - verify(() => tapFunction()).called(1); + verify(() => tapFunction(any())).called(1); verifyNoMoreInteractions(changedFunction); }, testDual: false); diff --git a/test/helper.dart b/test/helper.dart index 5a6401b..d97e175 100644 --- a/test/helper.dart +++ b/test/helper.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:animated_toggle_switch/animated_toggle_switch.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; import 'keys.dart'; @@ -75,7 +76,7 @@ typedef SwitchBuilder = AnimatedToggleSwitch Function({ List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues, ToggleStyle? style, @@ -95,7 +96,7 @@ typedef SimpleSwitchBuilder = AnimatedToggleSwitch Function({ List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues, ToggleStyle? style, @@ -122,6 +123,11 @@ void defaultTestAllSwitches( bool testCustom = true, bool testSize = true, }) { + registerFallbackValue(const TapProperties( + tapped: null, + values: [], + )); + testAllSwitches( description, (tester, buildSwitch, type) => test( @@ -132,7 +138,7 @@ void defaultTestAllSwitches( List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues = false, ToggleStyle? style, @@ -183,7 +189,7 @@ void defaultTestAllSwitches( List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues = false, ToggleStyle? style, @@ -246,7 +252,7 @@ void testAllSwitches( List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues = false, ToggleStyle? style, @@ -295,7 +301,7 @@ void testAllSwitches( List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues = false, ToggleStyle? style, @@ -348,7 +354,7 @@ void testAllSwitches( List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues = false, ToggleStyle? style, @@ -399,7 +405,7 @@ void testAllSwitches( List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues = false, ToggleStyle? style, @@ -457,7 +463,7 @@ void testAllSwitches( List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues = false, ToggleStyle? style, @@ -507,7 +513,7 @@ void testAllSwitches( List? iconList, TextDirection? textDirection, ChangeCallback? onChanged, - TapCallback? onTap, + TapCallback? onTap, bool? loading, bool allowUnlistedValues = false, ToggleStyle? style, diff --git a/test/loading_test.dart b/test/loading_test.dart index 6e6938a..633a3a3 100644 --- a/test/loading_test.dart +++ b/test/loading_test.dart @@ -17,7 +17,7 @@ void main() { child: buildSwitch( current: current, iconBuilder: iconBuilder, - onTap: () => Future.delayed(loadingDuration), + onTap: (info) => Future.delayed(loadingDuration), onChanged: (_) => Future.delayed(loadingDuration), ), )); @@ -107,7 +107,7 @@ void main() { child: buildSwitch( current: current, iconBuilder: iconBuilder, - onTap: () => Future.delayed(loadingDuration), + onTap: (info) => Future.delayed(loadingDuration), onChanged: (_) => Future.delayed(loadingDuration), loading: false, ), diff --git a/test/mocks.dart b/test/mocks.dart index 20794ac..b56c802 100644 --- a/test/mocks.dart +++ b/test/mocks.dart @@ -1,14 +1,15 @@ +import 'package:animated_toggle_switch/animated_toggle_switch.dart'; import 'package:mocktail/mocktail.dart'; -abstract class TestFunction { - void call(); +abstract class TestOnTapFunction { + void call(TapProperties props); } abstract class TestOnChangedFunction { void call(T value); } -class MockFunction extends Mock implements TestFunction {} +class MockFunction extends Mock implements TestOnTapFunction {} class MockOnChangedFunction extends Mock implements TestOnChangedFunction {}