/
main.dart
157 lines (145 loc) · 5.19 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
import 'package:flutter/material.dart';
import 'tile.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.light(),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<StatefulWidget> createState() {
return _MyHomePageState();
}
}
class _MyHomePageState extends State<MyHomePage> {
late TextEditingController _scale;
late TextEditingController _size;
late TextEditingController _zoom;
late TextEditingController _xOffset;
late TextEditingController _yOffset;
late TextEditingController _clipOffsetX;
late TextEditingController _clipOffsetY;
late TextEditingController _clipSize;
TileOptions options = TileOptions(
size: const Size(256, 256),
scale: 1.0,
zoom: 15,
xOffset: 0,
yOffset: 0,
clipOffsetX: 0,
clipOffsetY: 0,
clipSize: 0,
renderMode: RenderMode.vector);
@override
void initState() {
super.initState();
_scale = TextEditingController(text: '${options.scale}');
_size = TextEditingController(text: '${options.size.width}');
_zoom = TextEditingController(text: '${options.zoom.toInt()}');
_xOffset = TextEditingController(text: '${options.xOffset.toInt()}');
_yOffset = TextEditingController(text: '${options.yOffset.toInt()}');
_clipOffsetX =
TextEditingController(text: '${options.clipOffsetX.toInt()}');
_clipOffsetY =
TextEditingController(text: '${options.clipOffsetY.toInt()}');
_clipSize = TextEditingController(text: '${options.clipSize.toInt()}');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Vector Tile Example"),
),
body: Column(children: [
Padding(
padding: const EdgeInsets.all(10),
child: Row(children: [
_doubleTextField(_scale, 'Scale',
(value) => options.withValues(scale: value)),
_doubleTextField(_size, 'Size',
(value) => options.withValues(size: Size(value, value))),
_doubleTextField(_xOffset, 'X Offset',
(value) => options.withValues(xOffset: value)),
_doubleTextField(_yOffset, 'Y Offset',
(value) => options.withValues(yOffset: value)),
_doubleTextField(_clipOffsetY, 'Clip Offset X',
(value) => options.withValues(clipOffsetX: value)),
_doubleTextField(_clipOffsetX, 'Clip Offset Y',
(value) => options.withValues(clipOffsetY: value)),
_doubleTextField(_clipSize, 'Clip Size',
(value) => options.withValues(clipSize: value)),
_doubleTextField(
_zoom, 'Zoom', (value) => options.withValues(zoom: value)),
])),
_radio('Rendering', RenderMode.values, () => options.renderMode,
(v) => options.withValues(renderMode: v as RenderMode)),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [Tile(options: options)]))
]));
}
Widget _doubleTextField(TextEditingController controller, String label,
TileOptions Function(double) applyer) {
return _textField(controller, label, (value) {
final d = double.tryParse(value);
if (d != null) {
return applyer(d);
}
return null;
});
}
Widget _textField(TextEditingController controller, String label,
TileOptions? Function(String) applyer) =>
Padding(
padding: const EdgeInsets.only(right: 5.0),
child: SizedBox(
width: 100,
child: TextField(
controller: controller,
onChanged: (value) {
final newOptions = applyer(value);
if (newOptions != null) {
setState(() {
options = newOptions;
});
}
},
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: label,
))));
Widget _radio<T extends Enum>(String label, List<T> values,
T Function() currentValue, TileOptions Function(T value) applyer) {
return Row(
children: values
.map((v) => SizedBox(
width: 150,
child: ListTile(
title: Text(v.name),
leading: Radio<T>(
value: v,
groupValue: currentValue(),
onChanged: (T? value) {
if (value != null) {
setState(() {
options = applyer(value);
});
}
},
),
)))
.toList());
}
}