Skip to content

Commit

Permalink
provide childAnimation as param (#247)
Browse files Browse the repository at this point in the history
* provide childAnimation as param

* Fixed crash

_MyHomePageState is a SingleTickerProviderStateMixin but multiple tickers were created.
This was triggered when clicking on anything

* Changed passed argument

Just passing the animation Curve is sufficient, more efficient and just work

* Made example work

Also increased duration to see the actual animation

Co-authored-by: Luca <79720135+luca-colazzo@users.noreply.github.com>
  • Loading branch information
AbhishekDoshi26 and luca-colazzo authored Apr 29, 2022
1 parent 3c3fac8 commit a579c82
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
12 changes: 8 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class MyHomePage extends StatefulWidget {
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
class _MyHomePageState extends State<MyHomePage>
with TickerProviderStateMixin {
var renderOverlay = true;
var visible = true;
var switchLabelPosition = false;
Expand Down Expand Up @@ -189,15 +190,17 @@ class _MyHomePageState extends State<MyHomePage> {
vertical: 4, horizontal: 10),
child: Align(
alignment: Alignment.centerLeft,
child: Text( describeEnum(item).toUpperCase())),
child: Text(describeEnum(item)
.toUpperCase())),
);
}).toList();
},
items: SpeedDialDirection.values
.toList()
.map((item) {
return DropdownMenuItem<SpeedDialDirection>(
child: Text(describeEnum(item).toUpperCase()),
child:
Text(describeEnum(item).toUpperCase()),
value: item,
);
}).toList(),
Expand Down Expand Up @@ -388,8 +391,9 @@ class _MyHomePageState extends State<MyHomePage> {
// activeForegroundColor: Colors.red,
// activeBackgroundColor: Colors.blue,
elevation: 8.0,
animationCurve: Curves.elasticInOut
isOpenOnStart: false,
animationDuration: const Duration(milliseconds: 200),
animationDuration: const Duration(milliseconds: 1500),
shape: customDialRoot
? const RoundedRectangleBorder()
: const StadiumBorder(),
Expand Down
30 changes: 18 additions & 12 deletions lib/src/speed_dial.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class SpeedDial extends StatefulWidget {

final bool switchLabelPosition;

/// This is the animation of the child of the FAB, if specified it will animate b/w this
final Curve? animationCurve;

const SpeedDial({
Key? key,
this.children = const [],
Expand Down Expand Up @@ -178,6 +181,7 @@ class SpeedDial extends StatefulWidget {
this.childPadding = const EdgeInsets.symmetric(vertical: 5),
this.spaceBetweenChildren,
this.spacing,
this.animationCurve,
}) : super(key: key);

@override
Expand Down Expand Up @@ -276,6 +280,7 @@ class _SpeedDialState extends State<SpeedDial>
layerLink: _layerLink,
controller: _controller,
toggleChildren: _toggleChildren,
animationCurve: widget.animationCurve,
),
);
if (widget.renderOverlay) {
Expand Down Expand Up @@ -459,31 +464,32 @@ class _ChildrensOverlay extends StatelessWidget {
required this.dialKey,
required this.controller,
required this.toggleChildren,
this.childAnimation,
}) : super(key: key);

final SpeedDial widget;
final GlobalKey<State<StatefulWidget>> dialKey;
final LayerLink layerLink;
final AnimationController controller;
final Function toggleChildren;
final Curve? animationCurve;

List<Widget> _getChildrenList() {
return widget.children
.map((SpeedDialChild child) {
int index = widget.children.indexOf(child);

var childAnimation = Tween(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: controller,
curve: Interval(
index / widget.children.length,
1.0,
curve: Curves.ease,
),
),
);

return AnimatedChild(
animation: childAnimation,
animation: Tween(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: controller,
curve: Interval(
index / widget.children.length,
1.0,
curve: widget.animationCurve ?? Curves.ease,
),
),
),
index: index,
margin: widget.spaceBetweenChildren != null
? EdgeInsets.fromLTRB(
Expand Down

0 comments on commit a579c82

Please sign in to comment.