Skip to content

Commit

Permalink
version 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
maeddin committed Feb 25, 2022
1 parent 81c6e78 commit 16e9066
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 54 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.2 [2022-02-25]
- BREAKING: changes parameters of SlideCallback
- optimizes fade animation

## 0.1.1 [2022-02-21]
- fixes README.md

Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ Easy to use and highly customizable.

```dart
ActionSlider.standard(
width: 300.0,
child: const Text('Slide to confirm'),
successIcon: const Icon(Icons.check_rounded, color: Colors.white),
onSlide: (loading, success, failure, reset) async {
loading(); //or controller.loading()
onSlide: (controller) async {
controller.loading(); //starts loading animation
await Future.delayed(const Duration(seconds: 3));
success(); //or controller.success()
controller.success(); //starts success animation
},
),
)
```
16 changes: 8 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class _MyHomePageState extends State<MyHomePage> {
ActionSlider.standard(
width: 300.0,
child: const Text('Slide to confirm'),
onSlide: (loading, success, failure) async {
loading(); //or controller.loading()
onSlide: (controller) async {
controller.loading(); //starts loading animation
await Future.delayed(const Duration(seconds: 3));
success(); //or controller.success()
controller.success(); //starts success animation
await Future.delayed(const Duration(seconds: 1));
_controller.reset(); //for resetting the slider
controller.reset(); //resets the slider
},
),
const SizedBox(height: 24.0),
Expand All @@ -74,12 +74,12 @@ class _MyHomePageState extends State<MyHomePage> {
),
backgroundBuilder: (context, pos, width, height, child) => child!,
backgroundBorderRadius: BorderRadius.circular(5.0),
onSlide: (loading, success, failure) async {
loading(); //or controller.loading()
onSlide: (controller) async {
controller.loading(); //or controller.loading()
await Future.delayed(const Duration(seconds: 3));
success(); //or controller.success()
controller.success(); //or controller.success()
await Future.delayed(const Duration(seconds: 1));
_controller.reset(); //for resetting the slider
controller.reset(); //for resetting the slider
},
)
],
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.0"
version: "0.1.2"
async:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: example
description: Example for confirmation_slider.
description: Example for action_slider.

publish_to: 'none'

Expand Down
30 changes: 11 additions & 19 deletions lib/src/action_slider_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ typedef BackgroundBuilder = Widget Function(
BuildContext, double, double, double, Widget?);
typedef ForegroundBuilder = Widget Function(
BuildContext, double, double, double, Widget?, SliderMode);
typedef SlideCallback = Function(Function() loading, Function() success,
Function() failure, Function() reset);
typedef SlideCallback = Function(ActionSliderController controller);

class ActionSliderController extends ValueNotifier<SliderMode> {
ActionSliderController() : super(SliderMode.standard);
Expand Down Expand Up @@ -90,7 +89,7 @@ class ActionSlider extends StatefulWidget {
///Callback for sliding completely to the right.
///Here you should call the loading, success and failure methods of the [controller] for controlling the further behaviour/animations of the slider.
///Optionally [onSlide] can be a [SlideCallback] for using the widget without an external controller.
final Function? onSlide;
final SlideCallback? onSlide;

///Controller for controlling the widget from everywhere.
final ActionSliderController? controller;
Expand Down Expand Up @@ -125,10 +124,7 @@ class ActionSlider extends StatefulWidget {
offset: Offset(0, 2),
)
],
}) : assert(onSlide == null ||
onSlide is SlideCallback ||
onSlide is Function()),
super(key: key);
}) : super(key: key);

///Standard constructor for creating a Slider.
///If [customForegroundBuilder] is not null, the values of [successIcon], [failureIcon], [loadingIcon] and [icon] are ignored.
Expand All @@ -148,7 +144,7 @@ class ActionSlider extends StatefulWidget {
double height = 65.0,
double circleRadius = 25.0,
bool rotating = false,
Function? onSlide,
SlideCallback? onSlide,
ActionSliderController? controller,
double? width,
Duration slideAnimationDuration = const Duration(milliseconds: 250),
Expand Down Expand Up @@ -275,7 +271,8 @@ class ActionSlider extends StatefulWidget {
angle: pos * width / radius, child: icon)
: icon);
}
throw StateError('This should not happen :(');
throw StateError('For using custom SliderModes you have to '
'set customForegroundBuilder!');
},
size: (m1, m2) =>
m2 == SliderMode.success || m2 == SliderMode.failure),
Expand Down Expand Up @@ -381,6 +378,10 @@ class _ActionSliderState extends State<ActionSlider>
return LayoutBuilder(builder: (context, constraints) {
final maxWidth =
min(widget.width ?? double.infinity, constraints.maxWidth);
if (maxWidth == double.infinity) {
throw StateError('The constraints of the ActionSlider '
'are unbound and no width is set');
}
final standardWidth = maxWidth - widget.toggleWidth - frame * 2;
return AnimatedBuilder(
builder: (context, child) {
Expand Down Expand Up @@ -499,15 +500,6 @@ class _ActionSliderState extends State<ActionSlider>
}

void _onSlide() {
if (widget.onSlide == null) return;
if (widget.onSlide is Function()) {
widget.onSlide!();
} else if (widget.onSlide is SlideCallback) {
widget.onSlide!(_controller.loading, _controller.success,
_controller.failure, _controller.reset);
} else {
throw ArgumentError(
'onSlide should be null, a Function() or a SlideCallback');
}
widget.onSlide?.call(_controller);
}
}
37 changes: 19 additions & 18 deletions lib/src/cross_fade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class _CrossFadeState<T> extends State<CrossFade<T>>
if (status == AnimationStatus.completed) {
if (todo.length <= 1) return;
todo.removeAt(0);
if (todo.length > 1) _controller.forward(from: 0.0);
if (todo.length > 1) {
_controller.forward(from: 0.0);
} else {
_controller.value = 0.0;
}
}
});

Expand All @@ -66,8 +70,6 @@ class _CrossFadeState<T> extends State<CrossFade<T>>
),
],
).animate(_controller);

_controller.forward(from: 0.0);
}

@override
Expand All @@ -76,21 +78,14 @@ class _CrossFadeState<T> extends State<CrossFade<T>>
super.dispose();
}

Widget get current => Container(
key: _LocalKey(todo.first), child: widget.builder!(context, todo.first));

Widget? get next => todo.length > 1
? Container(
key: _LocalKey(todo[1]), child: widget.builder!(context, todo[1]))
: null;

@override
Widget build(BuildContext context) {
if (!widget.equals(widget.current, todo.last)) {
if (todo.length < 3)
if (todo.length < 3) {
todo.add(widget.current);
else
} else {
todo[todo.length - 1] = widget.current;
}
if (!_controller.isAnimating) _controller.forward(from: 0.0);
}

Expand All @@ -100,15 +95,21 @@ class _CrossFadeState<T> extends State<CrossFade<T>>
: 1.0,
child: Stack(
children: [
if (!_opacityAnimation.isCompleted)
Opacity(opacity: 1 - _opacityAnimation.value, child: current),
Opacity(opacity: _opacityAnimation.value, child: next ?? current)
Opacity(
key: _LocalKey(todo[0]),
opacity: 1 - _opacityAnimation.value,
child: widget.builder!(context, todo[0])),
if (todo.length > 1)
Opacity(
key: _LocalKey(todo[1]),
opacity: _opacityAnimation.value,
child: widget.builder!(context, todo[1]))
],
),
);
}
}

class _LocalKey extends ValueKey {
const _LocalKey(value) : super(value);
class _LocalKey<T> extends ValueKey<T> {
const _LocalKey(T value) : super(value);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: action_slider
description: A slider to confirm actions and provide feedback on the success of these after subsequent loading.
version: 0.1.1
version: 0.1.2
repository: https://github.com/SplashByte/action_slider

environment:
Expand Down

0 comments on commit 16e9066

Please sign in to comment.