-
-
Notifications
You must be signed in to change notification settings - Fork 508
/
Copy pathanim_switch_layout_demo_page.dart
149 lines (137 loc) · 3.95 KB
/
anim_switch_layout_demo_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class AnimSwitchLayoutDemoPage extends StatefulWidget {
const AnimSwitchLayoutDemoPage({super.key});
@override
State<AnimSwitchLayoutDemoPage> createState() =>
_AnimSwitchLayoutDemoPageState();
}
class _AnimSwitchLayoutDemoPageState extends State<AnimSwitchLayoutDemoPage>
with SingleTickerProviderStateMixin {
int currentIndex = 0;
PositionedItemData getIndexPosition(int index, Size size) {
switch (index) {
case 0:
return PositionedItemData(
width: size.width / 2 - 5,
height: size.height,
left: 0,
top: 0,
);
case 1:
return PositionedItemData(
width: size.width / 2 - 5,
height: size.height / 2 - 5,
left: size.width / 2 + 5,
top: 0,
);
case 2:
return PositionedItemData(
width: size.width / 2 - 5,
height: size.height,
left: size.width / 2 + 5,
top: size.height / 2 + 5,
);
}
return PositionedItemData(
width: size.width / 2 - 5,
height: size.height,
left: 0,
top: 0,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("ControllerDemoPage"),
),
extendBody: true,
body: Center(
child: Container(
height: 300,
margin: const EdgeInsets.symmetric(horizontal: 20),
child: LayoutBuilder(
builder: (_, con) {
var f = getIndexPosition(currentIndex % 3, con.biggest);
var s = getIndexPosition((currentIndex + 1) % 3, con.biggest);
var t = getIndexPosition((currentIndex + 2) % 3, con.biggest);
return Stack(
fit: StackFit.expand,
children: [
PositionItem(f,
child: InkWell(
onTap: () {
if (kDebugMode) {
print("red");
}
},
child: Container(color: Colors.redAccent),
)),
PositionItem(s,
child: InkWell(
onTap: () {
if (kDebugMode) {
print("green");
}
},
child: Container(color: Colors.greenAccent),
)),
PositionItem(t,
child: InkWell(
onTap: () {
if (kDebugMode) {
print("yello");
}
},
child: Container(color: Colors.yellowAccent),
)),
],
);
},
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
currentIndex = currentIndex + 1;
});
},
),
);
}
}
class PositionItem extends StatelessWidget {
final PositionedItemData data;
final Widget child;
const PositionItem(this.data, {super.key, required this.child});
@override
Widget build(BuildContext context) {
return AnimatedPositioned(
duration: const Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
left: data.left,
top: data.top,
child: AnimatedContainer(
duration: const Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
width: data.width,
height: data.height,
child: child,
),
);
}
}
class PositionedItemData {
final double left;
final double top;
final double width;
final double height;
PositionedItemData({
required this.left,
required this.top,
required this.width,
required this.height,
});
}