-
Notifications
You must be signed in to change notification settings - Fork 779
/
Copy pathlocalization.dart
305 lines (292 loc) · 10.5 KB
/
localization.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
///Flutter package imports
import 'package:flutter/material.dart';
///Core theme import
// ignore: depend_on_referenced_packages
import 'package:syncfusion_flutter_core/theme.dart';
///Map import
// ignore: import_of_legacy_library_into_null_safe
import 'package:syncfusion_flutter_maps/maps.dart';
///Local import
import '../../../model/sample_view.dart';
/// Renders the map widget with range color mapping
class MapsWithLocalization extends LocalizationSampleView {
/// Creates the map widget with range color mapping
const MapsWithLocalization(Key key) : super(key: key);
@override
_MapsWithLocalizationState createState() => _MapsWithLocalizationState();
}
class _MapsWithLocalizationState extends LocalizationSampleViewState {
late List<_Model> _australiaData;
late List<String> _stateDataLabelsLocale;
late MapShapeSource _mapShapeSource;
late String _title;
late bool _isLightTheme;
late ThemeData _themeData;
@override
Widget buildSample(BuildContext context) {
_themeData = Theme.of(context);
_isLightTheme = _themeData.brightness == Brightness.light;
_australiaData = <_Model>[
const _Model(0.809, 'New South Wales'),
const _Model(1.857, 'Queensland'),
const _Model(1.419, 'Northern Territory'),
const _Model(0.237, 'Victoria'),
const _Model(1.044, 'South Australia'),
const _Model(2.642, 'Western Australia'),
const _Model(0.0907, 'Tasmania'),
const _Model(0.0023, 'Australian Capital Territory'),
];
_updateLabelsBasedOnLocale();
_mapShapeSource = MapShapeSource.asset(
'assets/australia.json',
shapeDataField: 'STATE_NAME',
dataCount: _australiaData.length,
primaryValueMapper: (int index) => _australiaData[index].state,
dataLabelMapper: (int index) => _stateDataLabelsLocale[index],
shapeColorValueMapper: (int index) => _australiaData[index].state,
shapeColorMappers: <MapColorMapper>[
MapColorMapper(
value: 'New South Wales',
color: const Color.fromRGBO(255, 215, 0, 1.0),
text: _stateDataLabelsLocale[0],
),
MapColorMapper(
value: 'Queensland',
color: const Color.fromRGBO(72, 209, 204, 1.0),
text: _stateDataLabelsLocale[1],
),
MapColorMapper(
value: 'Northern Territory',
color: const Color.fromRGBO(255, 78, 66, 1.0),
text: _stateDataLabelsLocale[2],
),
MapColorMapper(
value: 'Victoria',
color: const Color.fromRGBO(171, 56, 224, 0.75),
text: _stateDataLabelsLocale[3],
),
MapColorMapper(
value: 'South Australia',
color: const Color.fromRGBO(126, 247, 74, 0.75),
text: _stateDataLabelsLocale[4],
),
MapColorMapper(
value: 'Western Australia',
color: const Color.fromRGBO(79, 60, 201, 0.7),
text: _stateDataLabelsLocale[5],
),
MapColorMapper(
value: 'Tasmania',
color: const Color.fromRGBO(99, 164, 230, 1),
text: _stateDataLabelsLocale[6],
),
MapColorMapper(
value: 'Australian Capital Territory',
color: Colors.teal,
text: _stateDataLabelsLocale[7],
),
],
);
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final bool scrollEnabled = constraints.maxHeight > 400;
double height = scrollEnabled ? constraints.maxHeight : 400;
if (model.isWebFullView ||
(model.isMobile &&
MediaQuery.of(context).orientation == Orientation.landscape)) {
final double refHeight = height * 0.6;
height = height > 500 ? (refHeight < 500 ? 500 : refHeight) : height;
}
return Center(
child: SingleChildScrollView(
child: ColoredBox(
color: model.sampleOutputCardColor,
child: SizedBox(
width: constraints.maxWidth,
height: height,
child: _buildMapsWidget(scrollEnabled),
),
),
),
);
},
);
}
Widget _buildMapsWidget(bool scrollEnabled) {
return Center(
child: Padding(
padding:
scrollEnabled
? EdgeInsets.only(
top: MediaQuery.of(context).size.height * 0.05,
bottom: MediaQuery.of(context).size.height * 0.05,
right: 10,
)
: const EdgeInsets.only(right: 10, bottom: 15),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 15, bottom: 30),
child: Align(
child: Text(
_title,
textDirection: TextDirection.rtl,
style: _themeData.textTheme.titleMedium,
),
),
),
Expanded(
child: SfMapsTheme(
data: const SfMapsThemeData(
shapeHoverColor: Colors.transparent,
shapeHoverStrokeColor: Colors.transparent,
),
child: SfMaps(
layers: <MapShapeLayer>[
MapShapeLayer(
source: _mapShapeSource,
strokeColor: model.homeCardColor,
strokeWidth: 0.5,
showDataLabels: true,
legend: const MapLegend(
MapElement.shape,
position: MapLegendPosition.bottom,
iconType: MapIconType.diamond,
),
dataLabelSettings: const MapDataLabelSettings(
overflowMode: MapLabelOverflow.ellipsis,
),
tooltipSettings: MapTooltipSettings(
color:
_isLightTheme
? const Color.fromRGBO(45, 45, 45, 1)
: const Color.fromRGBO(242, 242, 242, 1),
),
shapeTooltipBuilder: (BuildContext context, int index) {
final Color textColor =
_isLightTheme
? const Color.fromRGBO(255, 255, 255, 1)
: const Color.fromRGBO(10, 10, 10, 1);
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(
10.0,
7.0,
10.0,
8.5,
),
child: IntrinsicWidth(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_stateDataLabelsLocale[index],
textDirection: TextDirection.ltr,
style: _themeData.textTheme.bodySmall!
.copyWith(color: textColor),
),
const SizedBox(height: 5.0),
Text(
_australiaData[index].areaInMillionSqKm
.toString() +
'M sq. km',
textDirection: TextDirection.ltr,
style: _themeData.textTheme.bodySmall!
.copyWith(color: textColor),
),
],
),
),
),
],
);
},
),
],
),
),
),
],
),
),
);
}
void _updateLabelsBasedOnLocale() {
if (model.locale == const Locale('en', 'US')) {
_stateDataLabelsLocale = const <String>[
'New South Wales',
'Queensland',
'Northern Territory',
'Victoria',
'South Australia',
'Western Australia',
'Tasmania',
'Australian Capital Territory',
];
_title = 'Australia - Land Area (sq. Km)';
}
//Arabic.
else if (model.locale == const Locale('ar', 'AE')) {
_stateDataLabelsLocale = const <String>[
'نيو ساوث ويلز',
'كوينزلاند',
'الإقليم الشمالي',
'فيكتوريا',
'جنوب استراليا',
'القسم الغربي من استراليا',
'تسمانيا',
'إقليم العاصمة الأسترالية',
];
_title = '(كيلومتر مربع) - مساحة الأرض أستراليا';
}
//French.
else if (model.locale == const Locale('fr', 'FR')) {
_stateDataLabelsLocale = const <String>[
'Nouvelle Galles du Sud',
'Queensland',
'Territoire du Nord',
'Victoria',
'Le sud de lAustralie',
'Australie occidentale',
'Tasmanie',
'Territoire de la capitale australienne',
];
_title = 'Australie - Superficie terrestre (km²)';
}
//Chinese.
else if (model.locale == const Locale('zh', 'CN')) {
_stateDataLabelsLocale = const <String>[
'新南威尔士州',
'昆士兰',
'北方领土',
'维多利亚',
'南澳大利亚',
'澳大利亚西部',
'塔斯马尼亚',
'澳大利亚首都领地',
];
_title = '澳大利亚 - 土地面积(平方公里)';
}
//Spanish.
else {
_stateDataLabelsLocale = const <String>[
'Nueva Gales del Sur',
'Queensland',
'Territorio del Norte',
'Victoria',
'Sur de Australia',
'El oeste de Australia',
'Tasmania',
'Territorio de la Capital Australiana',
];
_title = 'Australia - Superficie terrestre (kilómetros cuadrados)';
}
}
}
class _Model {
const _Model(this.areaInMillionSqKm, this.state);
final String state;
final double areaInMillionSqKm;
}