|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:huixiang/generated/l10n.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/address.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/store_info.dart';
|
|
|
|
import 'package:huixiang/utils/flutter_utils.dart';
|
|
|
|
import 'package:huixiang/utils/font_weight.dart';
|
|
|
|
import 'package:huixiang/utils/location.dart';
|
|
|
|
import 'package:huixiang/view_widget/round_button.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
|
|
|
|
class DistributionMode extends StatefulWidget {
|
|
|
|
final Function(
|
|
|
|
String addressId,
|
|
|
|
int isTake,
|
|
|
|
String memberCouponId,
|
|
|
|
int orderId,
|
|
|
|
String promotionId,
|
|
|
|
) queryOrderInfo;
|
|
|
|
final Function(int selectedBtn) queryAddress;
|
|
|
|
final Function(String addId) selectedNewAddress;
|
|
|
|
final StoreInfo storeInfo;
|
|
|
|
final Address address;
|
|
|
|
|
|
|
|
DistributionMode(this.queryOrderInfo, this.queryAddress, this.storeInfo,
|
|
|
|
this.address, this.selectedNewAddress);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _DistributionMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DistributionMode extends State<DistributionMode> {
|
|
|
|
List<String> addressBgs = [
|
|
|
|
"assets/svg/dingdan_ziqu.svg",
|
|
|
|
"assets/svg/dingdan_waimai.svg",
|
|
|
|
"assets/svg/dingdan_wuliu.svg",
|
|
|
|
];
|
|
|
|
|
|
|
|
BMFCoordinate myLatLng;
|
|
|
|
String distance = "0";
|
|
|
|
int selectedBtn = 0;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
startLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
///定位获取当前的位置
|
|
|
|
void 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) {
|
|
|
|
myLatLng = BMFCoordinate(double.tryParse(event["latitude"]),
|
|
|
|
double.tryParse(event["longitude"]));
|
|
|
|
} else {
|
|
|
|
myLatLng = BMFCoordinate(event["latitude"], event["longitude"]);
|
|
|
|
}
|
|
|
|
calculate();
|
|
|
|
Location.getInstance().stopLocation();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Location.getInstance().prepareLoc();
|
|
|
|
Location.getInstance().startLocation(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
calculate() async {
|
|
|
|
BMFCoordinate bmfCoordinate = BMFCoordinate(
|
|
|
|
double.tryParse(widget.storeInfo.latitude),
|
|
|
|
double.tryParse(widget.storeInfo.longitude),
|
|
|
|
);
|
|
|
|
distance = await AppUtils.calculateDistance(bmfCoordinate, myLatLng);
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
height: 165.h,
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
left: 16,
|
|
|
|
right: 16,
|
|
|
|
top: 10,
|
|
|
|
),
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Color(0x80FFFFFF),
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Color(0x0D000000),
|
|
|
|
offset: Offset(0, 3),
|
|
|
|
blurRadius: 14,
|
|
|
|
spreadRadius: 0,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
addressBgs[selectedBtn],
|
|
|
|
width: double.infinity,
|
|
|
|
height: double.infinity,
|
|
|
|
fit: BoxFit.fill,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
// height: 50.h,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: GestureDetector(
|
|
|
|
behavior: HitTestBehavior.opaque,
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
selectedBtn = 0;
|
|
|
|
widget.queryOrderInfo(
|
|
|
|
null, selectedBtn, null, 0, null);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: 50.h,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
S.of(context).daodianziqu,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
fontWeight: MyFontWeight.semi_bold,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
selectedBtn = 1;
|
|
|
|
widget.queryAddress(selectedBtn);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: 50.h,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
S.of(context).waimaipeisong,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
SmartDialog.showToast("该功能暂未开放!",
|
|
|
|
alignment: Alignment.center);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: 50.h,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
S.of(context).kuaidiwuliu,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
selectedBtn == 0
|
|
|
|
? Container(
|
|
|
|
width: double.infinity,
|
|
|
|
padding: EdgeInsets.only(left: 16, right: 16, top: 15),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.spaceEvenly,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
widget.storeInfo != null
|
|
|
|
? (widget.storeInfo.storeName ?? "")
|
|
|
|
: "",
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
fontWeight: MyFontWeight.semi_bold,
|
|
|
|
color: Color(0xFF4C4C4C),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 6,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
widget.storeInfo != null
|
|
|
|
? widget.storeInfo.address
|
|
|
|
: "",
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 2,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
color: Color(0xFF727272),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: 18,
|
|
|
|
),
|
|
|
|
Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
Image.asset(
|
|
|
|
"assets/image/map.png",
|
|
|
|
height: 61.h,
|
|
|
|
width: 61.w,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
RoundButton(
|
|
|
|
// width: 41.w,
|
|
|
|
height: 13,
|
|
|
|
text: distance.length > 3
|
|
|
|
? "${distance}km"
|
|
|
|
: "距离您${distance}km",
|
|
|
|
textColor: Color(0xFF34A262),
|
|
|
|
fontWeight: MyFontWeight.semi_bold,
|
|
|
|
radius: 7.5,
|
|
|
|
backgroup: Colors.white,
|
|
|
|
fontSize: 7.sp,
|
|
|
|
),
|
|
|
|
Image.asset(
|
|
|
|
"assets/image/landmark.png",
|
|
|
|
height: 24.h,
|
|
|
|
width: 24.w,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
'/router/manage_address_page',
|
|
|
|
arguments: {"isSelector": true}).then((value) {
|
|
|
|
widget.selectedNewAddress((value as Map)["id"]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
width: double.infinity,
|
|
|
|
padding: EdgeInsets.only(left: 16, right: 16, top: 15),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Image.asset(
|
|
|
|
"assets/image/icon_permission_location.png",
|
|
|
|
height: 24.h,
|
|
|
|
width: 24.w,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
widget?.address?.username ?? "",
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 15.sp,
|
|
|
|
fontWeight: MyFontWeight.medium,
|
|
|
|
color: Color(0xFF4C4C4C),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: 13,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
widget?.address?.phone ?? "",
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 2,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 15.sp,
|
|
|
|
fontWeight: MyFontWeight.medium,
|
|
|
|
color: Color(0xFF4C4C4C),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
'/router/manage_address_page',
|
|
|
|
arguments: {
|
|
|
|
"isSelector": true
|
|
|
|
}).then((value) {
|
|
|
|
widget.selectedNewAddress(
|
|
|
|
(value as Map)["id"]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding:EdgeInsets.symmetric(horizontal:15.w,vertical: 5.h),
|
|
|
|
child: Icon(
|
|
|
|
Icons.keyboard_arrow_right,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 4, left: 25),
|
|
|
|
child: Text(
|
|
|
|
(widget?.address?.city ?? "") +
|
|
|
|
(widget?.address?.area ?? "") +
|
|
|
|
(widget?.address?.address ?? ""),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 2,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
color: Color(0xFF727272),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|