import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:huixiang/utils/location.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/store.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/item_title.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shared_preferences/shared_preferences.dart'; class QuickOrder extends StatefulWidget { @override State createState() { return _QuickOrder(); } } class _QuickOrder extends State { ApiService apiService; List storeList; BMFCoordinate latLng; BMFMapController _mapController; final TextEditingController editingController = TextEditingController(); @override void initState() { super.initState(); getLatLng(); startLocation(); } ///门店列表 queryStore(latitude, longitude, province, city, district, searchKey) async { BaseData> baseData = await apiService.queryStore({ // "city": city, // "district": district, // "province": province, "latitude": latitude, "longitude": longitude, "searchKey": searchKey }).catchError((error) { }); if (baseData != null && baseData.isSuccess) { storeList = baseData.data; } setState(() {}); } getLatLng() async { SharedPreferences.getInstance().then( (value) => { apiService = ApiService(Dio(), context: context, token: value.getString('token'), showLoading: false), if (value.containsKey("latitude") && value.containsKey("longitude") && value.containsKey("province") && value.containsKey("city") && value.containsKey("district")) { latLng = BMFCoordinate(double.tryParse(value.getString("latitude")), double.tryParse(value.getString("longitude"))), queryStore( value.getString("latitude"), value.getString("longitude"), value.getString("province"), value.getString("city"), value.getString("district"), editingController.text, ), setState(() { if (_mapController != null) { _mapController.updateMapOptions(BMFMapOptions( center: latLng, zoomLevel: 15, )); } }) } else { queryStore("", "", "", "", "", editingController.text), } }, ); } startLocation() async { Location.getInstance() .aMapFlutterLocation .onResultCallback() .listen((event) { if (event != null && event["latitude"] != null && event["longitude"] != null) { print("location: $event"); if (event["latitude"] is String && event["longitude"] is String) { latLng = BMFCoordinate(double.tryParse(event["latitude"]), double.tryParse(event["longitude"])); } else { latLng = BMFCoordinate(event["latitude"], event["longitude"]); } BMFCalculateUtils.coordConvert( coordinate: latLng, fromType: BMF_COORD_TYPE.BD09LL, toType: BMF_COORD_TYPE.COMMON) .then((value) { this.latLng = value; saveLatLng( value, event["province"], event["city"], event["district"]); print("union: Location result ${value.latitude} " "${value.longitude}"); Location.getInstance().stopLocation(); queryStore( "${value.latitude}", "${value.longitude}", event["province"], event["city"], event["district"], editingController.text); if (_mapController != null) _mapController.updateMapOptions(BMFMapOptions( center: value, zoomLevel: 15, )); }); } }); Location.getInstance().prepareLoc(); Location.getInstance().startLocation(context).then((value) { }); } saveLatLng(BMFCoordinate latLng, province, city, district) async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString("latitude", "${latLng.latitude}"); await prefs.setString("longitude", "${latLng.longitude}"); if (province != null) await prefs.setString("province", province); if (city != null) await prefs.setString("city", city); if (district != null) await prefs.setString("district", district); } @override Widget build(BuildContext context) { return Column( children: [ ItemTitle( text: "快捷下单", imgPath: "assets/image/icon_points_mall.png", ), Container( height: 170, margin: EdgeInsets.only(top: 10), child: ListView.builder( scrollDirection: Axis.horizontal, physics: BouncingScrollPhysics(), padding: EdgeInsets.symmetric(horizontal: 10), itemCount:storeList == null ? 0 : storeList.length, itemBuilder: (context, position) { return GestureDetector( onTap: () { Navigator.of(context).pushNamed( '/router/store_order', arguments: { "id": storeList[position].id, "tenant": storeList[position].tenantCode, "storeName": storeList[position].storeName }, ); }, child: storeItem(storeList[position],position), ); }, ), ), ], ); } Widget storeItem(Store store,position) { return Container( width: 160, height: 160, margin: EdgeInsets.symmetric( horizontal: 6.w, vertical: 3, ), decoration: BoxDecoration( borderRadius: BorderRadius.circular(4.w), boxShadow: [ BoxShadow( color: Color(0x08000000), offset: Offset(0, 3), blurRadius: 14, spreadRadius: 0, ), ], ), child: Stack( children: [ Positioned( top: 0, left: 0, right: 0, child: ClipRRect( child: MImage( store.facade, width: double.infinity, height: 95, fit: BoxFit.cover, errorSrc: "assets/image/default_1.png", fadeSrc: "assets/image/default_1.png", ), borderRadius: BorderRadius.vertical( top: Radius.circular(4), ), ), ), Positioned( bottom: 0, left: 0, right: 0, child: SvgPicture.asset( "assets/svg/kuaijiexiadan_bg.svg", width: double.infinity, height: 95, fit: BoxFit.fill, ), ), Positioned( bottom: 0, left: 0, right: 0, child: Container( height: 95, child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.center, children: [ MImage( store.logo, width: 32, height: 32, fit: BoxFit.cover, errorSrc: "assets/image/default_1.png", fadeSrc: "assets/image/default_1.png", ), Text( store.storeName, style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.medium, color: Colors.black, ), ), Text( store?.remark ??"", style: TextStyle( fontSize: 10.sp, fontWeight: MyFontWeight.medium, color: Color(0xFF868686), ), ), SizedBox( height: 5, ), ], ), ), ), ], ), ); } }