Skip to content

Instantly share code, notes, and snippets.

@red-star25
Created September 23, 2021 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save red-star25/27bf71cfe9df54b37e4420a64daa34a2 to your computer and use it in GitHub Desktop.
Save red-star25/27bf71cfe9df54b37e4420a64daa34a2 to your computer and use it in GitHub Desktop.
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