Skip to content

Instantly share code, notes, and snippets.

@PiN73
Created May 4, 2021 11:38
Show Gist options
  • Save PiN73/e809f7313390b3ab58bf531230758c43 to your computer and use it in GitHub Desktop.
Save PiN73/e809f7313390b3ab58bf531230758c43 to your computer and use it in GitHub Desktop.
Flutter AnimatedSwitcher SlideTransition
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