地址模块完成

hmxc
章文轩 3 years ago
parent 7539d545a7
commit 53b08b0ce3

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

@ -319,6 +319,18 @@ class R {
static const String ASSETS_ICONS_HOUSE_KEEPING_PNG = static const String ASSETS_ICONS_HOUSE_KEEPING_PNG =
'assets/icons/house_keeping.png'; 'assets/icons/house_keeping.png';
/// ![preview](file:///Users/datang/aku_community/assets/icons/icon_address_edit.png)
static const String ASSETS_ICONS_ICON_ADDRESS_EDIT_PNG =
'assets/icons/icon_address_edit.png';
/// ![preview](file:///Users/datang/aku_community/assets/icons/icon_address_isdefault.png)
static const String ASSETS_ICONS_ICON_ADDRESS_ISDEFAULT_PNG =
'assets/icons/icon_address_isdefault.png';
/// ![preview](file:///Users/datang/aku_community/assets/icons/icon_address_not.png)
static const String ASSETS_ICONS_ICON_ADDRESS_NOT_PNG =
'assets/icons/icon_address_not.png';
/// ![preview](file:///Users/datang/aku_community/assets/icons/icon_change_list.png) /// ![preview](file:///Users/datang/aku_community/assets/icons/icon_change_list.png)
static const String ASSETS_ICONS_ICON_CHANGE_LIST_PNG = static const String ASSETS_ICONS_ICON_CHANGE_LIST_PNG =
'assets/icons/icon_change_list.png'; 'assets/icons/icon_change_list.png';
@ -817,6 +829,10 @@ class R {
static const String ASSETS_IMAGES_PROPERTY_BG_PNG = static const String ASSETS_IMAGES_PROPERTY_BG_PNG =
'assets/images/property_bg.png'; 'assets/images/property_bg.png';
/// ![preview](file:///Users/datang/aku_community/assets/images/shop_car_empty.png)
static const String ASSETS_IMAGES_SHOP_CAR_EMPTY_PNG =
'assets/images/shop_car_empty.png';
/// ![preview](file:///Users/datang/aku_community/assets/images/splash_logo.png) /// ![preview](file:///Users/datang/aku_community/assets/images/splash_logo.png)
static const String ASSETS_IMAGES_SPLASH_LOGO_PNG = static const String ASSETS_IMAGES_SPLASH_LOGO_PNG =
'assets/images/splash_logo.png'; 'assets/images/splash_logo.png';

@ -1,7 +1,15 @@
import 'package:hive/hive.dart';
part 'province_model.g.dart';
@HiveType(typeId: 0)
class ProvinceModel { class ProvinceModel {
@HiveField(0)
int? id; int? id;
@HiveField(1)
String? name; String? name;
@HiveField(2)
List<City>? cityList; List<City>? cityList;
ProvinceModel({this.id, this.name, this.cityList}); ProvinceModel({this.id, this.name, this.cityList});
@ -28,9 +36,13 @@ class ProvinceModel {
} }
} }
@HiveType(typeId: 1)
class City { class City {
@HiveField(0)
int? id; int? id;
@HiveField(1)
String? name; String? name;
@HiveField(2)
List<District>? districts; List<District>? districts;
City({this.id, this.name, this.districts}); City({this.id, this.name, this.districts});
@ -38,8 +50,8 @@ class City {
City.fromJson(Map<String, dynamic> json) { City.fromJson(Map<String, dynamic> json) {
id = json['id']; id = json['id'];
name = json['name']; name = json['name'];
if (json['districts'] != null) { if (json['cityList'] != null) {
districts = (json['districts'] as List).map((e) => District.fromJson(e)).toList(); districts = (json['cityList'] as List).map((e) => District.fromJson(e)).toList();
}else }else
districts = []; districts = [];
@ -56,8 +68,11 @@ class City {
} }
} }
@HiveType(typeId: 2)
class District { class District {
@HiveField(0)
int? id; int? id;
@HiveField(1)
String? name; String? name;
District({this.id, this.name}); District({this.id, this.name});

@ -0,0 +1,124 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'province_model.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class ProvinceModelAdapter extends TypeAdapter<ProvinceModel> {
@override
final int typeId = 0;
@override
ProvinceModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return ProvinceModel(
id: fields[0] as int?,
name: fields[1] as String?,
cityList: (fields[2] as List?)?.cast<City>(),
);
}
@override
void write(BinaryWriter writer, ProvinceModel obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.name)
..writeByte(2)
..write(obj.cityList);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ProvinceModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class CityAdapter extends TypeAdapter<City> {
@override
final int typeId = 1;
@override
City read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return City(
id: fields[0] as int?,
name: fields[1] as String?,
districts: (fields[2] as List?)?.cast<District>(),
);
}
@override
void write(BinaryWriter writer, City obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.name)
..writeByte(2)
..write(obj.districts);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CityAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class DistrictAdapter extends TypeAdapter<District> {
@override
final int typeId = 2;
@override
District read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return District(
id: fields[0] as int?,
name: fields[1] as String?,
);
}
@override
void write(BinaryWriter writer, District obj) {
writer
..writeByte(2)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.name);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is DistrictAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

@ -131,16 +131,25 @@ class AddressListPageState extends State<AddressListPage>
super.build(context); super.build(context);
return BeeScaffold( return BeeScaffold(
title: '我的收货地址', title: '我的收货地址',
bottomNavi: MaterialButton( bottomNavi: GestureDetector(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onTap: ()async{
textColor: Colors.white, bool? result = await Get.to(() => NewAddressPage(isFirstAdd: _addressModels.isEmpty? true:false,));
child: '新增收货地址'.text.size(28.sp).make(), if(result!=null){
onPressed: (){ if(result) _refreshController.callRefresh();
Get.to(() => NewAddressPage()); }
}, },
color: Color(0xFFE52E2E), child: Container(
height: 98.w, margin: EdgeInsets.only(left: 100.w,right: 100.w,bottom: 100.w),
minWidth: double.infinity, alignment: Alignment.center,
child: '新增收货地址'.text.size(28.sp).white.make(),
decoration: BoxDecoration(
borderRadius: BorderRadius.horizontal(left: Radius.circular(49.w),right: Radius.circular(49.w)),
color: Color(0xFFE52E2E),
),
width: 522.w,
height: 98.w,
),
), ),
body:EasyRefresh( body:EasyRefresh(
firstRefresh: true, firstRefresh: true,
@ -148,14 +157,15 @@ class AddressListPageState extends State<AddressListPage>
controller: _refreshController, controller: _refreshController,
onRefresh: () async { onRefresh: () async {
_addressModels = await Userfunc.getMyAddress(); _addressModels = await Userfunc.getMyAddress();
_onload =false;
setState(() {}); setState(() {});
}, },
child: _onload child: _onload
? SizedBox() ? SizedBox()
: ListView( : ListView(
padding: EdgeInsets.all(20.w),
children: [ children: [
..._addressModels.map((e) => MyAddressItem(addressModel: e,setDefaultListener:(){}, ..._addressModels.map((e) => MyAddressItem(addressModel: e,refreshController: _refreshController,
deleteListener:(){},editListener:(){}
)).toList(), )).toList(),
// //
// ..._newItems.map((e) => ChatCard( // ..._newItems.map((e) => ChatCard(

@ -6,10 +6,12 @@
* remark : * remark :
* ==================================================== * ====================================================
*/ */
import 'package:aku_community/model/user/ProvinceModel.dart'; import 'package:aku_community/base/base_style.dart';
import 'package:aku_community/model/user/province_model.dart';
import 'package:aku_community/utils/text_utils.dart'; import 'package:aku_community/utils/text_utils.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:aku_community/utils/headers.dart';
typedef AddressSelectorCallback = Function( typedef AddressSelectorCallback = Function(
String province, String city, String disctrict,int? locationId); String province, String city, String disctrict,int? locationId);
@ -44,7 +46,7 @@ class _AddressSelectorState extends State<AddressSelector>
late ProvinceModel _province; late ProvinceModel _province;
late City? _city; late City? _city;
late District? _district; late District? _district;
Color _selectedColor = Colors.white; Color _selectedColor = Colors.black;
late BuildContext _context; late BuildContext _context;
late bool _tab = true; late bool _tab = true;
@ -63,7 +65,7 @@ class _AddressSelectorState extends State<AddressSelector>
_context = context; _context = context;
return GestureDetector( return GestureDetector(
onTap: () {}, onTap: () {},
child: _buildBody(), child: _buildBody(context),
); );
} }
@ -74,31 +76,32 @@ class _AddressSelectorState extends State<AddressSelector>
super.dispose(); super.dispose();
} }
Container _buildBody() { Container _buildBody(BuildContext context) {
return Container( return Container(
height: 750.w, height: 1000.w,
padding: EdgeInsets.symmetric(horizontal: 15), padding: EdgeInsets.symmetric(horizontal: 15.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(10))), borderRadius: BorderRadius.vertical(top: Radius.circular(10.w))),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[_header(), _tabBar(), _list()], children: <Widget>[_header(), _tabBar(), 10.hb, _list()],
), ),
); );
} }
Container _header() { Container _header() {
return Container( return Container(
margin: EdgeInsets.symmetric(vertical: 10), margin: EdgeInsets.symmetric(vertical: 30.w),
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Spacer(),
Text( Text(
"配送至", "请选择所在地区",
style: TextStyle( style: TextStyle(
fontSize: 18 * 2.sp, fontSize: 32.sp,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: Colors.black), color:ktextPrimary),
), ),
Spacer(), Spacer(),
GestureDetector( GestureDetector(
@ -106,15 +109,15 @@ class _AddressSelectorState extends State<AddressSelector>
_dismiss(); _dismiss();
}, },
child: Container( child: Container(
padding: EdgeInsets.all(5), padding: EdgeInsets.all(5.w),
decoration:BoxDecoration( decoration:BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)), borderRadius: BorderRadius.all(Radius.circular(20.w)),
color: Colors.grey[200], color: Colors.white,
), ),
child: Icon( child: Icon(
Icons.delete, Icons.close,
color: Colors.grey[500], color: Colors.grey[500],
size: 12, size: 40.w,
), ),
), ),
) )
@ -126,12 +129,12 @@ class _AddressSelectorState extends State<AddressSelector>
TabBar _tabBar() { TabBar _tabBar() {
return TabBar( return TabBar(
controller: _tabController, controller: _tabController,
labelPadding: EdgeInsets.zero, labelPadding: EdgeInsets.only(top: 5.w),
unselectedLabelColor: Colors.black, unselectedLabelColor: Color(0xFFE52E2E),
isScrollable: true, isScrollable: true,
indicatorColor: _selectedColor, indicatorColor: Color(0xFFE52E2E),
indicatorSize: TabBarIndicatorSize.label, indicatorSize: TabBarIndicatorSize.label,
indicatorPadding: EdgeInsets.only(left: 0, right: 0), indicatorPadding: EdgeInsets.only(left: 10.w, right: 10.w,bottom: -5.w),
tabs: _tabItems()); tabs: _tabItems());
} }
@ -146,7 +149,7 @@ class _AddressSelectorState extends State<AddressSelector>
} }
list.add(Container( list.add(Container(
margin: EdgeInsets.symmetric(horizontal: 5.w), margin: EdgeInsets.symmetric(horizontal: 5.w),
height: 30.w, height: 40.w,
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
TextUtils.isEmpty(_result[i]) ? "请选择" : _result[i], TextUtils.isEmpty(_result[i]) ? "请选择" : _result[i],
@ -176,7 +179,8 @@ class _AddressSelectorState extends State<AddressSelector>
child: Container( child: Container(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
child: Container( child: Container(
padding: EdgeInsets.symmetric(vertical: 6), color: Colors.transparent,
padding: EdgeInsets.symmetric(vertical: 10.w),
child: Row(children: [ child: Row(children: [
Text( Text(
addr, addr,
@ -189,7 +193,8 @@ class _AddressSelectorState extends State<AddressSelector>
offstage: !selected, offstage: !selected,
child: Icon( child: Icon(
Icons.check, Icons.check,
size: 16 * 2.sp, color: Color(0xFFE52E2E),
size: 40.sp,
)) ))
]), ]),
), ),
@ -297,7 +302,7 @@ class _AddressSelectorState extends State<AddressSelector>
/// ///
if (city.districts!.length == 0) { if (city.districts!.length == 0) {
_dismiss(); _dismiss();
widget.callback(_province.name??'', _city?.name??'', '',_province.id??null); widget.callback(_province.name??'', _city?.name??'', '',_city?.id??null);
return; return;
} }
@ -317,7 +322,7 @@ class _AddressSelectorState extends State<AddressSelector>
_result[2] = _district?.name??''; _result[2] = _district?.name??'';
_indexs[2] = index; _indexs[2] = index;
_dismiss(); _dismiss();
widget.callback(_province.name??'', _city?.name??'', _district?.name??'',_province.id??null); widget.callback(_province.name??'', _city?.name??'', _district?.name??'',_district?.id??null);
} }
} }
} }

@ -65,7 +65,7 @@ class _EditTileState extends State<EditTile> {
}, },
child: Container( child: Container(
constraints: widget.constraints, constraints: widget.constraints,
padding: EdgeInsets.symmetric(vertical: 2, horizontal: 15), padding: EdgeInsets.symmetric(vertical: 2.w, horizontal: 20.w),
color: Colors.white, color: Colors.white,
child: child:
widget.direction == Axis.horizontal ? _horizontal() : _vertical(), widget.direction == Axis.horizontal ? _horizontal() : _vertical(),
@ -77,7 +77,7 @@ class _EditTileState extends State<EditTile> {
return Row( return Row(
children: <Widget>[ children: <Widget>[
Container( Container(
width: 80.w, width: 120.w,
child: Text( child: Text(
widget.title, widget.title,
style: widget.titleStyle, style: widget.titleStyle,
@ -85,6 +85,7 @@ class _EditTileState extends State<EditTile> {
), ),
Expanded( Expanded(
child: InputView( child: InputView(
padding: EdgeInsets.symmetric(horizontal: 0),
focusNode: _focusNode, focusNode: _focusNode,
controller: _controller, controller: _controller,
maxLength: widget.maxLength, maxLength: widget.maxLength,
@ -113,7 +114,7 @@ class _EditTileState extends State<EditTile> {
Expanded( Expanded(
child: InputView( child: InputView(
focusNode: _focusNode, focusNode: _focusNode,
padding: EdgeInsets.symmetric(horizontal: 3), padding: EdgeInsets.symmetric(horizontal: 0),
maxLines: widget.maxLines, maxLines: widget.maxLines,
maxLength: widget.maxLength, maxLength: widget.maxLength,
controller: _controller, controller: _controller,

@ -1,13 +1,14 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:ui'; import 'dart:ui';
import 'package:aku_community/base/base_style.dart';
import 'package:aku_community/model/user/ProvinceModel.dart';
import 'package:aku_community/model/user/adress_model.dart'; import 'package:aku_community/model/user/adress_model.dart';
import 'package:aku_community/model/user/province_model.dart';
import 'package:aku_community/pages/personal/user_func.dart'; import 'package:aku_community/pages/personal/user_func.dart';
import 'package:aku_community/utils/hive_store.dart'; import 'package:aku_community/utils/hive_store.dart';
import 'package:aku_community/utils/text_utils.dart'; import 'package:aku_community/utils/text_utils.dart';
import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:aku_community/widget/bee_scaffold.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -23,17 +24,21 @@ import 'editView.dart';
class NewAddressPage extends StatefulWidget { class NewAddressPage extends StatefulWidget {
final bool? isFirstAdd; final bool? isFirstAdd;
final AddressModel? addressModel; final AddressModel? addressModel;
NewAddressPage({Key? key, this.isFirstAdd, this.addressModel}) : super(key: key); final EasyRefreshController? refreshController;
NewAddressPage({Key? key, this.isFirstAdd, this.addressModel, this.refreshController})
: super(key: key);
@override @override
_NewAddressPageState createState() => _NewAddressPageState(); _NewAddressPageState createState() => _NewAddressPageState();
} }
class _NewAddressPageState extends State<NewAddressPage>{ class _NewAddressPageState extends State<NewAddressPage> {
EasyRefreshController _refreshController = EasyRefreshController(); EasyRefreshController _refreshController = EasyRefreshController();
late AddressModel _address = AddressModel.empty(); late AddressModel _address = AddressModel.empty();
late List<ProvinceModel> _cityJsonModels = []; late List<ProvinceModel> _cityJsonModels = [];
late StateSetter _addressStateSetter; late StateSetter _addressStateSetter;
bool isDefault = false;
@override @override
void initState() { void initState() {
@ -43,224 +48,306 @@ class _NewAddressPageState extends State<NewAddressPage>{
} }
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BeeScaffold(
return BeeScaffold( title:widget.addressModel==null? '新建收货地址':'修改收货地址',
title: '新建收货地址', body: _buildBody(context),
body:_buildBody(context),
); );
} }
_buildBody(BuildContext context) { _buildBody(BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
//FocusScope.of(context).requestFocus(new FocusNode()); //FocusScope.of(context).requestFocus(new FocusNode());
}, },
child: Container( child: ListView(
child:ListView( children: [
children: [ Container(
Container( clipBehavior: Clip.antiAlias,
height: 10, margin: EdgeInsets.all(20.w),
), padding: EdgeInsets.only(top: 10.w),
EditTile( decoration: BoxDecoration(
constraints: BoxConstraints.tight(Size(double.infinity, 45)), color: Colors.white,
title: "收货人", borderRadius: BorderRadius.all(Radius.circular(24.w)),
value: _address.name??'',
hint: "请填写收货人姓名",
textChanged: (value) {
_address.name = value;
},
),
Container(
height: 3,
), ),
EditTile( child: Column(
constraints: BoxConstraints.tight(Size(double.infinity, 45)), children: [
title: "手机号码", EditTile(
value: _address.tel??'', constraints: BoxConstraints.tight(Size(double.infinity, 45)),
hint: "请填写收货人手机号码", title: "收货人",
maxLength: 11, titleStyle: TextStyle(fontSize: 28.sp, color: ktextPrimary),
textChanged: (value) { hintStyle: TextStyle(fontSize: 28.sp, color: Color(0xFFBBBBBB)),
_address.tel = value; textStyle: TextStyle(fontSize: 28.sp, color: ktextSubColor),
}, value: _address.name ?? '',
hint: "请填写收货人姓名",
textChanged: (value) {
_address.name = value;
},
),
Container(
height: 2.w,
color: Color(0xFFD9D9D9),
margin: EdgeInsets.symmetric(horizontal: 24.w)),
EditTile(
constraints: BoxConstraints.tight(Size(double.infinity, 100.w)),
title: "手机号码",
titleStyle: TextStyle(fontSize: 28.sp, color: ktextPrimary),
hintStyle: TextStyle(fontSize: 28.sp, color: Color(0xFFBBBBBB)),
textStyle: TextStyle(fontSize: 28.sp, color: ktextSubColor),
value: _address.tel ?? '',
hint: "请填写收货人手机号码",
maxLength: 11,
textChanged: (value) {
_address.tel = value;
},
),
Container(
height: 2.w,
color: Color(0xFFD9D9D9),
margin: EdgeInsets.symmetric(horizontal: 24.w)),
_addressView(),
Container(
height: 2.w,
color: Color(0xFFD9D9D9),
margin: EdgeInsets.symmetric(horizontal: 24.w)),
Container(
height: 20.w,
),
EditTile(
title: "详细地址",
hint: "街道门牌号等",
titleStyle: TextStyle(fontSize: 28.sp, color: ktextPrimary),
hintStyle: TextStyle(fontSize: 28.sp, color: Color(0xFFBBBBBB)),
textStyle: TextStyle(fontSize: 28.sp, color: ktextSubColor),
value: _address.addressDetail ?? '',
maxLength: 100,
maxLines: 3,
direction: Axis.vertical,
constraints: BoxConstraints(maxHeight: 100),
textChanged: (value) {
_address.addressDetail = value;
},
),
Container(
height: 2.w,
color: Color(0xFFD9D9D9),
margin: EdgeInsets.symmetric(horizontal: 24.w)),
Container(
height: 30.w,
),
],
), ),
Container( ),
height: 3, _defaultAddressTile(),
), // _defaultAddressTile(),
_addressView(), Container(
Container( height: 100,
height: 3, ),
), _saveButton(context)
EditTile( ],
title: "详细地址",
hint: "街道门牌号等",
value: _address.addressDetail??'',
maxLength: 100,
maxLines: 3,
direction: Axis.vertical,
constraints: BoxConstraints(maxHeight: 100),
textChanged: (value) {
_address.addressDetail = value;
},
),
Container(
height: 30,
),
// _defaultAddressTile(),
Container(
height: 100,
),
_saveButton(context)
],
)
), ),
); );
} }
Container _saveButton(BuildContext context) { Container _saveButton(BuildContext context) {
return Container( return Container(
margin: EdgeInsets.symmetric(horizontal: 15), margin: EdgeInsets.symmetric(horizontal: 100.w),
child: GestureDetector(
onTap: (){
_saveAddress(context);
child: GestureDetector(
onTap: () {
_saveAddress(context);
}, },
child: Container( child: Container(
alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.red, color: Colors.red,
borderRadius: BorderRadius.all(Radius.circular(8.w)), borderRadius: BorderRadius.horizontal(
left: Radius.circular(40.w), right: Radius.circular(40.w)),
), ),
height: 45.w, height: 80.w,
padding: EdgeInsets.symmetric(vertical: 8.w), padding: EdgeInsets.symmetric(vertical: 8.w),
child: Text( child: Text(
"保存地址",style: TextStyle( "保存并使用",
color: Colors.white, style: TextStyle(
fontSize: 17 * 2.sp, color: Colors.white,
), fontSize:28.sp,
),
), ),
), ),
), ),
); );
} }
_addressView() { _addressView() {
return StatefulBuilder( return StatefulBuilder(
builder: (BuildContext context, StateSetter setSta) { builder: (BuildContext context, StateSetter setSta) {
_addressStateSetter = setSta; _addressStateSetter = setSta;
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
print('1'); print('1');
if (_cityJsonModels.isEmpty) { if (_cityJsonModels.isEmpty) {
print('2'); print('2');
getCityList().then((success) { getCityList().then((success) {
if (success) { if (success) {
_selectAddress(context); _selectAddress(context);
}
} }
); });
return; return;
} }
_selectAddress(context); _selectAddress(context);
}, },
child: Container( child: Container(
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 15), padding: EdgeInsets.symmetric(vertical: 30.w, horizontal: 24.w),
decoration: BoxDecoration( child: Row(
color: Colors.red, children: <Widget>[
border: Border( Container(
bottom: BorderSide(color: Colors.grey, width: 0.5))), width: 120.w,
child: Row( child: Text("所在地区",
children: <Widget>[ style: TextStyle(fontSize: 28.sp, color: ktextPrimary)),
Container( ),
width: 80.w, Expanded(
child: Text( child: Text(
"所在地区", TextUtils.isEmpty(_address.locationName ?? '')
style:TextStyle(fontSize: 15.sp,) ? "选择地址"
), : "${_address.locationName}",
), textAlign: TextAlign.end,
Expanded( style: TextStyle(fontSize: 28.sp, color: Color(0xFFBBBBBB)),
child: Text( )),
TextUtils.isEmpty(_address.locationName??'') Icon(
? "选择地址" Icons.navigate_next,
: "${_address.locationName} : ""}", size: 40.w,
textAlign: TextAlign.end, color: ktextThirdColor,
style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w500), )
)), ],
Icon(
Icons.navigate_next,
size: 16,
color: Colors.black,
)
],
),
), ),
); ),
}, );
},
); );
} }
/// ///
_selectAddress(BuildContext context) { _selectAddress(BuildContext context) {
AddressSelectorHelper.show(context, AddressSelectorHelper.show(context,
models: _cityJsonModels, models: _cityJsonModels,
province: _address.province, province: _address.province,
city: _address.city, city: _address.city,
district: _address.district, district: _address.district, callback:
callback: (String province, String city, String district,int? locationId) { (String province, String city, String district, int? locationId) {
_address.locationName= province+city+district; _address.province = province;
_address.id = locationId??null; _address.city = city;
_addressStateSetter(() {}); _address.district = district;
print("$province - $city -$district"); _address.locationName = province + city + district;
}); _address.location = locationId ?? null;
_addressStateSetter(() {});
print("$province - $city -$district");
});
} }
Future<bool> getCityList() async { Future<bool> getCityList() async {
_cityJsonModels = await HiveStore.appBox?.get('cityList')??[]; _cityJsonModels = await (HiveStore.appBox?.get('cityList') ?? [])
.cast<ProvinceModel>()
.toList();
return true; return true;
} }
/// ///
_saveAddress(BuildContext context) async { _saveAddress(BuildContext context) async {
if (TextUtils.isEmpty(_address.name??"")) { if (TextUtils.isEmpty(_address.name ?? "")) {
BotToast.showText(text: '收货人不能为空'); BotToast.showText(text: '收货人不能为空');
return; return;
} }
if (TextUtils.isEmpty(_address.tel??'') || if (TextUtils.isEmpty(_address.tel ?? '') ||
!TextUtils.verifyPhone(_address.tel)) { !TextUtils.verifyPhone(_address.tel)) {
BotToast.showText(text: '手机号格式不正确'); BotToast.showText(text: '手机号格式不正确');
return; return;
} }
if (TextUtils.isEmpty(_address.province??'')) { if (_address.location==null) {
BotToast.showText(text: '所在地区不能为空'); BotToast.showText(text: '所在地区不能为空');
return; return;
} }
if (TextUtils.isEmpty(_address.addressDetail??'')) { if (TextUtils.isEmpty(_address.addressDetail ?? '')) {
BotToast.showText(text: '详细地址不能为空'); BotToast.showText(text: '详细地址不能为空');
return; return;
} }
if (_address.id == null) {
if (_address.id != null) { Userfunc.insertAddress(
Userfunc.insertAddress( _address.name??'', _address.tel??'', _address.name ?? '',
_address.location??null, _address.addressDetail??'', _address.isDefault??null); _address.tel ?? '',
_address.location ?? null,
_address.addressDetail ?? '',
_address.isDefault ?? null);
} else { } else {
Userfunc.updateAddress(_address.id!, _address.name??'', _address.tel??'', Userfunc.updateAddress(
_address.location??null, _address.addressDetail??'', _address.isDefault??null); _address.id!,
_address.name ?? '',
_address.tel ?? '',
_address.location ?? null,
_address.addressDetail ?? '',
_address.isDefault ?? null);
} }
Navigator.maybePop<dynamic>(context, _address); //Navigator.maybePop<dynamic>(context, _address);
Get.back(result: true);
}
_defaultAddressTile() {
if (widget.isFirstAdd != null)
if(_address.isDefault ==1){
isDefault = true;
}else{
isDefault = false;
widget.isFirstAdd! ? _address.isDefault = 1 : _address.isDefault = 0;
}
return Container(
clipBehavior: Clip.antiAlias,
margin: EdgeInsets.all(20.w),
padding: EdgeInsets.only(top: 24.w,bottom: 24.w,left: 24.w,right: 24.w),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(24.w)),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
'设置为默认地址'.text.size(28.sp).color(ktextPrimary).make(),
5.hb,
'提醒:每次下单灰默认推荐使用该地址'.text.size(24.sp).color(Color(0xFFBBBBBB)).make(),
],
),
Spacer(),
CupertinoSwitch(
value: isDefault,
onChanged: (value) {
if (value) {
isDefault = value;
_address.isDefault = 1;
print(1);
} else {
isDefault = value;
_address.isDefault = 0;
print(0);
}
setState(() {});
})
],
),
);
} }
} }

@ -9,102 +9,174 @@
import 'package:aku_community/base/base_style.dart'; import 'package:aku_community/base/base_style.dart';
import 'package:aku_community/model/user/adress_model.dart'; import 'package:aku_community/model/user/adress_model.dart';
import 'package:aku_community/pages/personal/user_func.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:aku_community/utils/headers.dart'; import 'package:aku_community/utils/headers.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'address/new_address_page.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class MyAddressItem extends StatelessWidget { class MyAddressItem extends StatefulWidget {
final AddressModel addressModel; final AddressModel addressModel;
final VoidCallback setDefaultListener; final EasyRefreshController? refreshController;
final VoidCallback deleteListener;
final VoidCallback editListener;
Color _titleColor = Colors.black; Color _titleColor = Colors.black;
MyAddressItem( MyAddressItem({required this.addressModel,
{required this.addressModel, this.refreshController})
required this.deleteListener,
required this.editListener,
required this.setDefaultListener})
: assert(addressModel != null); : assert(addressModel != null);
_MyAddressItemState createState() => _MyAddressItemState();
}
class _MyAddressItemState extends State<MyAddressItem> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
color: Colors.white, clipBehavior: Clip.antiAlias,
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( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Row( Row(
children: [ children: [
GestureDetector( GestureDetector(
onTap: (){ onTap: () async{
this.setDefaultListener; bool? result = await Userfunc.setIsDefaultAddress(widget.addressModel.id!);
if(result!=null){
if(result) widget.refreshController!.callRefresh();
}
}, },
child: Container( child: Container(
child: Image.asset(R.ASSETS_ICONS_ICON_MY_SETTING_PNG,width: 40.w,height: 40.w,), 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:
EdgeInsets.symmetric(horizontal: 20.w, vertical:6.w),
child: SizedBox(
width: 520.w,
child: Text(
widget.addressModel.locationName??'',
style:TextStyle(fontSize: 24.sp,color: ktextPrimary),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
Padding(
padding:
EdgeInsets.symmetric(horizontal: 20.w, vertical:6.w),
child: SizedBox(
width: 520.w,
child: Text(
( widget.addressModel.addressDetail??''),
style:TextStyle(fontSize: 32.sp,color: ktextPrimary),
maxLines: 1,
overflow: TextOverflow.ellipsis,
Padding( ),
padding:
EdgeInsets.symmetric(horizontal: 20.w, vertical:6.w),
child: Text(
addressModel.locationName??'',
style:TextStyle(fontSize: 24.sp,color: ktextPrimary)
),
),
Padding(
padding:
EdgeInsets.symmetric(horizontal: 20.w, vertical:6.w),
child: Text(
addressModel.addressDetail??'',
style:TextStyle(fontSize: 32.sp,color: ktextPrimary)
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
addressModel.name??'',
style: TextStyle(fontSize: 24.sp,color: ktextPrimary)
), ),
30.wb, ),
Text( Padding(
addressModel.tel??'', padding: EdgeInsets.symmetric(horizontal: 20.w, vertical:6.w),
style: TextStyle(fontSize: 24.sp,color: ktextPrimary) child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
widget.addressModel.name??'',
style: TextStyle(fontSize: 24.sp,color: ktextPrimary)
),
30.wb,
Text(
widget.addressModel.tel??'',
style: TextStyle(fontSize: 24.sp,color: ktextPrimary)
),
],
), ),
], ),
), ],
), ),
Spacer(),
GestureDetector( GestureDetector(
onTap: () async{
bool? result = await Get.to(() => NewAddressPage(isFirstAdd:false,addressModel: widget.addressModel,
));
if(result!=null){
if(result) widget.refreshController!.callRefresh();
}
},
child: Container( child: Container(
child: Image.asset(R.ASSETS_ICONS_ICON_MY_SETTING_PNG,width: 40.w,height: 40.w,), child: Image.asset(R.ASSETS_ICONS_ICON_ADDRESS_EDIT_PNG,width: 40.w,height: 40.w,),
), ),
) )
], ],
), ),
20.hb,
Container( Container(
height: 1, height: 1,
color: Colors.grey[200], color: Colors.grey[200],
), ),
20.hb,
Row( Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
10.wb,
Text( Text(
addressModel.isDefault == 0 ? "" : "默认地址", widget.addressModel.isDefault == 0 ? "" : "默认地址",
style: TextStyle(fontSize: 28.sp,color: ktextSubColor), style: TextStyle(fontSize: 28.sp,color: ktextSubColor),
), ),
Spacer(), Spacer(),
GestureDetector( GestureDetector(
onTap: (){ onTap: () async{
this.setDefaultListener; // bool? result = await Userfunc.deleteAddress(widget.addressModel.id!);
// if(result!=null){
// if(result) widget.refreshController!.callRefresh();
// }
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),
),
],
));
if (result == true) {
bool? result = await Userfunc.deleteAddress(widget.addressModel.id!);
if(result!=null){
if(result) widget.refreshController!.callRefresh();
}
};
}, },
child: Container( child: Container(
width: 70.w,
height: 40.w,
child:Text( child:Text(
"删除", "删除",
style: TextStyle(fontSize: 28.sp,color: ktextSubColor), style: TextStyle(fontSize: 28.sp,color: ktextSubColor),
@ -118,4 +190,5 @@ class MyAddressItem extends StatelessWidget {
), ),
); );
} }
} }

@ -11,6 +11,7 @@ import 'package:aku_community/models/market/order/goods_home_model.dart';
import 'package:aku_community/utils/network/base_list_model.dart'; import 'package:aku_community/utils/network/base_list_model.dart';
import 'package:aku_community/utils/network/base_model.dart'; import 'package:aku_community/utils/network/base_model.dart';
import 'package:aku_community/utils/network/net_util.dart'; import 'package:aku_community/utils/network/net_util.dart';
import 'package:bot_toast/bot_toast.dart';
class Userfunc { class Userfunc {
@ -30,47 +31,85 @@ class Userfunc {
/// ///
static Future<bool> insertAddress(String name,String tel,int? location, static Future<bool> insertAddress(String name,String tel,int? location,
String addressDetail,int? isDefault) async { String addressDetail,int? isDefault) async {
BaseModel model = await NetUtil().get( BaseModel model = await NetUtil().post(
API.user.insertAddress, API.user.insertAddress,
params: {'name':name,'tel':tel,'location':location, params: {'name':name,'tel':tel,'location':location,
'addressDetail':addressDetail,'isDefault':isDefault}, 'addressDetail':addressDetail,'isDefault':isDefault},
showMessage: true showMessage: false
); );
if (model.message! == "请求成功") if (model.status??false)
return true; {
else BotToast.showText(text: '添加成功');
return true;
}
else{
BotToast.showText(text: '添加失败');
return false; return false;
}
} }
/// ///
static Future<bool> updateAddress(int id,String name,String tel,int? location, static Future<bool> updateAddress(int id,String name,String tel,int? location,
String addressDetail,int? isDefault) async { String addressDetail,int? isDefault) async {
BaseModel model = await NetUtil().get( BaseModel model = await NetUtil().post(
API.user.updateAddress, API.user.updateAddress,
params: {'id': id,'name':name,'tel':tel,'location':location, params: {'id': id,'name':name,'tel':tel,'location':location,
'addressDetail':addressDetail,'isDefault':isDefault}, 'addressDetail':addressDetail,'isDefault':isDefault},
showMessage: true showMessage: false
); );
if (model.message! == "请求成功") if (model.status??false)
{
BotToast.showText(text: '修改成功');
return true; return true;
else }
else{
BotToast.showText(text: '修改失败');
return false; return false;
}
} }
/// ///
static Future<bool> deleteAddress(int addressId) async { static Future<bool> deleteAddress(int addressId) async {
BaseModel model = await NetUtil().get( BaseModel model = await NetUtil().post(
API.user.deleteAddress, API.user.deleteAddress,
params: {'addressId': addressId}, params: {'addressId': addressId},
showMessage: true showMessage: false
); );
if (model.message! == "请求成功") if (model.status??false)
{
BotToast.showText(text: '删除成功');
return true; return true;
else }
else{
BotToast.showText(text: '删除失败');
return false; return false;
}
} }
///
static Future<bool> setIsDefaultAddress(int addressId) async {
BaseModel model = await NetUtil().post(
API.user.settingDefaultAddress,
params: {'addressId': addressId},
showMessage: false
);
if (model.status??false)
{
BotToast.showText(text: '设置成功');
return true;
}
else{
BotToast.showText(text: '设置失败');
return false;
}
}

@ -2,8 +2,8 @@ import 'dart:io';
import 'package:aku_community/const/resource.dart'; import 'package:aku_community/const/resource.dart';
import 'package:aku_community/constants/api.dart'; import 'package:aku_community/constants/api.dart';
import 'package:aku_community/model/user/ProvinceModel.dart';
import 'package:aku_community/main_initialize.dart'; import 'package:aku_community/main_initialize.dart';
import 'package:aku_community/model/user/province_model.dart';
import 'package:aku_community/pages/setting_page/agreement_page/agreement_page.dart'; import 'package:aku_community/pages/setting_page/agreement_page/agreement_page.dart';
import 'package:aku_community/pages/setting_page/agreement_page/privacy_page.dart'; import 'package:aku_community/pages/setting_page/agreement_page/privacy_page.dart';
import 'package:aku_community/pages/tab_navigator.dart'; import 'package:aku_community/pages/tab_navigator.dart';
@ -115,23 +115,7 @@ class _SplashPageState extends State<SplashPage> {
context, context,
debug: DeveloperUtil.dev, debug: DeveloperUtil.dev,
); );
Future.delayed(Duration(milliseconds: 0), () async {
List<ProvinceModel> _province = [];
var agreement = await HiveStore.appBox?.get('cityList') ?? null;
if (agreement==null) {
///
BaseModel baseModel = await NetUtil().get(
API.user.findAllCityInfo,
);
if (baseModel.data!=null) {
_province = (baseModel.data as List)
.map((e) => ProvinceModel.fromJson(e))
.toList();
print(_province);
HiveStore.appBox!.put('cityList', _province);
}
}
});
Future.delayed(Duration(milliseconds: 0), () async { Future.delayed(Duration(milliseconds: 0), () async {
await _originOp(); await _originOp();

@ -1,8 +1,13 @@
import 'package:aku_community/const/resource.dart'; import 'package:aku_community/const/resource.dart';
import 'package:aku_community/constants/api.dart';
import 'package:aku_community/model/user/province_model.dart';
import 'package:aku_community/pages/property/property_page.dart'; import 'package:aku_community/pages/property/property_page.dart';
import 'package:aku_community/pages/sign/sign_in_page.dart'; import 'package:aku_community/pages/sign/sign_in_page.dart';
import 'package:aku_community/ui/community/community_views/community_page.dart'; import 'package:aku_community/ui/community/community_views/community_page.dart';
import 'package:aku_community/ui/market/market_page.dart'; import 'package:aku_community/ui/market/market_page.dart';
import 'package:aku_community/utils/hive_store.dart';
import 'package:aku_community/utils/network/base_model.dart';
import 'package:aku_community/utils/network/net_util.dart';
import 'package:aku_community/utils/websocket/web_socket_util.dart'; import 'package:aku_community/utils/websocket/web_socket_util.dart';
import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:aku_community/widget/bee_scaffold.dart';
import 'package:aku_community/widget/others/user_tool.dart'; import 'package:aku_community/widget/others/user_tool.dart';
@ -38,6 +43,22 @@ class _TabNavigatorState extends State<TabNavigator>
@override @override
void initState() { void initState() {
super.initState(); super.initState();
Future.delayed(Duration(milliseconds: 0), () async {
List<ProvinceModel> _province = [];
var agreement = await HiveStore.appBox?.get('cityList') ?? null;
if (agreement==null) {
///
BaseModel baseModel = await NetUtil().get(
API.user.findAllCityInfo,
);
if (baseModel.data!=null) {
_province = (baseModel.data as List)
.map((e) => ProvinceModel.fromJson(e))
.toList();
HiveStore.appBox!.put('cityList', _province);
}
}
});
_pages = [ _pages = [
HomePage(), HomePage(),
MarketPage(), MarketPage(),

@ -6,7 +6,6 @@ import 'package:aku_community/constants/config.dart';
import 'package:aku_community/model/common/real_time_weather_model.dart'; import 'package:aku_community/model/common/real_time_weather_model.dart';
import 'package:aku_community/model/community/hot_topic_model.dart'; import 'package:aku_community/model/community/hot_topic_model.dart';
import 'package:aku_community/model/message/message_center_model.dart'; import 'package:aku_community/model/message/message_center_model.dart';
import 'package:aku_community/model/user/ProvinceModel.dart';
import 'package:aku_community/model/user/car_parking_model.dart'; import 'package:aku_community/model/user/car_parking_model.dart';
import 'package:aku_community/models/user/passed_house_list_model.dart'; import 'package:aku_community/models/user/passed_house_list_model.dart';
import 'package:aku_community/utils/hive_store.dart'; import 'package:aku_community/utils/hive_store.dart';

@ -1,9 +1,22 @@
import 'package:aku_community/model/user/province_model.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
class HiveStore { class HiveStore {
static Box? _appBox; static Box? _appBox;
static Box? get appBox => _appBox; static Box? get appBox => _appBox;
static init() async { static Future init() async {
_appBox = await Hive.openBox('app'); if (!kIsWeb) {
var dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path);
Hive.registerAdapter(ProvinceModelAdapter());
Hive.registerAdapter(CityAdapter());
Hive.registerAdapter(DistrictAdapter());
_appBox = await Hive.openBox('app');
}
} }
} }

@ -590,6 +590,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.0" version: "1.1.0"
hive_generator:
dependency: "direct dev"
description:
name: hive_generator
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.1"
http: http:
dependency: transitive dependency: transitive
description: description:
@ -1087,6 +1094,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.3" version: "1.0.3"
source_helper:
dependency: transitive
description:
name: source_helper
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
source_span: source_span:
dependency: transitive dependency: transitive
description: description:

@ -119,6 +119,7 @@ dev_dependencies:
sdk: flutter sdk: flutter
#导入包整理 #导入包整理
import_sorter: ^4.5.1 import_sorter: ^4.5.1
hive_generator: ^1.1.0
#脚本工具 #脚本工具
grinder: ^0.9.0 grinder: ^0.9.0
flutter_native_splash: ^1.1.8+4 flutter_native_splash: ^1.1.8+4

Loading…
Cancel
Save