|
|
@ -21,7 +21,14 @@ import 'package:permission_handler/permission_handler.dart'; |
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import '../view_widget/no_data_view.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class StoreSelectorPage extends StatefulWidget { |
|
|
|
class StoreSelectorPage extends StatefulWidget { |
|
|
|
|
|
|
|
final Map<String, dynamic> arguments; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///兑换订单 |
|
|
|
|
|
|
|
StoreSelectorPage({this.arguments}); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
State<StatefulWidget> createState() { |
|
|
|
State<StatefulWidget> createState() { |
|
|
|
return _StoreSelectorPage(); |
|
|
|
return _StoreSelectorPage(); |
|
|
@ -30,194 +37,32 @@ class StoreSelectorPage extends StatefulWidget { |
|
|
|
|
|
|
|
|
|
|
|
class _StoreSelectorPage extends State<StoreSelectorPage> { |
|
|
|
class _StoreSelectorPage extends State<StoreSelectorPage> { |
|
|
|
ApiService apiService; |
|
|
|
ApiService apiService; |
|
|
|
|
|
|
|
List<Store> exchangeStoreList; |
|
|
|
LocationFlutterPlugin aMapFlutterLocation; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
void dispose() { |
|
|
|
|
|
|
|
super.dispose(); |
|
|
|
|
|
|
|
aMapFlutterLocation.stopLocation(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
super.initState(); |
|
|
|
|
|
|
|
exchangeShop(widget.arguments["creditGoodsId"]); |
|
|
|
SharedPreferences.getInstance().then((value) { |
|
|
|
|
|
|
|
apiService = |
|
|
|
|
|
|
|
ApiService(Dio(), |
|
|
|
|
|
|
|
showLoading: true, |
|
|
|
|
|
|
|
context: context, token: value.getString('token')); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (aMapFlutterLocation == null) { |
|
|
|
|
|
|
|
aMapFlutterLocation = LocationFlutterPlugin(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
aMapFlutterLocation.singleLocationCallback(callback: (BaiduLocation result) { |
|
|
|
|
|
|
|
if (result != null && |
|
|
|
|
|
|
|
result.latitude != null && |
|
|
|
|
|
|
|
result.longitude != null) { |
|
|
|
|
|
|
|
print("location: $result"); |
|
|
|
|
|
|
|
aMapFlutterLocation.stopLocation(); |
|
|
|
|
|
|
|
latLng = BMFCoordinate(result.latitude, result.longitude); |
|
|
|
|
|
|
|
BMFCalculateUtils.coordConvert( |
|
|
|
|
|
|
|
coordinate: latLng, |
|
|
|
|
|
|
|
fromType: BMF_COORD_TYPE.COMMON, |
|
|
|
|
|
|
|
toType: BMF_COORD_TYPE.BD09LL) |
|
|
|
|
|
|
|
.then((value) { |
|
|
|
|
|
|
|
this.latLng = value; |
|
|
|
|
|
|
|
saveLatLng( |
|
|
|
|
|
|
|
value, result.province, result.city, result.district); |
|
|
|
|
|
|
|
queryStore("${value.latitude}", "${value.longitude}", |
|
|
|
|
|
|
|
result.province, result.city, result.district); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
aMapFlutterLocation.prepareLoc({ |
|
|
|
|
|
|
|
"coorType": "bd09ll", |
|
|
|
|
|
|
|
"isNeedAddres": false, |
|
|
|
|
|
|
|
"isNeedAltitude": false, |
|
|
|
|
|
|
|
"isNeedLocationPoiList": false, |
|
|
|
|
|
|
|
"isNeedLocationDescribe": false, |
|
|
|
|
|
|
|
"isNeedNewVersionRgc": false, |
|
|
|
|
|
|
|
"scanspan": 0, |
|
|
|
|
|
|
|
"openGps": true, |
|
|
|
|
|
|
|
"locationMode": 2, |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
"locationMode": "kCLLocationAccuracyBest", |
|
|
|
|
|
|
|
"locationTimeout": 10, |
|
|
|
|
|
|
|
"reGeocodeTimeout": 10, |
|
|
|
|
|
|
|
"activityType": "CLActivityTypeAutomotiveNavigation", |
|
|
|
|
|
|
|
"BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", |
|
|
|
|
|
|
|
"isNeedNewVersionRgc": false, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startLocation(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saveLatLng(BMFCoordinate latLng, province, city, district) async { |
|
|
|
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance(); |
|
|
|
|
|
|
|
await prefs.setString("latitude", "${latLng.latitude}"); |
|
|
|
|
|
|
|
await prefs.setString("longitude", "${latLng.longitude}"); |
|
|
|
|
|
|
|
await prefs.setString("province", province ?? ""); |
|
|
|
|
|
|
|
await prefs.setString("city", city ?? ""); |
|
|
|
|
|
|
|
await prefs.setString("district", district ?? ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Store> storeList; |
|
|
|
|
|
|
|
BMFCoordinate latLng; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startLocation() async { |
|
|
|
|
|
|
|
if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { |
|
|
|
|
|
|
|
enableLocation(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (await Permission.location.isPermanentlyDenied) { |
|
|
|
|
|
|
|
requestDialog(); |
|
|
|
|
|
|
|
} else if (await Permission.location.isGranted) { |
|
|
|
|
|
|
|
EasyLoading.show(status: S.of(context).zhengzaijiazai); |
|
|
|
|
|
|
|
aMapFlutterLocation.startLocation(); |
|
|
|
|
|
|
|
Future.delayed(Duration(seconds: 6), () { |
|
|
|
|
|
|
|
EasyLoading.dismiss(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else if (await Permission.location.isUndetermined) { |
|
|
|
|
|
|
|
await Permission.location.request(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (Platform.isIOS) { |
|
|
|
|
|
|
|
//去设置中心 |
|
|
|
|
|
|
|
requestDialog(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await Permission.location.request(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enableLocation() { |
|
|
|
|
|
|
|
showCupertinoDialog( |
|
|
|
|
|
|
|
context: context, |
|
|
|
|
|
|
|
builder: (context) { |
|
|
|
|
|
|
|
return RequestPermission( |
|
|
|
|
|
|
|
"assets/image/icon_permission_location_bg.webp", |
|
|
|
|
|
|
|
S.of(context).nindingweigongnengweikaiqi, |
|
|
|
|
|
|
|
S.of(context).weilexiangnintuijianfujindemendianxinxi, |
|
|
|
|
|
|
|
S.of(context).dakaidingwei, |
|
|
|
|
|
|
|
(result) async { |
|
|
|
|
|
|
|
if (result) { |
|
|
|
|
|
|
|
final AndroidIntent intent = AndroidIntent( |
|
|
|
|
|
|
|
action: 'action_location_source_settings', |
|
|
|
|
|
|
|
package: "com.zsw.huixiang"); |
|
|
|
|
|
|
|
await intent.launch(); |
|
|
|
|
|
|
|
// startLocation(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
heightRatioWithWidth: 0.82, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
requestDialog() { |
|
|
|
///兑换门店列表 |
|
|
|
showCupertinoDialog( |
|
|
|
exchangeShop(creditGoodsId) async { |
|
|
|
|
|
|
|
if (apiService == null) { |
|
|
|
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
|
|
|
|
apiService = ApiService( |
|
|
|
|
|
|
|
Dio(), |
|
|
|
context: context, |
|
|
|
context: context, |
|
|
|
builder: (context) { |
|
|
|
showLoading: true, |
|
|
|
return RequestPermission( |
|
|
|
token: value.getString("token"), |
|
|
|
"assets/image/icon_permission_location_bg.webp", |
|
|
|
|
|
|
|
S.of(context).nindingweiquanxianweiyunxu, |
|
|
|
|
|
|
|
S.of(context).weilexiangnintuijianfujindemendianxinxi, |
|
|
|
|
|
|
|
S.of(context).kaiqiquanxian, |
|
|
|
|
|
|
|
(result) async { |
|
|
|
|
|
|
|
if (result) { |
|
|
|
|
|
|
|
await openAppSettings(); |
|
|
|
|
|
|
|
if (await Permission.location.isGranted) { |
|
|
|
|
|
|
|
startLocation(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
heightRatioWithWidth: 0.82, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getLatLng() async { |
|
|
|
|
|
|
|
SharedPreferences.getInstance().then( |
|
|
|
|
|
|
|
(value) => { |
|
|
|
|
|
|
|
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"), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
queryStore("", "", "", "", ""), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
BaseData<List<Store>> baseData = await apiService |
|
|
|
queryStore(latitude, longitude, province, city, district) async { |
|
|
|
.storeListByCreditId(creditGoodsId) |
|
|
|
BaseData<List<Store>> baseData = await apiService.queryStore({ |
|
|
|
.catchError((error) {}); |
|
|
|
"city": "", |
|
|
|
|
|
|
|
"district": "", |
|
|
|
|
|
|
|
"latitude": latitude, |
|
|
|
|
|
|
|
"longitude": longitude, |
|
|
|
|
|
|
|
"province": "", |
|
|
|
|
|
|
|
"searchKey": "" |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
|
|
storeList = baseData.data; |
|
|
|
setState((){ |
|
|
|
if (mounted) setState(() {}); |
|
|
|
exchangeStoreList = baseData.data; |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -236,8 +81,16 @@ class _StoreSelectorPage extends State<StoreSelectorPage> { |
|
|
|
child: Column( |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
Expanded( |
|
|
|
child: ListView.builder( |
|
|
|
child: (exchangeStoreList == null || exchangeStoreList.length == 0) |
|
|
|
itemCount: storeList != null ? storeList.length : 0, |
|
|
|
? NoDataView( |
|
|
|
|
|
|
|
src: "assets/image/xiao_fei.webp", |
|
|
|
|
|
|
|
isShowBtn: false, |
|
|
|
|
|
|
|
text: "当前暂无自提门店可选择", |
|
|
|
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
|
|
|
margin: EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
: ListView.builder( |
|
|
|
|
|
|
|
itemCount: exchangeStoreList != null ? exchangeStoreList.length : 0, |
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
itemBuilder: (context, position) { |
|
|
|
itemBuilder: (context, position) { |
|
|
|
return GestureDetector( |
|
|
|
return GestureDetector( |
|
|
@ -246,7 +99,7 @@ class _StoreSelectorPage extends State<StoreSelectorPage> { |
|
|
|
groupValue = position; |
|
|
|
groupValue = position; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
child: buildStoreItem(storeList[position], position), |
|
|
|
child: buildStoreItem(exchangeStoreList[position], position), |
|
|
|
); |
|
|
|
); |
|
|
|
}), |
|
|
|
}), |
|
|
|
), |
|
|
|
), |
|
|
@ -257,7 +110,7 @@ class _StoreSelectorPage extends State<StoreSelectorPage> { |
|
|
|
alignment: Alignment.center); |
|
|
|
alignment: Alignment.center); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
Store store = storeList[groupValue]; |
|
|
|
Store store = exchangeStoreList[groupValue]; |
|
|
|
Navigator.of(context).pop({ |
|
|
|
Navigator.of(context).pop({ |
|
|
|
"id": store.id, |
|
|
|
"id": store.id, |
|
|
|
"address": store.address, |
|
|
|
"address": store.address, |
|
|
|