fetchInputTips method
输入内容自动提示
输入关键字keyword
, 并且限制所在城市city
Implementation
static Future<List<InputTip>> fetchInputTips(
String keyword, {
String city = '',
}) async {
// 会在listener中关闭
// ignore: close_sinks
final _controller = StreamController<List<InputTip>>(sync: true);
platform(
android: (pool) async {
// 创建查询对象
final query = await ObjectFactory_Android
.createcom_amap_api_services_help_InputtipsQuery__String__String(
keyword, city);
// 限制在当前城市
await query.setCityLimit(true);
// 获取android上下文
final context = await ObjectFactory_Android.getandroid_app_Activity();
// 创建搜索对象
_androidInputTip = await ObjectFactory_Android
.createcom_amap_api_services_help_Inputtips__android_content_Context__com_amap_api_services_help_InputtipsQuery(
context, query);
// 设置回调
await _androidInputTip
.setInputtipsListener(_AndroidSearchListener(_controller));
// 开始搜索
await _androidInputTip.requestInputtipsAsyn();
// 局部变量从HEAP中解除引用
pool..add(query);
},
ios: (pool) async {
_iosSearch = await ObjectFactory_iOS.createAMapSearchAPI();
// 设置回调
await _iosSearch.set_delegate(_IOSSearchListener(_controller));
// 创建搜索请求
final request =
await ObjectFactory_iOS.createAMapInputTipsSearchRequest();
// 设置关键字
await request.set_keywords(keyword);
// 设置城市
await request.set_city(city);
// 开始搜索
await _iosSearch.AMapInputTipsSearch(request);
// 局部变量从HEAP中解除引用
pool..add(request);
},
);
return _controller.stream.first;
}