/
main.dart
103 lines (98 loc) · 3.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
import 'package:flutter/material.dart';
import 'package:flutter_2d_amap/flutter_2d_amap.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Flutter2dAMap.setApiKey("b6e0d9e494ff157ee3097dd5c53eec2d").then((value){
runApp(MyApp());
});
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<PoiSearch> _list = [];
int _index = 0;
ScrollController _controller = new ScrollController();
AMap2DController _aMap2DController;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('flutter_2d_amap'),
),
body: SafeArea(
child: Column(
children: <Widget>[
Expanded(
flex: 9,
child: AMap2DView(
webKey: '4e479545913a3a180b3cffc267dad646',
onPoiSearched: (result) {
if (result.isEmpty) {
print('无搜索结果返回');
return;
}
_controller.animateTo(0.0, duration: Duration(milliseconds: 10), curve: Curves.ease);
setState(() {
_index = 0;
_list = result;
});
},
onAMap2DViewCreated: (controller) {
_aMap2DController = controller;
},
),
),
Expanded(
flex: 11,
child: ListView.separated(
controller: _controller,
shrinkWrap: true,
itemCount: _list.length,
separatorBuilder: (_, index) {
return Divider(height: 0.6);
},
itemBuilder: (_, index) {
return InkWell(
onTap: () {
setState(() {
_index = index;
if (_aMap2DController != null) {
_aMap2DController.move(_list[index].latitude, _list[index].longitude);
}
});
},
child: Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.symmetric(horizontal: 16.0),
height: 50.0,
child: Row(
children: <Widget>[
Expanded(
child: Text(
_list[index].provinceName + " " +
_list[index].cityName + " " +
_list[index].adName + " " +
_list[index].title,
),
),
Opacity(
opacity: _index == index ? 1 : 0,
child: Icon(Icons.done, color: Colors.blue)
)
],
),
),
);
}
),
)
],
),
),
),
);
}
}