diff --git a/assets/icons/icon_address_edit.png b/assets/icons/icon_address_edit.png new file mode 100644 index 00000000..19cf4c98 Binary files /dev/null and b/assets/icons/icon_address_edit.png differ diff --git a/assets/icons/icon_address_isdefault.png b/assets/icons/icon_address_isdefault.png new file mode 100644 index 00000000..3382a10b Binary files /dev/null and b/assets/icons/icon_address_isdefault.png differ diff --git a/assets/icons/icon_address_not.png b/assets/icons/icon_address_not.png new file mode 100644 index 00000000..fb3d55b5 Binary files /dev/null and b/assets/icons/icon_address_not.png differ diff --git a/lib/const/resource.dart b/lib/const/resource.dart index 334a2c25..2858bedf 100644 --- a/lib/const/resource.dart +++ b/lib/const/resource.dart @@ -319,6 +319,18 @@ class R { static const String 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) static const String 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 = '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) static const String ASSETS_IMAGES_SPLASH_LOGO_PNG = 'assets/images/splash_logo.png'; diff --git a/lib/model/user/ProvinceModel.dart b/lib/model/user/province_model.dart similarity index 80% rename from lib/model/user/ProvinceModel.dart rename to lib/model/user/province_model.dart index c2445e78..70fb1e44 100644 --- a/lib/model/user/ProvinceModel.dart +++ b/lib/model/user/province_model.dart @@ -1,7 +1,15 @@ +import 'package:hive/hive.dart'; +part 'province_model.g.dart'; + +@HiveType(typeId: 0) class ProvinceModel { + + @HiveField(0) int? id; + @HiveField(1) String? name; + @HiveField(2) List? cityList; ProvinceModel({this.id, this.name, this.cityList}); @@ -28,9 +36,13 @@ class ProvinceModel { } } +@HiveType(typeId: 1) class City { + @HiveField(0) int? id; + @HiveField(1) String? name; + @HiveField(2) List? districts; City({this.id, this.name, this.districts}); @@ -38,8 +50,8 @@ class City { City.fromJson(Map json) { id = json['id']; name = json['name']; - if (json['districts'] != null) { - districts = (json['districts'] as List).map((e) => District.fromJson(e)).toList(); + if (json['cityList'] != null) { + districts = (json['cityList'] as List).map((e) => District.fromJson(e)).toList(); }else districts = []; @@ -56,8 +68,11 @@ class City { } } +@HiveType(typeId: 2) class District { + @HiveField(0) int? id; + @HiveField(1) String? name; District({this.id, this.name}); diff --git a/lib/model/user/province_model.g.dart b/lib/model/user/province_model.g.dart new file mode 100644 index 00000000..64836f1f --- /dev/null +++ b/lib/model/user/province_model.g.dart @@ -0,0 +1,124 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'province_model.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class ProvinceModelAdapter extends TypeAdapter { + @override + final int typeId = 0; + + @override + ProvinceModel read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + 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(), + ); + } + + @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 { + @override + final int typeId = 1; + + @override + City read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + 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(), + ); + } + + @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 { + @override + final int typeId = 2; + + @override + District read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + 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; +} diff --git a/lib/pages/personal/address/address_list_page.dart b/lib/pages/personal/address/address_list_page.dart index fbce9875..cff39005 100644 --- a/lib/pages/personal/address/address_list_page.dart +++ b/lib/pages/personal/address/address_list_page.dart @@ -131,16 +131,25 @@ class AddressListPageState extends State super.build(context); return BeeScaffold( title: '我的收货地址', - bottomNavi: MaterialButton( - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - textColor: Colors.white, - child: '新增收货地址'.text.size(28.sp).make(), - onPressed: (){ - Get.to(() => NewAddressPage()); + bottomNavi: GestureDetector( + onTap: ()async{ + bool? result = await Get.to(() => NewAddressPage(isFirstAdd: _addressModels.isEmpty? true:false,)); + if(result!=null){ + if(result) _refreshController.callRefresh(); + } }, - color: Color(0xFFE52E2E), - height: 98.w, - minWidth: double.infinity, + child: Container( + margin: EdgeInsets.only(left: 100.w,right: 100.w,bottom: 100.w), + 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( firstRefresh: true, @@ -148,14 +157,15 @@ class AddressListPageState extends State controller: _refreshController, onRefresh: () async { _addressModels = await Userfunc.getMyAddress(); + _onload =false; setState(() {}); }, child: _onload ? SizedBox() : ListView( + padding: EdgeInsets.all(20.w), children: [ - ..._addressModels.map((e) => MyAddressItem(addressModel: e,setDefaultListener:(){}, - deleteListener:(){},editListener:(){} + ..._addressModels.map((e) => MyAddressItem(addressModel: e,refreshController: _refreshController, )).toList(), // // ..._newItems.map((e) => ChatCard( diff --git a/lib/pages/personal/address/address_selector.dart b/lib/pages/personal/address/address_selector.dart index 9035dd64..f7106640 100644 --- a/lib/pages/personal/address/address_selector.dart +++ b/lib/pages/personal/address/address_selector.dart @@ -6,10 +6,12 @@ * 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:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter/material.dart'; +import 'package:aku_community/utils/headers.dart'; typedef AddressSelectorCallback = Function( String province, String city, String disctrict,int? locationId); @@ -44,7 +46,7 @@ class _AddressSelectorState extends State late ProvinceModel _province; late City? _city; late District? _district; - Color _selectedColor = Colors.white; + Color _selectedColor = Colors.black; late BuildContext _context; late bool _tab = true; @@ -63,7 +65,7 @@ class _AddressSelectorState extends State _context = context; return GestureDetector( onTap: () {}, - child: _buildBody(), + child: _buildBody(context), ); } @@ -74,31 +76,32 @@ class _AddressSelectorState extends State super.dispose(); } - Container _buildBody() { + Container _buildBody(BuildContext context) { return Container( - height: 750.w, - padding: EdgeInsets.symmetric(horizontal: 15), + height: 1000.w, + padding: EdgeInsets.symmetric(horizontal: 15.w), decoration: BoxDecoration( color: Colors.white, - borderRadius: BorderRadius.vertical(top: Radius.circular(10))), + borderRadius: BorderRadius.vertical(top: Radius.circular(10.w))), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, - children: [_header(), _tabBar(), _list()], + children: [_header(), _tabBar(), 10.hb, _list()], ), ); } Container _header() { return Container( - margin: EdgeInsets.symmetric(vertical: 10), + margin: EdgeInsets.symmetric(vertical: 30.w), child: Row( children: [ + Spacer(), Text( - "配送至", + "请选择所在地区", style: TextStyle( - fontSize: 18 * 2.sp, + fontSize: 32.sp, fontWeight: FontWeight.w500, - color: Colors.black), + color:ktextPrimary), ), Spacer(), GestureDetector( @@ -106,15 +109,15 @@ class _AddressSelectorState extends State _dismiss(); }, child: Container( - padding: EdgeInsets.all(5), + padding: EdgeInsets.all(5.w), decoration:BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(20)), - color: Colors.grey[200], + borderRadius: BorderRadius.all(Radius.circular(20.w)), + color: Colors.white, ), child: Icon( - Icons.delete, + Icons.close, color: Colors.grey[500], - size: 12, + size: 40.w, ), ), ) @@ -126,12 +129,12 @@ class _AddressSelectorState extends State TabBar _tabBar() { return TabBar( controller: _tabController, - labelPadding: EdgeInsets.zero, - unselectedLabelColor: Colors.black, + labelPadding: EdgeInsets.only(top: 5.w), + unselectedLabelColor: Color(0xFFE52E2E), isScrollable: true, - indicatorColor: _selectedColor, + indicatorColor: Color(0xFFE52E2E), indicatorSize: TabBarIndicatorSize.label, - indicatorPadding: EdgeInsets.only(left: 0, right: 0), + indicatorPadding: EdgeInsets.only(left: 10.w, right: 10.w,bottom: -5.w), tabs: _tabItems()); } @@ -146,7 +149,7 @@ class _AddressSelectorState extends State } list.add(Container( margin: EdgeInsets.symmetric(horizontal: 5.w), - height: 30.w, + height: 40.w, alignment: Alignment.center, child: Text( TextUtils.isEmpty(_result[i]) ? "请选择" : _result[i], @@ -176,7 +179,8 @@ class _AddressSelectorState extends State child: Container( padding: EdgeInsets.zero, child: Container( - padding: EdgeInsets.symmetric(vertical: 6), + color: Colors.transparent, + padding: EdgeInsets.symmetric(vertical: 10.w), child: Row(children: [ Text( addr, @@ -189,7 +193,8 @@ class _AddressSelectorState extends State offstage: !selected, child: Icon( Icons.check, - size: 16 * 2.sp, + color: Color(0xFFE52E2E), + size: 40.sp, )) ]), ), @@ -297,7 +302,7 @@ class _AddressSelectorState extends State /// 没有次级列表返回 if (city.districts!.length == 0) { _dismiss(); - widget.callback(_province.name??'', _city?.name??'', '',_province.id??null); + widget.callback(_province.name??'', _city?.name??'', '',_city?.id??null); return; } @@ -317,7 +322,7 @@ class _AddressSelectorState extends State _result[2] = _district?.name??''; _indexs[2] = index; _dismiss(); - widget.callback(_province.name??'', _city?.name??'', _district?.name??'',_province.id??null); + widget.callback(_province.name??'', _city?.name??'', _district?.name??'',_district?.id??null); } } } diff --git a/lib/pages/personal/address/editView.dart b/lib/pages/personal/address/editView.dart index bcc6f09d..fd5cd10d 100644 --- a/lib/pages/personal/address/editView.dart +++ b/lib/pages/personal/address/editView.dart @@ -65,7 +65,7 @@ class _EditTileState extends State { }, child: Container( constraints: widget.constraints, - padding: EdgeInsets.symmetric(vertical: 2, horizontal: 15), + padding: EdgeInsets.symmetric(vertical: 2.w, horizontal: 20.w), color: Colors.white, child: widget.direction == Axis.horizontal ? _horizontal() : _vertical(), @@ -77,7 +77,7 @@ class _EditTileState extends State { return Row( children: [ Container( - width: 80.w, + width: 120.w, child: Text( widget.title, style: widget.titleStyle, @@ -85,6 +85,7 @@ class _EditTileState extends State { ), Expanded( child: InputView( + padding: EdgeInsets.symmetric(horizontal: 0), focusNode: _focusNode, controller: _controller, maxLength: widget.maxLength, @@ -113,7 +114,7 @@ class _EditTileState extends State { Expanded( child: InputView( focusNode: _focusNode, - padding: EdgeInsets.symmetric(horizontal: 3), + padding: EdgeInsets.symmetric(horizontal: 0), maxLines: widget.maxLines, maxLength: widget.maxLength, controller: _controller, diff --git a/lib/pages/personal/address/new_address_page.dart b/lib/pages/personal/address/new_address_page.dart index 86438ca0..e8552a28 100644 --- a/lib/pages/personal/address/new_address_page.dart +++ b/lib/pages/personal/address/new_address_page.dart @@ -1,13 +1,14 @@ import 'dart:convert'; import 'dart:ui'; - -import 'package:aku_community/model/user/ProvinceModel.dart'; +import 'package:aku_community/base/base_style.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/utils/hive_store.dart'; import 'package:aku_community/utils/text_utils.dart'; import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:bot_toast/bot_toast.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -23,17 +24,21 @@ import 'editView.dart'; class NewAddressPage extends StatefulWidget { final bool? isFirstAdd; 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 _NewAddressPageState createState() => _NewAddressPageState(); } -class _NewAddressPageState extends State{ +class _NewAddressPageState extends State { EasyRefreshController _refreshController = EasyRefreshController(); late AddressModel _address = AddressModel.empty(); late List _cityJsonModels = []; late StateSetter _addressStateSetter; + bool isDefault = false; @override void initState() { @@ -43,224 +48,306 @@ class _NewAddressPageState extends State{ } } - @override Widget build(BuildContext context) { - - return BeeScaffold( - title: '新建收货地址', - body:_buildBody(context), + return BeeScaffold( + title:widget.addressModel==null? '新建收货地址':'修改收货地址', + body: _buildBody(context), ); - - - - } + _buildBody(BuildContext context) { return GestureDetector( onTap: () { //FocusScope.of(context).requestFocus(new FocusNode()); }, - child: Container( - child:ListView( - children: [ - Container( - height: 10, - ), - EditTile( - constraints: BoxConstraints.tight(Size(double.infinity, 45)), - title: "收货人", - value: _address.name??'', - hint: "请填写收货人姓名", - textChanged: (value) { - _address.name = value; - }, - ), - Container( - height: 3, + child: ListView( + children: [ + Container( + clipBehavior: Clip.antiAlias, + margin: EdgeInsets.all(20.w), + padding: EdgeInsets.only(top: 10.w), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(24.w)), ), - EditTile( - constraints: BoxConstraints.tight(Size(double.infinity, 45)), - title: "手机号码", - value: _address.tel??'', - hint: "请填写收货人手机号码", - maxLength: 11, - textChanged: (value) { - _address.tel = value; - }, + child: Column( + children: [ + EditTile( + constraints: BoxConstraints.tight(Size(double.infinity, 45)), + 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.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, - ), - _addressView(), - Container( - height: 3, - ), - 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) - ], - ) + ), + _defaultAddressTile(), + // _defaultAddressTile(), + Container( + height: 100, + ), + _saveButton(context) + ], ), ); } Container _saveButton(BuildContext context) { return Container( - margin: EdgeInsets.symmetric(horizontal: 15), - child: GestureDetector( - onTap: (){ - - _saveAddress(context); + margin: EdgeInsets.symmetric(horizontal: 100.w), + child: GestureDetector( + onTap: () { + _saveAddress(context); }, child: Container( + alignment: Alignment.center, decoration: BoxDecoration( 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), child: Text( - "保存地址",style: TextStyle( - color: Colors.white, - fontSize: 17 * 2.sp, - ), + "保存并使用", + style: TextStyle( + color: Colors.white, + fontSize:28.sp, + ), ), - ), ), ); } _addressView() { - return StatefulBuilder( - builder: (BuildContext context, StateSetter setSta) { - _addressStateSetter = setSta; - return GestureDetector( - onTap: () { - print('1'); - if (_cityJsonModels.isEmpty) { - print('2'); - getCityList().then((success) { - if (success) { - _selectAddress(context); - } + return StatefulBuilder( + builder: (BuildContext context, StateSetter setSta) { + _addressStateSetter = setSta; + return GestureDetector( + onTap: () { + print('1'); + if (_cityJsonModels.isEmpty) { + print('2'); + getCityList().then((success) { + if (success) { + _selectAddress(context); } - ); - return; - } - _selectAddress(context); - }, - child: Container( - padding: EdgeInsets.symmetric(vertical: 12, horizontal: 15), - decoration: BoxDecoration( - color: Colors.red, - border: Border( - bottom: BorderSide(color: Colors.grey, width: 0.5))), - child: Row( - children: [ - Container( - width: 80.w, + }); + return; + } + _selectAddress(context); + }, + child: Container( + padding: EdgeInsets.symmetric(vertical: 30.w, horizontal: 24.w), + child: Row( + children: [ + Container( + width: 120.w, + child: Text("所在地区", + style: TextStyle(fontSize: 28.sp, color: ktextPrimary)), + ), + Expanded( child: Text( - "所在地区", - style:TextStyle(fontSize: 15.sp,) - ), - ), - Expanded( - child: Text( - TextUtils.isEmpty(_address.locationName??'') - ? "选择地址" - : "${_address.locationName} : ""}", - textAlign: TextAlign.end, - style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w500), - )), - Icon( - Icons.navigate_next, - size: 16, - color: Colors.black, - ) - ], - ), + TextUtils.isEmpty(_address.locationName ?? '') + ? "选择地址" + : "${_address.locationName}", + textAlign: TextAlign.end, + style: TextStyle(fontSize: 28.sp, color: Color(0xFFBBBBBB)), + )), + Icon( + Icons.navigate_next, + size: 40.w, + color: ktextThirdColor, + ) + ], ), - ); - }, - + ), + ); + }, ); } - - /// 弹出地址选择 _selectAddress(BuildContext context) { AddressSelectorHelper.show(context, models: _cityJsonModels, province: _address.province, city: _address.city, - district: _address.district, - callback: (String province, String city, String district,int? locationId) { - _address.locationName= province+city+district; - _address.id = locationId??null; - _addressStateSetter(() {}); - print("$province - $city -$district"); - }); + district: _address.district, callback: + (String province, String city, String district, int? locationId) { + _address.province = province; + _address.city = city; + _address.district = district; + _address.locationName = province + city + district; + _address.location = locationId ?? null; + _addressStateSetter(() {}); + print("$province - $city -$district"); + }); } Future getCityList() async { - _cityJsonModels = await HiveStore.appBox?.get('cityList')??[]; + _cityJsonModels = await (HiveStore.appBox?.get('cityList') ?? []) + .cast() + .toList(); return true; } /// 保存地址 _saveAddress(BuildContext context) async { - if (TextUtils.isEmpty(_address.name??"")) { + if (TextUtils.isEmpty(_address.name ?? "")) { BotToast.showText(text: '收货人不能为空'); return; } - if (TextUtils.isEmpty(_address.tel??'') || + if (TextUtils.isEmpty(_address.tel ?? '') || !TextUtils.verifyPhone(_address.tel)) { BotToast.showText(text: '手机号格式不正确'); return; } - if (TextUtils.isEmpty(_address.province??'')) { + if (_address.location==null) { BotToast.showText(text: '所在地区不能为空'); return; } - if (TextUtils.isEmpty(_address.addressDetail??'')) { + if (TextUtils.isEmpty(_address.addressDetail ?? '')) { BotToast.showText(text: '详细地址不能为空'); return; } - - if (_address.id != null) { - Userfunc.insertAddress( _address.name??'', _address.tel??'', - _address.location??null, _address.addressDetail??'', _address.isDefault??null); + if (_address.id == null) { + Userfunc.insertAddress( + _address.name ?? '', + _address.tel ?? '', + _address.location ?? null, + _address.addressDetail ?? '', + _address.isDefault ?? null); } else { - Userfunc.updateAddress(_address.id!, _address.name??'', _address.tel??'', - _address.location??null, _address.addressDetail??'', _address.isDefault??null); + Userfunc.updateAddress( + _address.id!, + _address.name ?? '', + _address.tel ?? '', + _address.location ?? null, + _address.addressDetail ?? '', + _address.isDefault ?? null); } - Navigator.maybePop(context, _address); + //Navigator.maybePop(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(() {}); + }) + ], + ), + ); + + } + } diff --git a/lib/pages/personal/item_my_address.dart b/lib/pages/personal/item_my_address.dart index 3c0f17b6..94227e9e 100644 --- a/lib/pages/personal/item_my_address.dart +++ b/lib/pages/personal/item_my_address.dart @@ -9,102 +9,174 @@ import 'package:aku_community/base/base_style.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: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 -class MyAddressItem extends StatelessWidget { +class MyAddressItem extends StatefulWidget { final AddressModel addressModel; - final VoidCallback setDefaultListener; - final VoidCallback deleteListener; - final VoidCallback editListener; + final EasyRefreshController? refreshController; Color _titleColor = Colors.black; - MyAddressItem( - {required this.addressModel, - required this.deleteListener, - required this.editListener, - required this.setDefaultListener}) + MyAddressItem({required this.addressModel, +this.refreshController}) : assert(addressModel != null); + _MyAddressItemState createState() => _MyAddressItemState(); +} +class _MyAddressItemState extends State { @override Widget build(BuildContext context) { 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( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ GestureDetector( - onTap: (){ - this.setDefaultListener; + onTap: () async{ + bool? result = await Userfunc.setIsDefaultAddress(widget.addressModel.id!); + if(result!=null){ + if(result) widget.refreshController!.callRefresh(); + } }, 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: [ - Text( - addressModel.name??'', - style: TextStyle(fontSize: 24.sp,color: ktextPrimary) + ), ), - 30.wb, - Text( - addressModel.tel??'', - style: TextStyle(fontSize: 24.sp,color: ktextPrimary) + ), + Padding( + padding: EdgeInsets.symmetric(horizontal: 20.w, vertical:6.w), + child: Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + 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( + onTap: () async{ + + bool? result = await Get.to(() => NewAddressPage(isFirstAdd:false,addressModel: widget.addressModel, + )); + if(result!=null){ + if(result) widget.refreshController!.callRefresh(); + } + + }, 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( height: 1, color: Colors.grey[200], ), + 20.hb, Row( + crossAxisAlignment: CrossAxisAlignment.center, children: [ + 10.wb, Text( - addressModel.isDefault == 0 ? "" : "默认地址", + widget.addressModel.isDefault == 0 ? "" : "默认地址", style: TextStyle(fontSize: 28.sp,color: ktextSubColor), ), Spacer(), GestureDetector( - onTap: (){ - this.setDefaultListener; + onTap: () async{ + // 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( + width: 70.w, + height: 40.w, child:Text( "删除", style: TextStyle(fontSize: 28.sp,color: ktextSubColor), @@ -118,4 +190,5 @@ class MyAddressItem extends StatelessWidget { ), ); } + } diff --git a/lib/pages/personal/user_func.dart b/lib/pages/personal/user_func.dart index 6ee38e01..b6c9d37e 100644 --- a/lib/pages/personal/user_func.dart +++ b/lib/pages/personal/user_func.dart @@ -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_model.dart'; import 'package:aku_community/utils/network/net_util.dart'; +import 'package:bot_toast/bot_toast.dart'; class Userfunc { @@ -30,47 +31,85 @@ class Userfunc { ///添加收货地址 static Future insertAddress(String name,String tel,int? location, String addressDetail,int? isDefault) async { - BaseModel model = await NetUtil().get( + BaseModel model = await NetUtil().post( API.user.insertAddress, params: {'name':name,'tel':tel,'location':location, 'addressDetail':addressDetail,'isDefault':isDefault}, - showMessage: true + showMessage: false ); - if (model.message! == "请求成功") - return true; - else + if (model.status??false) + { + BotToast.showText(text: '添加成功'); + return true; + } + + else{ + BotToast.showText(text: '添加失败'); return false; + } + } ///修改收货地址 static Future updateAddress(int id,String name,String tel,int? location, String addressDetail,int? isDefault) async { - BaseModel model = await NetUtil().get( + BaseModel model = await NetUtil().post( API.user.updateAddress, params: {'id': id,'name':name,'tel':tel,'location':location, 'addressDetail':addressDetail,'isDefault':isDefault}, - showMessage: true + showMessage: false ); - if (model.message! == "请求成功") + if (model.status??false) + { + BotToast.showText(text: '修改成功'); return true; - else + } + + else{ + BotToast.showText(text: '修改失败'); return false; + } } ///删除收货地址 static Future deleteAddress(int addressId) async { - BaseModel model = await NetUtil().get( + BaseModel model = await NetUtil().post( API.user.deleteAddress, params: {'addressId': addressId}, - showMessage: true + showMessage: false ); - if (model.message! == "请求成功") + if (model.status??false) + { + BotToast.showText(text: '删除成功'); return true; - else + } + + else{ + BotToast.showText(text: '删除失败'); return false; + } } + ///设置默认收货地址 + static Future 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; + } + } + diff --git a/lib/pages/splash/splash_page.dart b/lib/pages/splash/splash_page.dart index ebb72747..3d43e1fc 100644 --- a/lib/pages/splash/splash_page.dart +++ b/lib/pages/splash/splash_page.dart @@ -2,8 +2,8 @@ import 'dart:io'; import 'package:aku_community/const/resource.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/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/privacy_page.dart'; import 'package:aku_community/pages/tab_navigator.dart'; @@ -115,23 +115,7 @@ class _SplashPageState extends State { context, debug: DeveloperUtil.dev, ); - Future.delayed(Duration(milliseconds: 0), () async { - List _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 { await _originOp(); diff --git a/lib/pages/tab_navigator.dart b/lib/pages/tab_navigator.dart index 7b2733a7..17eec659 100644 --- a/lib/pages/tab_navigator.dart +++ b/lib/pages/tab_navigator.dart @@ -1,8 +1,13 @@ 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/sign/sign_in_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/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/widget/bee_scaffold.dart'; import 'package:aku_community/widget/others/user_tool.dart'; @@ -38,6 +43,22 @@ class _TabNavigatorState extends State @override void initState() { super.initState(); + Future.delayed(Duration(milliseconds: 0), () async { + List _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 = [ HomePage(), MarketPage(), diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index c23bf682..0ba224d4 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -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/community/hot_topic_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/models/user/passed_house_list_model.dart'; import 'package:aku_community/utils/hive_store.dart'; diff --git a/lib/utils/hive_store.dart b/lib/utils/hive_store.dart index 143ac72d..1f068589 100644 --- a/lib/utils/hive_store.dart +++ b/lib/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:path_provider/path_provider.dart'; class HiveStore { static Box? _appBox; static Box? get appBox => _appBox; - static init() async { - _appBox = await Hive.openBox('app'); + static Future init() async { + if (!kIsWeb) { + var dir = await getApplicationDocumentsDirectory(); + Hive.init(dir.path); + Hive.registerAdapter(ProvinceModelAdapter()); + Hive.registerAdapter(CityAdapter()); + Hive.registerAdapter(DistrictAdapter()); + _appBox = await Hive.openBox('app'); + } + + } + } diff --git a/pubspec.lock b/pubspec.lock index ded7d741..0d1ec43c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -590,6 +590,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted 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: dependency: transitive description: @@ -1087,6 +1094,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted 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: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bad244df..ac79709d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -119,6 +119,7 @@ dev_dependencies: sdk: flutter #导入包整理 import_sorter: ^4.5.1 + hive_generator: ^1.1.0 #脚本工具 grinder: ^0.9.0 flutter_native_splash: ^1.1.8+4