我无法获得 AnimatedCrossFade 的基本实现。我能够成功更改状态,但是当状态更改时动画不会触发。这是我所拥有的:
class Home extends StatefulWidget {
@override
HomeState createState() => HomeState();
}
class HomeState extends State<Home> {
bool showPost;
@override
void initState() {
showPost = true;
super.initState();
}
@override
Widget build(BuildContext context) {
return CupertinoTabView(builder: (context) {
return getPage();
});
}
Widget getPage() {
return Center(
child: Row(children: [
CupertinoButton(
child: Text("press"),
onPressed: () {
setState(() {
showPost = !showPost;
});
log(showPost.toString());
},
),
AnimatedCrossFade(
duration: const Duration(seconds: 3),
firstChild: Center(child: Text("First Option")),
secondChild: Center(
child: Text("Second Option")),
crossFadeState:
showPost ? CrossFadeState.showFirst : CrossFadeState.showSecond)
]));
}
}