/
main.dart
308 lines (284 loc) · 8.45 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import 'package:flutter/material.dart';
import 'package:img/img.dart';
void main() => runApp(const ExampleFrame());
/// [MaterialApp] frame.
class ExampleFrame extends StatelessWidget {
/// [MaterialApp] frame.
const ExampleFrame({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => const MaterialApp(
debugShowCheckedModeBanner: false,
home: Example(),
);
}
/// Construct a [new Example] `Widget` to fill an [ExampleFrame].
class Example extends StatelessWidget {
/// Fill an [ExampleFrame] with a [Scaffold] and [AppBar] whose body is a
/// [PageView]. The `children` of this swiping page view are each built by
/// [buildView], save for an example that is recreated from a README sample
/// and another example demonstrating [StringToTexture].
const Example({Key? key}) : super(key: key);
/// One entire page for a [PageView]. Comprised of a [SingleChildScrollView]
/// and a [Column], it presents a series of [Text] and [Img].
Widget buildView({
required Repeat repeat,
required double w,
required double h,
required String url,
required double scale1,
required double scale2,
required String mode,
required String subtitle,
}) =>
SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 25),
ImageToo(image: NetworkImage(url, scale: scale1)),
const SizedBox(height: 25),
Text(
'Repeat.$mode',
style: const TextStyle(fontSize: 30, color: Colors.white),
),
Text(
subtitle,
style: const TextStyle(fontSize: 20, color: Colors.white),
),
Center(
/// Equivalent to [ImageToo]
child: Img(
image: NetworkImage(url, scale: scale2),
repeat: repeat,
width: w,
height: h,
),
),
],
),
);
@override
Widget build(BuildContext context) {
final s = MediaQuery.of(context).size;
final w = s.width;
final h = s.height;
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(title: const Text('img')),
body: PageView(
physics: const BouncingScrollPhysics(),
children: [
buildView(
repeat: Repeat.noRepeat,
w: w,
h: h,
url: window,
scale1: 3,
scale2: 1,
mode: 'noRepeat',
subtitle: '',
),
buildView(
repeat: Repeat.repeatX,
w: w,
h: h,
url: fire,
scale1: 3,
scale2: 1,
mode: 'repeatX',
subtitle: 'Works great because this image naturally tiles',
),
buildView(
repeat: Repeat.repeat,
w: w,
h: h,
url: fire,
scale1: 3,
scale2: 2,
mode: 'repeat',
subtitle: 'but uh oh... what if we need fire everywhere?',
),
buildView(
repeat: Repeat.mirror,
w: w,
h: h,
url: fire,
scale1: 3,
scale2: 4,
mode: 'mirror',
subtitle: 'Now that\'s strange, but a little better!',
),
buildView(
repeat: Repeat.mirror,
w: w,
h: h,
url: glitter,
scale1: 3,
scale2: 6,
mode: 'mirror',
subtitle: 'Turn any image into a seamless texture.',
),
buildView(
repeat: Repeat.mirror,
w: w,
h: h,
url: frog,
scale1: 3,
scale2: 2,
mode: 'mirror',
subtitle: 'Or create a kalediscopic dreamworld!',
),
/// Sample from README, adjusted
Center(
child: Container(
width: w * 2 / 3,
height: h * 2 / 3,
decoration: const BoxDecoration(
color: Colors.amber,
image: DecorationImageToo(
image: NetworkImage(fire, scale: 14),
repeatMode: Repeat.mirror,
),
),
child: const Center(
child: Text(
'THE\nFLOOR\nIS\nLAVA',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 75,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
),
),
/// Extension methods
tatsu.toSeamlessTexture(),
tatsu.toSeamlessTexture(scale: 10),
InteractiveViewer(
maxScale: 150,
child: tatsu.toSeamlessTexture(scale: 75),
),
const LovelyRainyDay(),
],
),
);
}
}
/// Construct a [Stack] of mirror-tiling images formed by
/// `String.toSeamlessTexture` method with a [new LovelyRainyDay].
class LovelyRainyDay extends StatelessWidget {
/// A [Stack] of mirror-tiling images formed by
/// `String.toSeamlessTexture` method.
///
/// Draws a scene of a lovely spring day with clouds, hills, a pond,
/// and some rain.
const LovelyRainyDay({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned.fill(child: clouds.toSeamlessTexture(scale: 2, height: 300)),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
child: field.toSeamlessRow(height: 300),
),
),
for (var hill in hillLayers) hill,
for (var shower in rainLayers) shower,
],
);
}
}
/// A group of [Positioned] images that are formed into mirroring textures
/// from simple `String`s.
final hillLayers = [
Positioned(
bottom: 300,
left: 0,
right: 0,
child: hills.toSeamlessRow(
height: 190,
color: Colors.blueGrey[900]!.withOpacity(0.75),
blendMode: BlendMode.srcATop,
),
),
Positioned(
bottom: 235,
left: 0,
right: 0,
child: hills.toSeamlessRow(
height: 190,
color: Colors.black.withOpacity(0.35),
blendMode: BlendMode.srcATop,
),
),
Positioned(
bottom: 180,
left: 0,
right: 0,
child: hills.toSeamlessRow(
height: 100,
color: Colors.blueGrey[800]!.withOpacity(0.4),
blendMode: BlendMode.srcATop,
),
),
Positioned(
bottom: 145,
left: 0,
right: 0,
child: hills.toSeamlessRow(height: 50, offset: const Offset(20, 0)),
),
];
/// A group of [Positioned] images that are formed into mirroring textures
/// from simple `String`s.
final rainLayers = [
Positioned(
left: -450,
top: 0,
right: 0,
bottom: 0,
child: rain.toSeamlessColumn(scale: 2),
),
Positioned(
left: -400,
top: 0,
right: 0,
bottom: 0,
child: rain.toSeamlessColumn(scale: 3),
),
Positioned(
left: -225,
top: 0,
right: 0,
bottom: 0,
child: rain.toSeamlessColumn(scale: 5),
),
];
/// URL leading to an animated image of a window with a moon and tain.
const window = 'https://www.gifstop.com/images/weathergifs/raingif.gif';
/// URL leading to an animated image of fire.
const fire = 'https://gifimage.net/wp-content/uploads/2017/08/'
'transparent-fire-gif-22.gif';
/// URL leading to an animated image colored glitter.
const glitter = 'https://i.giphy.com/media/R2B4OcBpN7YS4/giphy.gif';
/// URL leading to an animated image of a frog floating in water.
const frog = 'https://www.gifmania.it/Gif-Animate-Animali/'
'Immagini-Animate-Rane/Gif-Animati-Immagini-Di-Rane/'
'Immagini-Di-Rane-66777.gif';
/// URL leading to a Tatsuro Yamashita album cover.
const tatsu = 'https://spice.eplus.jp/images/'
'KefMrp9J1bM7NGRvFqK64ZNOfbTGUDKVCC8ePaiKB1cOcOJz1rEN3DQUJMBZhQJ2.jpg';
/// URL leading to an image of clouds.
const clouds = 'https://i.pinimg.com/736x/9e/03/4d/'
'9e034dec913971c7750e4836dc1f479b.jpg';
/// URL leading to an image of a field.
const field =
'https://static.vecteezy.com/system/resources/previews/000/519/977/original/open-field-vector.jpg';
/// URL leading to an image of hills.
const hills = 'http://clipart-library.com/img1/1255972.png';
/// URL leading to an animated image of rain.
const rain = 'https://i.giphy.com/media/495IrnWutQBc4hhhoL/giphy.gif';