gxcm_amap_search 0.0.1
gxcm_amap_search: ^0.0.1 copied to clipboard
高德官方没有提供search相关的Flutter插件,本插件针对高德地图搜索功能官方原生插件进行封装
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:gxcm_amap_search/PoiResultItem.dart';
import 'package:gxcm_amap_search/gxcm_amap_search.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final textEditingController = TextEditingController();
List<PoiResultItem> dataList = [];
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: [
TextButton.icon(
onPressed: () {
GxcmAmapSearch.setApiKey('f53141bcada3bd03fd79c37f652cd45f', 'df6898859be82405b9b41d8d1f1e86d3');
GxcmAmapSearch.updatePrivacyAgree(true);
GxcmAmapSearch.updatePrivacyShow(true, true);
},
icon: const Icon(Icons.login),
label: const Text('注册id')),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextField(
controller: textEditingController,
),
),
TextButton.icon(
onPressed: () async {
dataList = await GxcmAmapSearch.searchKeyword(
keyword: textEditingController.text,
city: "广州市",
);
setState(() {});
},
icon: const Icon(Icons.search),
label: const Text('搜索')),
],
),
),
TextButton.icon(
onPressed: () async {
dataList = await GxcmAmapSearch.searchAround(
latitude: 23.110081, longitude: 113.401344,
keyword: textEditingController.text);
setState(() {});
},
icon: const Icon(Icons.search),
label: const Text('搜索')),
Expanded(
child: ListView.builder(
itemBuilder: (context, index) {
return ListTile(
title: Text(dataList[index].title ?? ''),
subtitle: Text(dataList[index].provinceName ?? ''),
trailing: Text(dataList[index].cityName ?? ''),
);
},
itemCount: dataList.length,
),
),
],
),
),
);
}
}