-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from splashbyte/version0.8.0
version 0.8.0-beta.5
- Loading branch information
Showing
10 changed files
with
142 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
part of 'package:animated_toggle_switch/animated_toggle_switch.dart'; | ||
|
||
class _AnimationTypeHoverBuilder<T, V> extends StatefulWidget { | ||
final V Function(StyledToggleProperties<T> local) valueProvider; | ||
final V Function(V value1, V value2, double t) lerp; | ||
final Widget Function(V value) builder; | ||
final GlobalToggleProperties<T> properties; | ||
final Duration animationDuration; | ||
final Curve animationCurve; | ||
final Duration indicatorAppearingDuration; | ||
final Curve indicatorAppearingCurve; | ||
|
||
const _AnimationTypeHoverBuilder({ | ||
required this.valueProvider, | ||
required this.lerp, | ||
required this.builder, | ||
required this.properties, | ||
required this.animationDuration, | ||
required this.animationCurve, | ||
required this.indicatorAppearingDuration, | ||
required this.indicatorAppearingCurve, | ||
}); | ||
|
||
@override | ||
State<_AnimationTypeHoverBuilder<T, V>> createState() => | ||
_AnimationTypeHoverBuilderState(); | ||
} | ||
|
||
class _AnimationTypeHoverBuilderState<T, V> | ||
extends State<_AnimationTypeHoverBuilder<T, V>> { | ||
final _builderKey = GlobalKey(); | ||
T? _lastUnlistedValue; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
if (!widget.properties.isCurrentListed) { | ||
_lastUnlistedValue = widget.properties.current; | ||
} | ||
} | ||
|
||
@override | ||
void didUpdateWidget(covariant _AnimationTypeHoverBuilder<T, V> oldWidget) { | ||
super.didUpdateWidget(oldWidget); | ||
if (!widget.properties.isCurrentListed) { | ||
_lastUnlistedValue = widget.properties.current; | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final pos = widget.properties.position; | ||
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)), | ||
widget.valueProvider( | ||
StyledToggleProperties(value: values[index2], index: index2)), | ||
pos - pos.floor(), | ||
); | ||
final unlistedDoubleValue = isListed ? 0.0 : 1.0; | ||
return TweenAnimationBuilder<double>( | ||
duration: widget.indicatorAppearingDuration, | ||
curve: widget.indicatorAppearingCurve, | ||
tween: Tween(begin: unlistedDoubleValue, end: unlistedDoubleValue), | ||
builder: (context, unlistedDoubleValue, _) { | ||
if (unlistedDoubleValue == 0.0) { | ||
return _EmptyWidget( | ||
key: _builderKey, child: widget.builder(listedValueFunction())); | ||
} | ||
final unlistedValue = widget.valueProvider( | ||
StyledToggleProperties(value: _lastUnlistedValue as T, index: -1)); | ||
return TweenAnimationBuilder<V>( | ||
duration: widget.animationDuration, | ||
curve: widget.animationCurve, | ||
tween: _CustomTween(widget.lerp, | ||
begin: unlistedValue, end: unlistedValue), | ||
builder: (context, unlistedValue, _) { | ||
return _EmptyWidget( | ||
key: _builderKey, | ||
child: widget.builder(unlistedDoubleValue == 1.0 | ||
? unlistedValue | ||
: widget.lerp(listedValueFunction(), unlistedValue, | ||
unlistedDoubleValue)), | ||
); | ||
}); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
part of 'package:animated_toggle_switch/animated_toggle_switch.dart'; | ||
|
||
class _CustomTween<V> extends Tween<V> { | ||
final V Function(V value1, V value2, double t) lerpFunction; | ||
|
||
_CustomTween(this.lerpFunction, {super.begin, super.end}); | ||
|
||
@override | ||
V lerp(double t) => lerpFunction(begin as V, end as V, t); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters