You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/pages/personal/item_my_address.dart

221 lines
8.1 KiB

/*
* ====================================================
* package :
* author : Created by nansi.
* time : 2019/6/24 4:05 PM
* remark :
* ====================================================
*/
3 years ago
import 'package:aku_new_community/base/base_style.dart';
import 'package:aku_new_community/model/user/adress_model.dart';
import 'package:aku_new_community/pages/personal/user_func.dart';
import 'package:aku_new_community/provider/app_provider.dart';
import 'package:aku_new_community/utils/headers.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
3 years ago
import 'package:provider/provider.dart';
import 'address/new_address_page.dart';
// ignore: must_be_immutable
class MyAddressItem extends StatefulWidget {
final AddressModel addressModel;
final EasyRefreshController? refreshController;
final bool canBack;
Color _titleColor = Colors.black;
3 years ago
MyAddressItem(
{required this.addressModel,
this.refreshController,
required this.canBack})
: assert(addressModel != null);
_MyAddressItemState createState() => _MyAddressItemState();
}
3 years ago
class _MyAddressItemState extends State<MyAddressItem> {
@override
Widget build(BuildContext context) {
3 years ago
final appProvider = Provider.of<AppProvider>(context);
return GestureDetector(
3 years ago
onTap: widget.canBack
? () {
Get.back(result: widget.addressModel);
}
: () {},
child: Container(
clipBehavior: Clip.antiAlias,
3 years ago
margin: EdgeInsets.only(bottom: 20.w),
padding:
EdgeInsets.only(top: 22.w, bottom: 24.w, left: 24.w, right: 20.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(24.w)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: [
GestureDetector(
3 years ago
onTap: () async {
bool? result = await Userfunc.setIsDefaultAddress(
widget.addressModel.id!);
if (result != null) {
if (result) {
3 years ago
await appProvider.getMyAddress();
widget.refreshController!.callRefresh();
}
}
},
child: Container(
3 years ago
child: widget.addressModel.isDefault == 1
? Image.asset(
R.ASSETS_ICONS_ICON_ADDRESS_ISDEFAULT_PNG,
width: 40.w,
height: 40.w,
)
: Image.asset(
R.ASSETS_ICONS_ICON_ADDRESS_NOT_PNG,
width: 40.w,
height: 40.w,
),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding:
3 years ago
EdgeInsets.symmetric(horizontal: 20.w, vertical: 6.w),
child: SizedBox(
width: 520.w,
child: Text(
3 years ago
widget.addressModel.locationName ?? '',
style:
TextStyle(fontSize: 24.sp, color: ktextPrimary),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
Padding(
padding:
3 years ago
EdgeInsets.symmetric(horizontal: 20.w, vertical: 6.w),
child: SizedBox(
width: 520.w,
child: Text(
3 years ago
(widget.addressModel.addressDetail ?? ''),
style:
TextStyle(fontSize: 32.sp, color: ktextPrimary),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
Padding(
3 years ago
padding:
EdgeInsets.symmetric(horizontal: 20.w, vertical: 6.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
3 years ago
Text(widget.addressModel.name ?? '',
style: TextStyle(
fontSize: 24.sp, color: ktextPrimary)),
30.wb,
3 years ago
Text(widget.addressModel.tel ?? '',
style: TextStyle(
fontSize: 24.sp, color: ktextPrimary)),
],
),
),
],
),
Spacer(),
GestureDetector(
3 years ago
onTap: () async {
bool? result = await Get.to(() => NewAddressPage(
isFirstAdd: false,
addressModel: widget.addressModel,
));
if (result != null) {
if (result) widget.refreshController!.callRefresh();
}
},
child: Container(
3 years ago
child: Image.asset(
R.ASSETS_ICONS_ICON_ADDRESS_EDIT_PNG,
width: 40.w,
height: 40.w,
),
),
)
],
),
20.hb,
Container(
height: 1,
color: Colors.grey[200],
),
20.hb,
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
10.wb,
Text(
widget.addressModel.isDefault == 0 ? "" : "默认地址",
3 years ago
style: TextStyle(fontSize: 28.sp, color: ktextSubColor),
),
Spacer(),
GestureDetector(
3 years ago
onTap: () async {
// bool? result = await Userfunc.deleteAddress(widget.addressModel.id!);
// if(result!=null){
// if(result) widget.refreshController!.callRefresh();
// }
3 years ago
bool? result = await Get.dialog(CupertinoAlertDialog(
title: '您确定要删除该地址吗?'.text.isIntrinsic.size(30.sp).make(),
actions: [
CupertinoDialogAction(
child: '取消'.text.black.isIntrinsic.make(),
onPressed: () => Get.back(),
),
CupertinoDialogAction(
child:
'确定'.text.color(Colors.orange).isIntrinsic.make(),
onPressed: () => Get.back(result: true),
),
],
));
3 years ago
if (result == true) {
bool? result =
await Userfunc.deleteAddress(widget.addressModel.id!);
if (result != null) {
if (result) widget.refreshController!.callRefresh();
}
}
;
},
child: Container(
width: 70.w,
height: 40.w,
3 years ago
child: Text(
"删除",
3 years ago
style: TextStyle(fontSize: 28.sp, color: ktextSubColor),
),
),
),
],
)
],
),
),
);
}
}