Я пытался улучшить себя, изучая новые виджеты, когда я работал с AnimatedIcons и Animations, у меня возникла проблема, после добавления двух анимированных значков и виджета InkWell для каждого из них, когда я нажимаю один из значков, другой тоже начинает анимацию, как я могу предотвратить это?
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyFirstWidget(),
);
}
}
class MyFirstWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() => MyFirstWidgetState();
}
class MyFirstWidgetState extends State<MyFirstWidget>
with SingleTickerProviderStateMixin {
bool reverse = false, reverse1 = false;
Animation animation;
AnimationController animationController, animationController1;
@override
void initState() {
super.initState();
animationController =
new AnimationController(vsync: this, duration: Duration(seconds: 1));
animation = Tween<double>(begin: 0, end: 2).animate(animationController);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.green,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage("assets/mathware.jpg"),fit: BoxFit.cover)),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () {
if (reverse == false) {
animationController.forward();
} else
animationController.reverse();
reverse = !reverse;
},
child: AnimatedIcon(
icon: AnimatedIcons.home_menu,
progress: animation,
size: 50,
color: Colors.black,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () {
if (reverse1 == false) {
animationController1.forward();
} else
animationController1.reverse();
reverse1 = !reverse1;
},
child: AnimatedIcon(
icon: AnimatedIcons.event_add,
progress: animation,
size: 50,
color: Colors.black,
),
),
],
)
],
)
],
),
),
);
}
}