Created
May 4, 2021 11:38
-
-
Save PiN73/e809f7313390b3ab58bf531230758c43 to your computer and use it in GitHub Desktop.
Flutter AnimatedSwitcher SlideTransition
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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
bool isLoggedIn = false; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: AnimatedSwitcher( | |
duration: Duration(seconds: 1), | |
switchInCurve: Curves.ease, | |
switchOutCurve: Threshold(0), | |
transitionBuilder: (child, animation) => SlideTransition( | |
child: child, | |
position: Tween( | |
begin: Offset(1, 0), | |
end: Offset.zero, | |
).animate(animation), | |
), | |
child: isLoggedIn | |
? Scaffold( | |
key: ValueKey(1), | |
backgroundColor: Colors.blue, | |
) | |
: Scaffold( | |
key: ValueKey(2), | |
backgroundColor: Colors.orange, | |
body: Center( | |
child: ElevatedButton( | |
onPressed: () => setState(() { | |
isLoggedIn = true; | |
}), | |
child: Text('Log in'), | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment