diff --git a/analysis_options.yaml b/analysis_options.yaml index 9eb12564..97c90be8 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1,2 @@ -analyzer: - errors: \ No newline at end of file +analyzer: \ No newline at end of file diff --git a/lib/constants/api.dart b/lib/constants/api.dart index ffa98711..335e5ba4 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -2,7 +2,7 @@ part 'sars_api.dart'; class API { ///HOST - static const String host = 'http://shop.kaidalai.cn'; + static const String host = 'http://121.41.26.225:8006'; ///接口基础地址 static const String baseURL = '$host/api/app'; diff --git a/lib/main.dart b/lib/main.dart index 4f9a86f4..fb1af376 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'package:aku_new_community/constants/app_theme.dart'; import 'package:aku_new_community/main_initialize.dart'; import 'package:aku_new_community/pages/splash/splash_page.dart'; import 'package:aku_new_community/provider/app_provider.dart'; +import 'package:aku_new_community/provider/data_provider.dart'; import 'package:aku_new_community/provider/sign_up_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/utils/developer_util.dart'; @@ -38,6 +39,7 @@ class _MyAppState extends State { ChangeNotifierProvider(create: (context) => UserProvider()), ChangeNotifierProvider(create: (context) => AppProvider()), ChangeNotifierProvider(create: (context) => SignUpProvider()), + ChangeNotifierProvider(create: (context) => DataProvider()), ], child: GestureDetector( onTap: () { diff --git a/lib/models/login/picked_city_model.dart b/lib/models/login/picked_city_model.dart index 33f23195..02022fe8 100644 --- a/lib/models/login/picked_city_model.dart +++ b/lib/models/login/picked_city_model.dart @@ -21,7 +21,7 @@ class PickedCityModel { factory PickedCityModel.fromId( {required int provinceId, required int cityId, required int distrctId}) { var provinces = - HiveStore.chinaRegionBox!.values.cast().toList(); + HiveStore.dataBox!.get('cities').cast().toList(); final _province = provinces.firstWhere((element) => element.id == provinceId); final _city = diff --git a/lib/pages/personal/personal_page.dart b/lib/pages/personal/personal_page.dart index c7160ed8..22f4e9e7 100644 --- a/lib/pages/personal/personal_page.dart +++ b/lib/pages/personal/personal_page.dart @@ -4,7 +4,7 @@ import 'package:aku_new_community/gen/assets.gen.dart'; import 'package:aku_new_community/pages/personal/clock_in/clock_in_page.dart'; import 'package:aku_new_community/pages/personal/user_profile_page.dart'; import 'package:aku_new_community/pages/setting_page/settings_page.dart'; -import 'package:aku_new_community/pages/sign/sign_in_page.dart'; +import 'package:aku_new_community/pages/sign/login/login_page.dart'; import 'package:aku_new_community/painters/user_bottom_bar_painter.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/ui/market/order/order_page.dart'; @@ -66,7 +66,7 @@ class _PersonalIndexState extends State padding: EdgeInsets.all(5.w), onPressed: () { if (!userProvider.isLogin) - Get.to(() => SignInPage()); + Get.to(() => LoginPage()); else Get.to(() => UserProfilePage()); }, @@ -263,7 +263,7 @@ class _PersonalIndexState extends State padding: EdgeInsets.all(5.w), onPressed: () { if (!userProvider.isLogin) - Get.to(() => SignInPage()); + Get.to(() => LoginPage()); else Get.to(() => UserProfilePage()); }, @@ -276,10 +276,14 @@ class _PersonalIndexState extends State child: ClipOval( child: FadeInImage.assetNetwork( placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, - image: API.image(userProvider - .userInfoModel!.imgUrls.isNotEmpty - ? userProvider - .userInfoModel!.imgUrls.first.url + image: API.image((userProvider + .userInfoModel?.imgUrls ?? + []) + .isNotEmpty + ? (userProvider.userInfoModel?.imgUrls ?? + []) + .first + .url : ''), height: 106.w, width: 106.w, @@ -513,7 +517,7 @@ class _PersonalIndexState extends State R.ASSETS_ICONS_ICON_MY_HOUSE_PNG, () => HouseOwnersPage( identify: - UserTool.userProvider.userDetailModel!.type ?? + UserTool.userProvider.userDetailModel?.type ?? 4, ), userProvider.userDetailModel!.estateNames!.isEmpty diff --git a/lib/pages/setting_page/account_manager_page.dart b/lib/pages/setting_page/account_manager_page.dart index 7616c303..a1a8a5f3 100644 --- a/lib/pages/setting_page/account_manager_page.dart +++ b/lib/pages/setting_page/account_manager_page.dart @@ -1,4 +1,4 @@ -import 'package:aku_new_community/pages/sign/sign_in_page.dart'; +import 'package:aku_new_community/pages/sign/login/login_page.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -36,7 +36,7 @@ class _AccountManagerPageState extends State { ), ), onPressed: () { - Get.offAll(() => SignInPage()); + Get.offAll(() => LoginPage()); }, ), ], diff --git a/lib/pages/sign/login/select_community.dart b/lib/pages/sign/login/select_community.dart index ddd15b82..75af528e 100644 --- a/lib/pages/sign/login/select_community.dart +++ b/lib/pages/sign/login/select_community.dart @@ -1,5 +1,7 @@ +import 'package:aku_new_community/constants/api.dart'; import 'package:aku_new_community/models/login/community_model.dart'; import 'package:aku_new_community/models/login/picked_city_model.dart'; +import 'package:aku_new_community/utils/network/net_util.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart'; import 'package:aku_new_community/widget/picker/bee_city_picker.dart'; import 'package:aku_new_community/widget/picker/bee_community_picker.dart'; @@ -77,40 +79,13 @@ class _SelectCommunityState extends State { onTap: () async { var cancel = BotToast.showLoading(); List _communities = []; - // var base = await NetUtil().get(API.sarsApi.login.allCommunity); - // if (base.status ?? false) { - // _communities = (base.data as List) - // .map((e) => CommunityModel.fromJson(e)) - // .toList(); - // } + var base = await NetUtil().get(API.sarsApi.login.allCommunity); + if (base.status ?? false) { + _communities = (base.data as List) + .map((e) => CommunityModel.fromJson(e)) + .toList(); + } cancel(); - _communities = [ - CommunityModel( - id: 0, - name: '111', - address: 'address', - addressDetails: 'addressDetails'), - CommunityModel( - id: 0, - name: '2222', - address: 'address', - addressDetails: 'addressDetails'), - CommunityModel( - id: 0, - name: '3333', - address: 'address', - addressDetails: 'addressDetails'), - CommunityModel( - id: 0, - name: '444', - address: 'address', - addressDetails: 'addressDetails'), - CommunityModel( - id: 0, - name: '5555', - address: 'address', - addressDetails: 'addressDetails') - ]; _community = await BeeCommunityPicker.pick(context, _communities); setState(() {}); }, diff --git a/lib/pages/splash/splash_page.dart b/lib/pages/splash/splash_page.dart index ddc2af60..ec17ca33 100644 --- a/lib/pages/splash/splash_page.dart +++ b/lib/pages/splash/splash_page.dart @@ -10,6 +10,7 @@ import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/utils/developer_util.dart'; import 'package:aku_new_community/utils/headers.dart'; import 'package:aku_new_community/utils/hive_store.dart'; +import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:amap_flutter_location/amap_flutter_location.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; @@ -132,6 +133,7 @@ class _SplashPageState extends State { await Permission.locationWhenInUse.request(); } await _initOp(); + UserTool.dataProvider.init(); AMapFlutterLocation.updatePrivacyShow(true, true); AMapFlutterLocation.updatePrivacyAgree(true); MainInitialize.initTheme(); diff --git a/lib/pages/tab_navigator.dart b/lib/pages/tab_navigator.dart index d1bd45a1..d5566434 100644 --- a/lib/pages/tab_navigator.dart +++ b/lib/pages/tab_navigator.dart @@ -2,7 +2,7 @@ import 'package:aku_new_community/const/resource.dart'; import 'package:aku_new_community/constants/api.dart'; import 'package:aku_new_community/model/user/province_model.dart'; import 'package:aku_new_community/pages/property/property_page.dart'; -import 'package:aku_new_community/pages/sign/sign_in_page.dart'; +import 'package:aku_new_community/pages/sign/login/login_page.dart'; import 'package:aku_new_community/provider/app_provider.dart'; import 'package:aku_new_community/ui/community/community_views/community_page.dart'; import 'package:aku_new_community/ui/market/market_page.dart'; @@ -155,7 +155,7 @@ class _TabNavigatorState extends State unselectedFontSize: 20.sp, onTap: (index) { if (UserTool.userProvider.isLogin == false) { - Get.offAll(() => SignInPage()); + Get.offAll(() => LoginPage()); } else { _tabController!.animateTo(index, curve: Curves.easeInOutCubic); setFunc(() => _currentIndex = index); diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 4340f33a..3dbbf4d0 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -8,7 +8,6 @@ import 'package:aku_new_community/model/community/hot_topic_model.dart'; import 'package:aku_new_community/model/message/message_center_model.dart'; import 'package:aku_new_community/model/user/adress_model.dart'; import 'package:aku_new_community/model/user/car_parking_model.dart'; -import 'package:aku_new_community/models/login/china_region_model.dart'; import 'package:aku_new_community/models/user/passed_house_list_model.dart'; import 'package:aku_new_community/utils/hive_store.dart'; import 'package:aku_new_community/utils/network/base_model.dart'; @@ -328,18 +327,4 @@ class AppProvider extends ChangeNotifier { } notifyListeners(); } - - ChinaRegionModel? _cityModel; - - ChinaRegionModel? get cityModel => _cityModel; - - Future updateCityList() async { - var model = await NetUtil().get(API.sarsApi.city.allCity); - if (model.status ?? false) { - _cityModel = ChinaRegionModel.fromJson(model.data); - return true; - } else { - return false; - } - } } diff --git a/lib/provider/data_provider.dart b/lib/provider/data_provider.dart new file mode 100644 index 00000000..085d344f --- /dev/null +++ b/lib/provider/data_provider.dart @@ -0,0 +1,45 @@ +import 'package:aku_new_community/constants/api.dart'; +import 'package:aku_new_community/models/login/china_region_model.dart'; +import 'package:aku_new_community/models/login/history_login_model.dart'; +import 'package:aku_new_community/utils/hive_store.dart'; +import 'package:aku_new_community/utils/network/net_util.dart'; +import 'package:flutter/material.dart'; + +class DataProvider extends ChangeNotifier { + Future init() async { + updateCityList(); + _loginHistories = HiveStore.dataBox! + .get('historyLogin') + .cast() + .toList(); + } + + List _cityModel = []; + + List get cityModel => _cityModel; + + Future updateCityList() async { + var model = await NetUtil().get(API.sarsApi.city.allCity); + if (model.status ?? false) { + _cityModel = (model.data as List) + .map((e) => ChinaRegionModel.fromJson(e)) + .toList(); + HiveStore.dataBox!.put('cities', _cityModel); + return true; + } else { + return false; + } + } + + List _loginHistories = []; + + List get loginHistories => _loginHistories; + + Future addHistories(HistoryLoginModel model) async { + _loginHistories.insert(0, model); + if (_loginHistories.length > 4) { + _loginHistories.removeAt(_loginHistories.length - 1); + } + HiveStore.dataBox!.put('historyLogin', _loginHistories); + } +} diff --git a/lib/ui/market/goods/goods_detail_page.dart b/lib/ui/market/goods/goods_detail_page.dart index aa6a2f1c..a5b5f859 100644 --- a/lib/ui/market/goods/goods_detail_page.dart +++ b/lib/ui/market/goods/goods_detail_page.dart @@ -4,7 +4,7 @@ import 'package:aku_new_community/constants/api.dart'; import 'package:aku_new_community/model/common/img_model.dart'; import 'package:aku_new_community/models/market/goods_detail_model.dart'; import 'package:aku_new_community/models/market/goods_item.dart'; -import 'package:aku_new_community/pages/sign/sign_in_page.dart'; +import 'package:aku_new_community/pages/sign/login/login_page.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/ui/market/goods/goods_card.dart'; import 'package:aku_new_community/ui/market/goods/goods_order_detail_page.dart'; @@ -180,7 +180,7 @@ class _GoodsDetailPageState extends State { onPressed: () { if (!UserTool.userProvider.isLogin) { BotToast.showText(text: '请先登录!'); - Get.offAll(() => SignInPage()); + Get.offAll(() => LoginPage()); return; } Get.bottomSheet(Material( diff --git a/lib/utils/hive_store.dart b/lib/utils/hive_store.dart index 13335cb4..dbbb8bd3 100644 --- a/lib/utils/hive_store.dart +++ b/lib/utils/hive_store.dart @@ -10,10 +10,10 @@ class HiveStore { static Box? _appBox; static Box? get appBox => _appBox; - static Box? _chinaRegionBox; - static Box? get chinaRegionBox => _chinaRegionBox; static Box? _userBox; static Box? get userBox => _userBox; + static Box? _dataBox; + static Box? get dataBox => _dataBox; static Future init() async { if (!kIsWeb) { @@ -26,8 +26,8 @@ class HiveStore { Hive.registerAdapter(HistoryLoginModelAdapter()); Hive.registerAdapter(UserConfigModelAdapter()); _appBox = await Hive.openBox('app'); - _chinaRegionBox = await Hive.openBox('chinaRegionBox'); _userBox = await Hive.openBox('userBox'); + _dataBox = await Hive.openBox('dataBox'); } } } diff --git a/lib/utils/login_util.dart b/lib/utils/login_util.dart index c6dceef5..3d5b02ed 100644 --- a/lib/utils/login_util.dart +++ b/lib/utils/login_util.dart @@ -1,4 +1,4 @@ -import 'package:aku_new_community/pages/sign/sign_in_page.dart'; +import 'package:aku_new_community/pages/sign/login/login_page.dart'; import 'package:aku_new_community/provider/app_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/ui/profile/house/add_house_page.dart'; @@ -20,7 +20,7 @@ class LoginUtil { final userProvider = Provider.of(Get.context!, listen: false); if (userProvider.isNotLogin) { BotToast.showText(text: '请先登录'); - Get.to(() => SignInPage()); + Get.to(() => LoginPage()); return false; } return true; diff --git a/lib/utils/network/net_util.dart b/lib/utils/network/net_util.dart index c6f259b0..9f17038d 100644 --- a/lib/utils/network/net_util.dart +++ b/lib/utils/network/net_util.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'dart:typed_data'; import 'package:aku_new_community/constants/api.dart'; -import 'package:aku_new_community/pages/sign/sign_in_page.dart'; +import 'package:aku_new_community/pages/sign/login/login_page.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/utils/developer_util.dart'; import 'package:aku_new_community/utils/network/base_file_model.dart'; @@ -184,7 +184,7 @@ class NetUtil { final userProvider = Provider.of(Get.context!, listen: false); if (!model.status! && model.message == '登录失效,请登录' && userProvider.isLogin) { userProvider.logout(); - Get.offAll(() => SignInPage()); + Get.offAll(() => LoginPage()); } if (!model.status! || showMessage) { BotToast.showText(text: model.message!); diff --git a/lib/widget/others/user_tool.dart b/lib/widget/others/user_tool.dart index 2a922c88..18bc3e69 100644 --- a/lib/widget/others/user_tool.dart +++ b/lib/widget/others/user_tool.dart @@ -1,4 +1,5 @@ import 'package:aku_new_community/provider/app_provider.dart'; +import 'package:aku_new_community/provider/data_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; @@ -9,4 +10,6 @@ class UserTool { static AppProvider get appProveider => Provider.of(Get.context!, listen: false); + static DataProvider get dataProvider => + Provider.of(Get.context!, listen: false); } diff --git a/lib/widget/picker/bee_city_picker.dart b/lib/widget/picker/bee_city_picker.dart index ee5a0da4..11d00cb7 100644 --- a/lib/widget/picker/bee_city_picker.dart +++ b/lib/widget/picker/bee_city_picker.dart @@ -25,7 +25,7 @@ class BeeCityPicker extends StatefulWidget { class _BeeCityPickerState extends State { List get provinces => - HiveStore.chinaRegionBox!.values.cast().toList(); + HiveStore.dataBox!.get('cities').cast().toList(); late int _pickedProvinceIndex; late int _pickedCityIndex;