feat: first open app init

This commit is contained in:
louis 2024-03-26 16:02:49 +08:00
parent cf51cd8ada
commit 6aab12f536
26 changed files with 72 additions and 54 deletions

View File

@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:sk_base_mobile/config.dart'; import 'package:sk_base_mobile/config.dart';
import 'package:sk_base_mobile/screens/landing/landing.dart';
import 'package:sk_base_mobile/screens/login/login%20copy.dart';
import 'package:sk_base_mobile/services/storage.service.dart'; import 'package:sk_base_mobile/services/storage.service.dart';
import 'package:sk_base_mobile/app_theme.dart'; import 'package:sk_base_mobile/app_theme.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
@ -18,6 +20,8 @@ class IndexPage extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isLandscape = final isLandscape =
MediaQuery.of(context).orientation == Orientation.landscape; MediaQuery.of(context).orientation == Orientation.landscape;
final isLogin =
StorageService.to.getString(CacheKeys.token, isWithUser: false) != null;
return ScreenUtilInit( return ScreenUtilInit(
minTextAdapt: true, minTextAdapt: true,
designSize: isLandscape designSize: isLandscape
@ -35,7 +39,6 @@ class IndexPage extends StatelessWidget {
title: GloablConfig.DOMAIN_NAME, title: GloablConfig.DOMAIN_NAME,
getPages: RouteConfig.getPages, getPages: RouteConfig.getPages,
initialRoute: getInitialRoute(), initialRoute: getInitialRoute(),
// initialRoute: RouteConfig.onboarding,
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
builder: (_, widget) { builder: (_, widget) {
return Obx(() => MediaQuery( return Obx(() => MediaQuery(

View File

@ -8,7 +8,7 @@ import 'package:sk_base_mobile/util/screen_adaper_util.dart';
class ChangeButtonRow extends StatelessWidget { class ChangeButtonRow extends StatelessWidget {
ChangeButtonRow({super.key}); ChangeButtonRow({super.key});
final controller = Get.put(InventoryInoutController()); final controller = Get.find<InventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(

View File

@ -10,7 +10,7 @@ import 'package:sk_base_mobile/widgets/core/zt_base_date_picker.dart';
class CustomAppBar extends StatelessWidget { class CustomAppBar extends StatelessWidget {
CustomAppBar({super.key}); CustomAppBar({super.key});
final controller = Get.put(InventoryInoutController()); final controller = Get.find<InventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(

View File

@ -8,7 +8,7 @@ import 'dates.dart';
class DateContainer extends StatelessWidget { class DateContainer extends StatelessWidget {
final int index; final int index;
DateContainer({super.key, required this.index}); DateContainer({super.key, required this.index});
final controller = Get.put(InventoryInoutController()); final controller = Get.find<InventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final size = MediaQuery.sizeOf(context); final size = MediaQuery.sizeOf(context);

View File

@ -6,7 +6,7 @@ import 'package:sk_base_mobile/util/util.dart';
class Dates extends StatelessWidget { class Dates extends StatelessWidget {
Dates({super.key, required this.index}); Dates({super.key, required this.index});
final int index; final int index;
final controller = Get.put(InventoryInoutController()); final controller = Get.find<InventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(

View File

@ -176,6 +176,7 @@ class InventoryInouInfoController extends GetxController {
@override @override
onReady() { onReady() {
super.onReady();
getData(); getData();
} }

View File

@ -5,7 +5,7 @@ import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controlle
class InventoryInoutView extends StatelessWidget { class InventoryInoutView extends StatelessWidget {
InventoryInoutView({super.key}); InventoryInoutView({super.key});
final controller = Get.put(InventoryInoutController()); final controller = Get.find<InventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return PageView( return PageView(

View File

@ -35,7 +35,7 @@ class Grid extends StatelessWidget {
final int crossAsis; final int crossAsis;
final double ratio; final double ratio;
final int ind; final int ind;
final controller = Get.put(InventoryInoutController()); final controller = Get.find<InventoryInoutController>();
Grid( Grid(
{super.key, {super.key,
required this.crossAsis, required this.crossAsis,

View File

@ -10,7 +10,7 @@ class TodayButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final controller = Get.put(InventoryInoutController()); final controller = Get.find<InventoryInoutController>();
return InkWell( return InkWell(
borderRadius: BorderRadius.circular(ScreenAdaper.sp(30)), borderRadius: BorderRadius.circular(ScreenAdaper.sp(30)),
onTap: () => controller.pageController.animateToPage(0, onTap: () => controller.pageController.animateToPage(0,

View File

@ -8,7 +8,7 @@ import 'package:sk_base_mobile/util/util.dart';
class UperBody extends StatelessWidget { class UperBody extends StatelessWidget {
UperBody({super.key}); UperBody({super.key});
final controller = Get.put(InventoryInoutController()); final controller = Get.find<InventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(

View File

@ -33,8 +33,8 @@ class InventoryInoutController extends GetxController {
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
final daysNum = 20; final daysNum = 20;
@override @override
void onInit() { onReady() {
super.onInit(); super.onReady();
getData(); getData();
} }

View File

@ -13,6 +13,7 @@ class LandingPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
printInfo(info: 'landing');
return Material( return Material(
child: Stack(children: [ child: Stack(children: [
const BackColors(), const BackColors(),

View File

@ -1,15 +1,41 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:sk_base_mobile/models/app_bottom_nav_item.dart';
import 'package:sk_base_mobile/screens/inventory/inventory.dart';
import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout.dart';
import 'package:sk_base_mobile/screens/mine/mine.dart';
import 'package:sk_base_mobile/screens/workbench/workbench.dart';
import 'package:sk_base_mobile/services/app_info.service.dart'; import 'package:sk_base_mobile/services/app_info.service.dart';
class LandingController extends GetxController { class LandingController extends GetxController {
RxInt currentIndex = 0.obs; RxInt currentIndex = 0.obs;
RxBool showCreateBtn = true.obs; RxBool showCreateBtn = true.obs;
List<Widget> pages = []; List<Widget> pages = [];
List<AppBottomNavItem>? bottomNavItems = [
AppBottomNavItem(
icon: Icons.home_max_outlined,
activeIcon: Icons.home_max_outlined,
label: '登记',
page: InvenotryInoutPage()),
AppBottomNavItem(
icon: Icons.inventory_outlined,
activeIcon: Icons.inventory_rounded,
label: '库存',
page: InventoryPage()),
AppBottomNavItem(
icon: Icons.widgets_outlined,
activeIcon: Icons.widgets_rounded,
label: '工作台',
page: WorkBenchPage()),
AppBottomNavItem(
icon: Icons.person_outline_outlined,
activeIcon: Icons.person,
label: '我的',
page: MinePage()),
];
@override @override
onInit() { onInit() {
super.onInit(); super.onInit();
pages = AppInfoService.to.bottomNavItems!.map((e) => e.page!).toList(); pages = bottomNavItems!.map((e) => e.page!).toList();
} }
} }

View File

@ -7,7 +7,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_c
class CategoryInput extends StatelessWidget { class CategoryInput extends StatelessWidget {
CategoryInput({super.key}); CategoryInput({super.key});
final controller = Get.put(NewInventoryInoutController()); final controller = Get.find<NewInventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -6,7 +6,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_c
class DateTimeInput extends StatelessWidget { class DateTimeInput extends StatelessWidget {
DateTimeInput({super.key}); DateTimeInput({super.key});
final controller = Get.put(NewInventoryInoutController()); final controller = Get.find<NewInventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -5,7 +5,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/components/text_input
import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_controller.dart'; import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_controller.dart';
class DescriptionInput extends StatelessWidget { class DescriptionInput extends StatelessWidget {
final controller = Get.put(NewInventoryInoutController()); final controller = Get.find<NewInventoryInoutController>();
DescriptionInput({super.key}); DescriptionInput({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -6,7 +6,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_c
class SelectImageList extends StatelessWidget { class SelectImageList extends StatelessWidget {
SelectImageList({super.key}); SelectImageList({super.key});
final controller = Get.put(NewInventoryInoutController()); final controller = Get.find<NewInventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(

View File

@ -7,7 +7,7 @@ import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_c
class LabelInput extends StatelessWidget { class LabelInput extends StatelessWidget {
LabelInput({super.key}); LabelInput({super.key});
final controller = Get.put(NewInventoryInoutController()); final controller = Get.find<NewInventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(

View File

@ -14,7 +14,7 @@ class TextInputField extends StatelessWidget {
required this.hint, required this.hint,
required this.focus, required this.focus,
required this.onTap}); required this.onTap});
final taskController = Get.put(NewInventoryInoutController()); final taskController = Get.find<NewInventoryInoutController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AnimatedContainer( return AnimatedContainer(

View File

@ -24,8 +24,10 @@ class NewInventoryInout extends StatelessWidget {
final dictService = Get.find<DictService>(); final dictService = Get.find<DictService>();
final int inOrOut; final int inOrOut;
NewInventoryInout({Key? key, this.inOrOut = InventoryInOrOutEnum.In}) NewInventoryInout({Key? key, this.inOrOut = InventoryInOrOutEnum.In})
: controller = Get.put(NewInventoryInoutController(inOrOut: inOrOut)), : controller = Get.find<NewInventoryInoutController>(),
super(key: key); super(key: key) {
controller.inOrOut = inOrOut;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -16,7 +16,7 @@ import 'package:sk_base_mobile/util/snack_bar.util.dart';
class NewInventoryInoutController extends GetxController { class NewInventoryInoutController extends GetxController {
final formKey = GlobalKey<FormState>(); final formKey = GlobalKey<FormState>();
final int? inOrOut; int? inOrOut;
DateTime? pickedDate; DateTime? pickedDate;
final DbHelper db = DbHelper(); final DbHelper db = DbHelper();
RxInt selectedImage = 0.obs; RxInt selectedImage = 0.obs;
@ -28,7 +28,7 @@ class NewInventoryInoutController extends GetxController {
RxString startTime = ''.obs; RxString startTime = ''.obs;
RxString endTime = ''.obs; RxString endTime = ''.obs;
RxBool loading = false.obs; RxBool loading = false.obs;
final inventoryInoutController = Get.put(InventoryInoutController()); final inventoryInoutController = Get.find<InventoryInoutController>();
final label = TextEditingController().obs; final label = TextEditingController().obs;
final description = TextEditingController().obs; final description = TextEditingController().obs;
final category = TextEditingController().obs; final category = TextEditingController().obs;

View File

@ -27,28 +27,7 @@ class AppInfoService extends GetxService {
final scale = RxDouble(1.0); final scale = RxDouble(1.0);
final isLarge = RxBool(false); final isLarge = RxBool(false);
final isCameraing = RxBool(false); final isCameraing = RxBool(false);
List<AppBottomNavItem>? bottomNavItems = [
AppBottomNavItem(
icon: Icons.home_max_outlined,
activeIcon: Icons.home_max_outlined,
label: '登记',
page: InvenotryInoutPage()),
AppBottomNavItem(
icon: Icons.inventory_outlined,
activeIcon: Icons.inventory_rounded,
label: '库存',
page: InventoryPage()),
AppBottomNavItem(
icon: Icons.widgets_outlined,
activeIcon: Icons.widgets_rounded,
label: '工作台',
page: WorkBenchPage()),
AppBottomNavItem(
icon: Icons.person_outline_outlined,
activeIcon: Icons.person,
label: '我的',
page: MinePage()),
];
Future<AppInfoService> init() async { Future<AppInfoService> init() async {
LoggerUtil() LoggerUtil()
.info("[service-appInfo] Register app-related information service"); .info("[service-appInfo] Register app-related information service");

View File

@ -62,9 +62,7 @@ class DioService extends Get.GetxService {
e.response?.data['message'], e.response?.data['message'],
); );
} else if (e.response?.statusCode == 401) { } else if (e.response?.statusCode == 401) {
await SnackBarUtil().error( await SnackBarUtil().error('请重新登录');
'Your role at this season has been updated. Please log in again.',
);
// dio.lock(); // dio.lock();
LoggerUtil().error('[Service-dio] logout:${e.response}'); LoggerUtil().error('[Service-dio] logout:${e.response}');
await AuthStore().logout(force: true); await AuthStore().logout(force: true);

View File

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:dio/dio.dart' as Dio; import 'package:dio/dio.dart' as Dio;
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:sk_base_mobile/apis/index.dart'; import 'package:sk_base_mobile/apis/index.dart';
import 'package:sk_base_mobile/store/dict.store.dart';
import 'package:sk_base_mobile/util/logger_util.dart'; import 'package:sk_base_mobile/util/logger_util.dart';
import 'package:sk_base_mobile/widgets/tap_to_dismiss_keyboard.dart'; import 'package:sk_base_mobile/widgets/tap_to_dismiss_keyboard.dart';
import 'package:sk_base_mobile/models/auth.dart'; import 'package:sk_base_mobile/models/auth.dart';
@ -11,7 +12,7 @@ import 'package:sk_base_mobile/services/service.dart';
import '../constants/constants.dart'; import '../constants/constants.dart';
import '../util/util.dart'; import '../util/util.dart';
class AuthStore extends GetxController { class AuthStore extends GetxService {
static AuthStore get to => Get.find(); static AuthStore get to => Get.find();
final userInfo = UserInfoModel().obs; final userInfo = UserInfoModel().obs;
@ -59,8 +60,10 @@ class AuthStore extends GetxController {
// final response = await Api.logout(); // final response = await Api.logout();
// if (response.data != null) { // if (response.data != null) {
LoggerUtil().info('[Store-Auth] Logout succeed.'); LoggerUtil().info('[Store-Auth] Logout succeed.');
Get.offAllNamed(RouteConfig.login); // login界面
// } if (Get.currentRoute != RouteConfig.login) {
Get.offAllNamed(RouteConfig.login);
}
} catch (e) { } catch (e) {
print(e); print(e);
} finally { } finally {
@ -92,7 +95,7 @@ class AuthStore extends GetxController {
} }
await getUserInfo(); await getUserInfo();
Get.offNamed(RouteConfig.home); Get.offNamed(RouteConfig.home);
// getCommonInfo(); getCommonInfo();
} }
} catch (e) { } catch (e) {
await SnackBarUtil().error('账号密码错误'); await SnackBarUtil().error('账号密码错误');
@ -141,6 +144,8 @@ class AuthStore extends GetxController {
Future<void> getCommonInfo() async { Future<void> getCommonInfo() async {
await AppInfoService.to.getAppConfig(); await AppInfoService.to.getAppConfig();
await Future.wait([ await Future.wait([
DictService.to.getDictTypes()
/// ///
// Get.putAsync<BlockStore>(() => BlockStore().init()), // Get.putAsync<BlockStore>(() => BlockStore().init()),
]); ]);

View File

@ -4,6 +4,7 @@ import 'package:sk_base_mobile/constants/dict_enum.dart';
import 'package:sk_base_mobile/models/dict_item.model.dart'; import 'package:sk_base_mobile/models/dict_item.model.dart';
import 'package:sk_base_mobile/models/dict_type.model.dart'; import 'package:sk_base_mobile/models/dict_type.model.dart';
import 'package:sk_base_mobile/apis/index.dart'; import 'package:sk_base_mobile/apis/index.dart';
import 'package:sk_base_mobile/store/auth.store.dart';
import 'package:sk_base_mobile/util/logger_util.dart'; import 'package:sk_base_mobile/util/logger_util.dart';
const needCachedKey = [ const needCachedKey = [
@ -13,7 +14,9 @@ const needCachedKey = [
]; ];
class DictService extends GetxService { class DictService extends GetxService {
static DictService get to => Get.find();
Future<DictService> init() async { Future<DictService> init() async {
if (AuthStore.to.userInfo.value.id == null) return this;
await getDictTypes(); await getDictTypes();
return this; return this;
} }

View File

@ -35,12 +35,12 @@ class BottomNavBar extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon( Icon(
AppInfoService.to.bottomNavItems![index].icon, controller.bottomNavItems![index].icon,
size: ScreenAdaper.sp(40), size: ScreenAdaper.sp(40),
color: color, color: color,
), ),
AutoSizeText( AutoSizeText(
AppInfoService.to.bottomNavItems![index].label ?? '', controller.bottomNavItems![index].label ?? '',
maxLines: 1, maxLines: 1,
style: TextStyle(color: color, fontSize: ScreenAdaper.sp(20)), style: TextStyle(color: color, fontSize: ScreenAdaper.sp(20)),
group: autoSizeGroup, group: autoSizeGroup,