import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'package:ysairplane2/base/YSBase.dart'; import 'package:ysairplane2/tools/YSNetWorking.dart'; import 'package:ysairplane2/tools/YSTools.dart'; class YSChooseLocation extends StatefulWidget { final location; const YSChooseLocation({Key key, this.location}) : super(key: key); @override _YSChooseLocationState createState() => _YSChooseLocationState(); } class _YSChooseLocationState extends State { MethodChannel _platform; String _coordinate = '40,116'; @override Widget build(BuildContext context) { return YSBase( ystitle: '选择登机地址', yschild: Container( height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44, width: MediaQuery.of(context).size.width, color: Colors.white, child: Stack( children: [ platformView( platforms: (value){ value.setMethodCallHandler((call) { if(call.method == "search"){ List array = call.arguments; _showAlert(array); }else if(call.method == "coordinate"){ _coordinate = call.arguments; if(widget.location!=null){ print(widget.location); Map item = {'lat':widget.location['lat'],'lng':widget.location['lng'] ,'title':widget.location['title'],'content':widget.location['content'],'type':0}; _platform.invokeMethod('setLocation', item); _coordinate = '${item['lat']},${item['lng']}'; } } return; }); _platform = value; } ), Container( height: hsp(100), width: MediaQuery.of(context).size.width-hsp(80), margin: EdgeInsets.only(top: hsp(50),left: hsp(40)), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(5)) ), padding: EdgeInsets.only(left: hsp(10),right: hsp(10)), child: CupertinoTextField( placeholder: '请输入你要登机的地点', style: TextStyle(fontSize: zsp(30),color: Color(0xFF666666)), decoration: BoxDecoration(), textInputAction: TextInputAction.search, onSubmitted: (value){ if(value.length>0){ _searchLocation(value); } }, ), ) ], ), ) ); } _showAlert(List array){ showModalBottomSheet( context: context, backgroundColor: Colors.transparent, isScrollControlled: true, builder: (context){ return Container( height: MediaQuery.of(context).size.height*0.5, width: MediaQuery.of(context).size.width, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)) ), child: Column( children: [ Container( height: 39.7, child: Text('选择地址',style: TextStyle(fontSize: zsp(32),color: Colors.black,fontWeight: FontWeight.bold),), alignment: Alignment.center, ), Divider(height: 0.3,thickness: 0.3,color: Colors.grey,), Container( height: MediaQuery.of(context).size.height*0.5-40, child: ListView.separated( itemBuilder: (context,index){ return GestureDetector( onTap: (){ Navigator.pop(context); Navigator.of(context).pop({'lat': array[index]['lat'],'lng': array[index]['lng'],'title': array[index]['title'],'content': array[index]['content'],'airplaneName':array[index]['title']}); }, behavior: HitTestBehavior.opaque, child: Container( padding: EdgeInsets.only(left: 15,right: 15,bottom: 5,top: 5), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( child: Text('${array[index]['title']}',style: TextStyle(fontSize: zsp(30),color: Colors.black,fontWeight: FontWeight.bold),), margin: EdgeInsets.only(bottom: 5), ), Text('${array[index]['content']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF999999)),), ], ), ), ); }, separatorBuilder: (context,index){ return Divider(height: 0.3,thickness: 0.3,color: Colors.grey,); }, itemCount: array.length, ), ) ], ), ); } ); } _searchLocation(String searchStr) async{ FocusScope.of(context).unfocus(); Map httpHeaders = { 'Accept': 'application/json,*/*', 'Content-Type': 'application/json', }; Response response = await Dio().get('https://apis.map.qq.com/ws/place/v1/search?keyword=$searchStr&boundary=nearby($_coordinate,10000)&' 'key=OOZBZ-NHIWS-OCAOO-6VB3W-ROSBH-ZYB7Z',queryParameters: Map.from({}),options: Options(receiveTimeout: outTime,headers: httpHeaders)); Map dict = response.data; print('==========object'); if(dict['status']==0){ print(dict['data']); List array = dict['data']; List dataArray = []; int count = array.length>20?20:array.length; for(int i = 0;i