Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool animatePosition = false;
Alignment currentAlignment = Alignment.topLeft;
late Alignment resultAlignment;
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
setState(() {
animatePosition = true;
resultAlignment = Alignment.topLeft;
});
},
child: const Text("TopLeft"),
),
),
Expanded(
child: ElevatedButton(
onPressed: () {
setState(() {
animatePosition = true;
resultAlignment = Alignment.topRight;
});
},
child: const Text("TopRight"),
),
),
Expanded(
child: ElevatedButton(
onPressed: () {
setState(() {
animatePosition = true;
resultAlignment = Alignment.topCenter;
});
},
child: const Text("TopCenter"),
),
),
// same for other alignment
],
),
body: Container(
color: Colors.blueGrey,
child: AnimatedAlign(
alignment: animatePosition ? resultAlignment : currentAlignment,
duration: const Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
child: Container(
height: 100,
width: 100,
color: Colors.green,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment