searchWeather method
todo 获取天气数据
Implementation
static Future<Weather> searchWeather(String city, {int mode = 0}) async {
// 会在listener中关闭
// ignore: close_sinks
final _controller = StreamController<Weather>(sync: true);
platform(
android: (pool) async {
// 创建请求对象
final query = await ObjectFactory_Android
.createcom_amap_api_services_weather_WeatherSearchQuery__String__int(
city,
mode,
);
// 获取android上下文
final context = await ObjectFactory_Android.getandroid_app_Activity();
// 创建搜索对象
_androidWeatherSearch = await ObjectFactory_Android
.createcom_amap_api_services_weather_WeatherSearch__android_content_Context(
context);
// 设置请求
await _androidWeatherSearch.setQuery(query);
// 设置回调
await _androidWeatherSearch
.setOnWeatherSearchListener(_AndroidSearchListener(_controller));
// 开始搜索
await _androidDistrictSearch.searchDistrictAsyn();
// 局部变量从HEAP中解除引用
pool..add(query);
ObjectFactory_Android.release(query);
},
ios: (pool) async {
_iosSearch = await ObjectFactory_iOS.createAMapSearchAPI();
// 设置回调
await _iosSearch.set_delegate(_IOSSearchListener(_controller));
// 创建搜索请求
final request =
await ObjectFactory_iOS.createAMapWeatherSearchRequest();
// 设置站点名称
await request.set_city(city);
await request.set_type(AMapWeatherType.values[mode]);
// 开始搜索
await _iosSearch.AMapWeatherSearch(request);
// 局部变量从HEAP中解除引用
pool..add(request);
},
);
return _controller.stream.first;
}