Skip to content

Commit

Permalink
enhancement: 优化example
Browse files Browse the repository at this point in the history
  • Loading branch information
yohom committed Dec 17, 2018
1 parent 8efe2ce commit 0605e0b
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 88 deletions.
159 changes: 77 additions & 82 deletions example/lib/search/fetch_data/bound_poi_search.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,90 +29,85 @@ class _BoundPoiSearchScreenState extends State<BoundPoiSearchScreen> {
backgroundColor: Colors.black,
centerTitle: true,
),
body: ListView(
shrinkWrap: true,
children: <Widget>[
Form(
child: ListView(
padding: const EdgeInsets.all(8.0),
shrinkWrap: true,
physics: ClampingScrollPhysics(),
children: <Widget>[
TextFormField(
decoration: InputDecoration(
hintText: '输入中心',
border: OutlineInputBorder(),
),
enabled: false,
controller: _centerController,
validator: (value) {
if (value.isEmpty) {
return '请输入中心';
}
},
),
SPACE_NORMAL,
TextFormField(
decoration: InputDecoration(
hintText: '输入关键字',
border: OutlineInputBorder(),
),
controller: _keywordController,
validator: (value) {
if (value.isEmpty) {
return '请输入关键字';
}
},
),
SPACE_NORMAL,
TextFormField(
decoration: InputDecoration(
hintText: '输入半径/米',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
controller: _rangeController,
validator: (value) {
try {
int.parse(value);
} catch (e) {
return '请输入数字';
}
},
),
SPACE_NORMAL,
Button(
label: '开始搜索',
onPressed: (context) async {
if (!Form.of(context).validate()) {
return;
}
body: Form(
child: ListView(
padding: const EdgeInsets.all(8.0),
shrinkWrap: true,
physics: ClampingScrollPhysics(),
children: <Widget>[
TextFormField(
decoration: InputDecoration(
hintText: '输入中心',
border: OutlineInputBorder(),
),
enabled: false,
controller: _centerController,
validator: (value) {
if (value.isEmpty) {
return '请输入中心';
}
},
),
SPACE_NORMAL,
TextFormField(
decoration: InputDecoration(
hintText: '输入关键字',
border: OutlineInputBorder(),
),
controller: _keywordController,
validator: (value) {
if (value.isEmpty) {
return '请输入关键字';
}
},
),
SPACE_NORMAL,
TextFormField(
decoration: InputDecoration(
hintText: '输入半径/米',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
controller: _rangeController,
validator: (value) {
try {
int.parse(value);
} catch (e) {
return '请输入数字';
}
},
),
SPACE_NORMAL,
Button(
label: '开始搜索',
onPressed: (context) async {
if (!Form.of(context).validate()) {
return;
}

loading(
context,
AMapSearch().searchPoiBound(
PoiSearchQuery(
query: _keywordController.text,
location: LatLng(39.909604, 116.397228), // iOS必须
searchBound: SearchBound(
center: LatLng(39.909604, 116.397228),
range: int.parse(_rangeController.text),
), // Android必须
),
),
).then((poiResult) {
setState(() {
_result = poiResult.toString();
});
}).catchError((e) => showError(context, e.toString()));
},
),
SPACE_NORMAL,
Text(_result),
],
loading(
context,
AMapSearch().searchPoiBound(
PoiSearchQuery(
query: _keywordController.text,
location: LatLng(39.909604, 116.397228), // iOS必须
searchBound: SearchBound(
center: LatLng(39.909604, 116.397228),
range: int.parse(_rangeController.text),
), // Android必须
),
),
).then((poiResult) {
setState(() {
_result = jsonFormat(poiResult.toJson());
});
}).catchError((e) => showError(context, e.toString()));
},
),
),
],
SPACE_NORMAL,
ListView(children: <Widget>[Text(_result)]),
],
),
),
);
}
Expand Down
4 changes: 3 additions & 1 deletion example/lib/search/fetch_data/geocode.screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:amap_base/amap_base.dart';
import 'package:amap_base_example/utils/misc.dart';
import 'package:amap_base_example/utils/view.dart';
Expand Down Expand Up @@ -78,7 +80,7 @@ class _GeocodeScreenState extends State<GeocodeScreen> {
),
).then((result) {
setState(() {
_result = result.toString();
_result = jsonFormat(result.toJson());
});
}).catchError((e) => showError(context, e.toString()));
},
Expand Down
2 changes: 1 addition & 1 deletion example/lib/search/fetch_data/id_poi_search.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _IdPoiSearchScreenState extends State<IdPoiSearchScreen> {
AMapSearch().searchPoiId('B0FFJD44SX'),
).then((poiResult) {
setState(() {
_result = poiResult.toString();
_result = jsonFormat(poiResult.toJson());
});
}).catchError((e) => showError(context, e.toString()));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _KeywordPoiSearchScreenState extends State<KeywordPoiSearchScreen> {
),
).then((poiResult) {
setState(() {
_result = poiResult.toString();
_result = jsonFormat(poiResult.toJson());
});
}).catchError((e) => showError(context, e.toString()));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class _PolygonPoiSearchScreenState extends State<PolygonPoiSearchScreen> {
),
).then((poiResult) {
setState(() {
_result = poiResult.toString();
_result = jsonFormat(poiResult.toJson());
});
}).catchError((e) => showError(context, e.toString()));
},
Expand Down
2 changes: 1 addition & 1 deletion example/lib/search/fetch_data/route_poi_search.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _RoutePoiSearchScreenState extends State<RoutePoiSearchScreen> {
),
).then((routePoiResult) {
setState(() {
_result = routePoiResult.toString();
_result = jsonFormat(routePoiResult.toJson());
});
}).catchError((e) => showError(context, e.toString()));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DrivingRoutPlanScreenState extends State<DrivingRoutPlanScreen> {
),
).then((result) {
setState(() {
_result = result.toString();
_result = jsonFormat(result.toJson());
});
}).catchError((e) => showError(context, e.toString()));
},
Expand Down
7 changes: 7 additions & 0 deletions example/lib/utils/misc.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:amap_base/amap_base.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -34,3 +36,8 @@ Future<T> loading<T>(BuildContext context, Future<T> futureTask) {
}
});
}

String jsonFormat(Map<String, Object> json) {
JsonEncoder encoder = JsonEncoder.withIndent(' ');
return encoder.convert(json);
}

0 comments on commit 0605e0b

Please sign in to comment.