-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalignment_change_page.dart
80 lines (73 loc) · 2.09 KB
/
alignment_change_page.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'package:flutter/material.dart';
import 'package:flutter_animations/app_drawer.dart';
import 'package:flutter_animations/core/duration_items.dart';
class AlignmentChangePage extends StatefulWidget {
const AlignmentChangePage({Key? key}) : super(key: key);
@override
State<AlignmentChangePage> createState() => _AlignmentChangePageState();
}
class _AlignmentChangePageState extends State<AlignmentChangePage>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late final Tween<AlignmentGeometry> _alignmentTween;
@override
void initState() {
super.initState();
_alignmentTween = Tween<AlignmentGeometry>(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
);
_controller = AnimationController(
vsync: this,
duration: const DurationItems.durationLow(),
);
_controller.forward();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("AlignTransition and Controller"),
),
drawer: const AppDrawer(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
setState(() {
_controller.value == 0
? _controller.animateTo(1)
: _controller.animateTo(0);
});
},
child: const Text("Change Alignment"),
),
const SizedBox(
height: 20,
),
Container(
color: Colors.black,
width: 200,
height: 200,
child: AlignTransition(
alignment: _alignmentTween.animate(_controller),
child: Container(
color: const Color(0xFFD4606A),
width: 50,
height: 50,
),
),
)
],
),
),
);
}
}