省市区数据,历史登录等数据本地化存贮

pull/1/head
张萌 3 years ago
parent 5892afbcae
commit baf8af8c43

@ -1,3 +1,2 @@
analyzer: analyzer:
errors:

@ -2,7 +2,7 @@ part 'sars_api.dart';
class API { class API {
///HOST ///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'; static const String baseURL = '$host/api/app';

@ -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/main_initialize.dart';
import 'package:aku_new_community/pages/splash/splash_page.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/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/sign_up_provider.dart';
import 'package:aku_new_community/provider/user_provider.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/developer_util.dart';
@ -38,6 +39,7 @@ class _MyAppState extends State<MyApp> {
ChangeNotifierProvider(create: (context) => UserProvider()), ChangeNotifierProvider(create: (context) => UserProvider()),
ChangeNotifierProvider(create: (context) => AppProvider()), ChangeNotifierProvider(create: (context) => AppProvider()),
ChangeNotifierProvider(create: (context) => SignUpProvider()), ChangeNotifierProvider(create: (context) => SignUpProvider()),
ChangeNotifierProvider(create: (context) => DataProvider()),
], ],
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {

@ -21,7 +21,7 @@ class PickedCityModel {
factory PickedCityModel.fromId( factory PickedCityModel.fromId(
{required int provinceId, required int cityId, required int distrctId}) { {required int provinceId, required int cityId, required int distrctId}) {
var provinces = var provinces =
HiveStore.chinaRegionBox!.values.cast<ChinaRegionModel>().toList(); HiveStore.dataBox!.get('cities').cast<ChinaRegionModel>().toList();
final _province = final _province =
provinces.firstWhere((element) => element.id == provinceId); provinces.firstWhere((element) => element.id == provinceId);
final _city = final _city =

@ -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/clock_in/clock_in_page.dart';
import 'package:aku_new_community/pages/personal/user_profile_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/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/painters/user_bottom_bar_painter.dart';
import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart';
import 'package:aku_new_community/ui/market/order/order_page.dart'; import 'package:aku_new_community/ui/market/order/order_page.dart';
@ -66,7 +66,7 @@ class _PersonalIndexState extends State<PersonalIndex>
padding: EdgeInsets.all(5.w), padding: EdgeInsets.all(5.w),
onPressed: () { onPressed: () {
if (!userProvider.isLogin) if (!userProvider.isLogin)
Get.to(() => SignInPage()); Get.to(() => LoginPage());
else else
Get.to(() => UserProfilePage()); Get.to(() => UserProfilePage());
}, },
@ -263,7 +263,7 @@ class _PersonalIndexState extends State<PersonalIndex>
padding: EdgeInsets.all(5.w), padding: EdgeInsets.all(5.w),
onPressed: () { onPressed: () {
if (!userProvider.isLogin) if (!userProvider.isLogin)
Get.to(() => SignInPage()); Get.to(() => LoginPage());
else else
Get.to(() => UserProfilePage()); Get.to(() => UserProfilePage());
}, },
@ -276,10 +276,14 @@ class _PersonalIndexState extends State<PersonalIndex>
child: ClipOval( child: ClipOval(
child: FadeInImage.assetNetwork( child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(userProvider image: API.image((userProvider
.userInfoModel!.imgUrls.isNotEmpty .userInfoModel?.imgUrls ??
? userProvider [])
.userInfoModel!.imgUrls.first.url .isNotEmpty
? (userProvider.userInfoModel?.imgUrls ??
[])
.first
.url
: ''), : ''),
height: 106.w, height: 106.w,
width: 106.w, width: 106.w,
@ -513,7 +517,7 @@ class _PersonalIndexState extends State<PersonalIndex>
R.ASSETS_ICONS_ICON_MY_HOUSE_PNG, R.ASSETS_ICONS_ICON_MY_HOUSE_PNG,
() => HouseOwnersPage( () => HouseOwnersPage(
identify: identify:
UserTool.userProvider.userDetailModel!.type ?? UserTool.userProvider.userDetailModel?.type ??
4, 4,
), ),
userProvider.userDetailModel!.estateNames!.isEmpty userProvider.userDetailModel!.estateNames!.isEmpty

@ -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:aku_new_community/widget/bee_scaffold.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -36,7 +36,7 @@ class _AccountManagerPageState extends State<AccountManagerPage> {
), ),
), ),
onPressed: () { onPressed: () {
Get.offAll(() => SignInPage()); Get.offAll(() => LoginPage());
}, },
), ),
], ],

@ -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/community_model.dart';
import 'package:aku_new_community/models/login/picked_city_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/bee_scaffold.dart';
import 'package:aku_new_community/widget/picker/bee_city_picker.dart'; import 'package:aku_new_community/widget/picker/bee_city_picker.dart';
import 'package:aku_new_community/widget/picker/bee_community_picker.dart'; import 'package:aku_new_community/widget/picker/bee_community_picker.dart';
@ -77,40 +79,13 @@ class _SelectCommunityState extends State<SelectCommunity> {
onTap: () async { onTap: () async {
var cancel = BotToast.showLoading(); var cancel = BotToast.showLoading();
List<CommunityModel> _communities = []; List<CommunityModel> _communities = [];
// var base = await NetUtil().get(API.sarsApi.login.allCommunity); var base = await NetUtil().get(API.sarsApi.login.allCommunity);
// if (base.status ?? false) { if (base.status ?? false) {
// _communities = (base.data as List) _communities = (base.data as List)
// .map((e) => CommunityModel.fromJson(e)) .map((e) => CommunityModel.fromJson(e))
// .toList(); .toList();
// } }
cancel(); 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); _community = await BeeCommunityPicker.pick(context, _communities);
setState(() {}); setState(() {});
}, },

@ -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/developer_util.dart';
import 'package:aku_new_community/utils/headers.dart'; import 'package:aku_new_community/utils/headers.dart';
import 'package:aku_new_community/utils/hive_store.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:amap_flutter_location/amap_flutter_location.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -132,6 +133,7 @@ class _SplashPageState extends State<SplashPage> {
await Permission.locationWhenInUse.request(); await Permission.locationWhenInUse.request();
} }
await _initOp(); await _initOp();
UserTool.dataProvider.init();
AMapFlutterLocation.updatePrivacyShow(true, true); AMapFlutterLocation.updatePrivacyShow(true, true);
AMapFlutterLocation.updatePrivacyAgree(true); AMapFlutterLocation.updatePrivacyAgree(true);
MainInitialize.initTheme(); MainInitialize.initTheme();

@ -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/constants/api.dart';
import 'package:aku_new_community/model/user/province_model.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/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/provider/app_provider.dart';
import 'package:aku_new_community/ui/community/community_views/community_page.dart'; import 'package:aku_new_community/ui/community/community_views/community_page.dart';
import 'package:aku_new_community/ui/market/market_page.dart'; import 'package:aku_new_community/ui/market/market_page.dart';
@ -155,7 +155,7 @@ class _TabNavigatorState extends State<TabNavigator>
unselectedFontSize: 20.sp, unselectedFontSize: 20.sp,
onTap: (index) { onTap: (index) {
if (UserTool.userProvider.isLogin == false) { if (UserTool.userProvider.isLogin == false) {
Get.offAll(() => SignInPage()); Get.offAll(() => LoginPage());
} else { } else {
_tabController!.animateTo(index, curve: Curves.easeInOutCubic); _tabController!.animateTo(index, curve: Curves.easeInOutCubic);
setFunc(() => _currentIndex = index); setFunc(() => _currentIndex = index);

@ -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/message/message_center_model.dart';
import 'package:aku_new_community/model/user/adress_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/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/models/user/passed_house_list_model.dart';
import 'package:aku_new_community/utils/hive_store.dart'; import 'package:aku_new_community/utils/hive_store.dart';
import 'package:aku_new_community/utils/network/base_model.dart'; import 'package:aku_new_community/utils/network/base_model.dart';
@ -328,18 +327,4 @@ class AppProvider extends ChangeNotifier {
} }
notifyListeners(); notifyListeners();
} }
ChinaRegionModel? _cityModel;
ChinaRegionModel? get cityModel => _cityModel;
Future<bool> 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;
}
}
} }

@ -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<HistoryLoginModel>()
.toList();
}
List<ChinaRegionModel> _cityModel = [];
List<ChinaRegionModel> get cityModel => _cityModel;
Future<bool> 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<HistoryLoginModel> _loginHistories = [];
List<HistoryLoginModel> 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);
}
}

@ -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/model/common/img_model.dart';
import 'package:aku_new_community/models/market/goods_detail_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/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/provider/user_provider.dart';
import 'package:aku_new_community/ui/market/goods/goods_card.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'; import 'package:aku_new_community/ui/market/goods/goods_order_detail_page.dart';
@ -180,7 +180,7 @@ class _GoodsDetailPageState extends State<GoodsDetailPage> {
onPressed: () { onPressed: () {
if (!UserTool.userProvider.isLogin) { if (!UserTool.userProvider.isLogin) {
BotToast.showText(text: '请先登录!'); BotToast.showText(text: '请先登录!');
Get.offAll(() => SignInPage()); Get.offAll(() => LoginPage());
return; return;
} }
Get.bottomSheet(Material( Get.bottomSheet(Material(

@ -10,10 +10,10 @@ class HiveStore {
static Box? _appBox; static Box? _appBox;
static Box? get appBox => _appBox; static Box? get appBox => _appBox;
static Box? _chinaRegionBox;
static Box? get chinaRegionBox => _chinaRegionBox;
static Box? _userBox; static Box? _userBox;
static Box? get userBox => _userBox; static Box? get userBox => _userBox;
static Box? _dataBox;
static Box? get dataBox => _dataBox;
static Future init() async { static Future init() async {
if (!kIsWeb) { if (!kIsWeb) {
@ -26,8 +26,8 @@ class HiveStore {
Hive.registerAdapter(HistoryLoginModelAdapter()); Hive.registerAdapter(HistoryLoginModelAdapter());
Hive.registerAdapter(UserConfigModelAdapter()); Hive.registerAdapter(UserConfigModelAdapter());
_appBox = await Hive.openBox('app'); _appBox = await Hive.openBox('app');
_chinaRegionBox = await Hive.openBox('chinaRegionBox');
_userBox = await Hive.openBox('userBox'); _userBox = await Hive.openBox('userBox');
_dataBox = await Hive.openBox('dataBox');
} }
} }
} }

@ -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/app_provider.dart';
import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart';
import 'package:aku_new_community/ui/profile/house/add_house_page.dart'; import 'package:aku_new_community/ui/profile/house/add_house_page.dart';
@ -20,7 +20,7 @@ class LoginUtil {
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false); final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
if (userProvider.isNotLogin) { if (userProvider.isNotLogin) {
BotToast.showText(text: '请先登录'); BotToast.showText(text: '请先登录');
Get.to(() => SignInPage()); Get.to(() => LoginPage());
return false; return false;
} }
return true; return true;

@ -2,7 +2,7 @@ import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:aku_new_community/constants/api.dart'; 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/provider/user_provider.dart';
import 'package:aku_new_community/utils/developer_util.dart'; import 'package:aku_new_community/utils/developer_util.dart';
import 'package:aku_new_community/utils/network/base_file_model.dart'; import 'package:aku_new_community/utils/network/base_file_model.dart';
@ -184,7 +184,7 @@ class NetUtil {
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false); final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
if (!model.status! && model.message == '登录失效,请登录' && userProvider.isLogin) { if (!model.status! && model.message == '登录失效,请登录' && userProvider.isLogin) {
userProvider.logout(); userProvider.logout();
Get.offAll(() => SignInPage()); Get.offAll(() => LoginPage());
} }
if (!model.status! || showMessage) { if (!model.status! || showMessage) {
BotToast.showText(text: model.message!); BotToast.showText(text: model.message!);

@ -1,4 +1,5 @@
import 'package:aku_new_community/provider/app_provider.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/user_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -9,4 +10,6 @@ class UserTool {
static AppProvider get appProveider => static AppProvider get appProveider =>
Provider.of<AppProvider>(Get.context!, listen: false); Provider.of<AppProvider>(Get.context!, listen: false);
static DataProvider get dataProvider =>
Provider.of<DataProvider>(Get.context!, listen: false);
} }

@ -25,7 +25,7 @@ class BeeCityPicker extends StatefulWidget {
class _BeeCityPickerState extends State<BeeCityPicker> { class _BeeCityPickerState extends State<BeeCityPicker> {
List<ChinaRegionModel> get provinces => List<ChinaRegionModel> get provinces =>
HiveStore.chinaRegionBox!.values.cast<ChinaRegionModel>().toList(); HiveStore.dataBox!.get('cities').cast<ChinaRegionModel>().toList();
late int _pickedProvinceIndex; late int _pickedProvinceIndex;
late int _pickedCityIndex; late int _pickedCityIndex;

Loading…
Cancel
Save