Goal: Press a button and have it switch to another page with an animated transition.
For that, I'm using AnimatedSwitcher.
Below is my code:
class WelcomeScreenSwitcher extends State<RandomWords>{
Widget calledWidget;
void switchPage(int newNumber, context) {
if (newNumber == 1) {
setState(() {calledWidget = welcomeScreen(context);},);
} else if (newNumber == 2) {
setState(() {calledWidget = learnMoreScreen(context);},);}
}
@override
Widget build(BuildContext context) {
if (calledWidget == null) {
switchPage(1, context);
}
return AnimatedSwitcher(
duration: Duration(milliseconds: 5000),
child: calledWidget,
);
Widget welcomeScreen(context){
return Scaffold({body: Column(children: [
RaisedButton(onPressed: () {switchPage(2, context);}, child: Text('B'),),],
);
});
}
Widget learnMoreScreen(context){
return Scaffold({body: Column(children: [
RaisedButton(onPressed: () {switchPage(2, context);}, child: Text('B'),),],
);
});
}
}
The code is functional. It does actually switch between the two pages, but there's no animation to go with it.
At some point during development, I was getting the animation, but then it just stopped happening and I can't find out why. I don't remember changing anything specific about how I call the AnimatedSwitcher.
If it's of any use, hot reloading also doesn't work anymore. I need to Restart the app to have ANY change register. It used to function properly before beginning work on the AnimatedSwitcher.