-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
60 lines (54 loc) · 1.74 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'package:flutter/material.dart';
void main() => runApp(const ImplicitAnimationsApp());
class ImplicitAnimationsApp extends StatefulWidget {
const ImplicitAnimationsApp({super.key});
@override
State<ImplicitAnimationsApp> createState() => _ImplicitAnimationsAppState();
}
class _ImplicitAnimationsAppState extends State<ImplicitAnimationsApp> {
var isForward = true;
void _onAnimationEnd() {
setState(() {
isForward = !isForward;
});
}
@override
Widget build(BuildContext context) {
final screenSize = MediaQuery.sizeOf(context);
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: const Text("Implicit Animations"),
),
body: Center(
child: Container(
width: screenSize.width,
height: screenSize.width,
color: isForward ? const Color(0xFF222222) : Colors.white,
child: Center(
child: Container(
width: screenSize.width / 2,
height: screenSize.width / 2,
decoration: BoxDecoration(
color: const Color(0xFFE14C45),
shape: isForward ? BoxShape.rectangle : BoxShape.circle,
),
child: AnimatedAlign(
alignment:
isForward ? Alignment.centerRight : Alignment.centerLeft,
duration: const Duration(seconds: 1),
onEnd: _onAnimationEnd,
child: Container(
width: 12,
color: isForward ? Colors.white : Colors.black,
),
),
),
),
),
),
),
);
}
}