-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgalaxy.dart
More file actions
152 lines (140 loc) · 4.11 KB
/
galaxy.dart
File metadata and controls
152 lines (140 loc) · 4.11 KB
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
150
151
152
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Galaxy extends StatefulWidget {
static Map<String, WidgetBuilder> routeNameMap = {
"/Galaxy": (context) => Galaxy()
};
@override
_GalaxyState createState() => _GalaxyState();
}
const _kDefaultCircleSize = 20.0;
const _kDefaultCircleRadius = 100.0;
const _kAnimationDuration = 4000;
const _kBlurRadius = 24.0;
const _kSpreadRadius = 16.0;
class _GalaxyState extends State<Galaxy> with SingleTickerProviderStateMixin {
AnimationController animationController;
Animation animation;
Offset panOffset = Offset.zero;
@override
void initState() {
super.initState();
animationController = AnimationController(
duration: const Duration(milliseconds: _kAnimationDuration),
vsync: this,
);
animationController.addListener(() {
setState(() {});
});
animation =
Tween(begin: 0.0, end: 2 * math.pi).animate(animationController);
animationController.repeat();
}
@override
void dispose() {
animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Transform(
transform: Matrix4.identity()
..setEntry(3, 2, 0.001) // perspective
..rotateX(0.01 * panOffset.dy), // changed
alignment: FractionalOffset.center,
child: GestureDetector(
onPanUpdate: (details) => setState(() => panOffset += details.delta),
onPanEnd: (details) => setState(() => panOffset = Offset.zero),
child: buildMainScreen(context),
),
);
}
Widget buildMainScreen(BuildContext context) {
Size size = MediaQuery.of(context).size;
double dy = math.sin(animation.value) * _kDefaultCircleRadius;
double dx = math.cos(animation.value) * _kDefaultCircleRadius;
return Scaffold(
backgroundColor: Colors.black,
body: Stack(
fit: StackFit.expand,
alignment: Alignment.center,
children: [
getRedBox(Offset(size.width / 2 + dx, size.height / 2 + dy)),
getBlueBox(Offset(size.width / 2 - dx, size.height / 2 - dy)),
getLittleBox(Offset(size.width / 2 - dx, size.height / 2 - dy)),
],
),
);
}
Widget getLittleBox(Offset offset) {
double dx =
offset.dx + math.sin(animation.value) * _kDefaultCircleRadius / 2;
double dy =
offset.dy + math.cos(animation.value) * _kDefaultCircleRadius / 2;
return Positioned.fromRect(
rect: Rect.fromCenter(
center: Offset(dx, dy),
width: _kDefaultCircleSize / 2,
height: _kDefaultCircleSize / 2,
),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.grey[200],
blurRadius: _kBlurRadius / 2,
spreadRadius: _kSpreadRadius / 2,
),
BoxShadow(color: Colors.grey),
],
),
),
);
}
Widget getBlueBox(Offset offset) {
return Positioned.fromRect(
rect: Rect.fromCenter(
center: offset,
width: _kDefaultCircleSize,
height: _kDefaultCircleSize,
),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.cyanAccent[200],
blurRadius: _kBlurRadius,
spreadRadius: _kSpreadRadius,
),
BoxShadow(color: Colors.cyanAccent),
],
),
),
);
}
Widget getRedBox(Offset offset) {
return Positioned.fromRect(
rect: Rect.fromCenter(
center: offset,
width: _kDefaultCircleSize,
height: _kDefaultCircleSize,
),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.orange[200],
blurRadius: _kBlurRadius,
spreadRadius: _kSpreadRadius,
),
BoxShadow(color: Colors.orange),
],
),
),
);
}
}