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:get/get.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/app_theme.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
@ -18,6 +20,8 @@ class IndexPage extends StatelessWidget {
Widget build(BuildContext context) {
final isLandscape =
MediaQuery.of(context).orientation == Orientation.landscape;
final isLogin =
StorageService.to.getString(CacheKeys.token, isWithUser: false) != null;
return ScreenUtilInit(
minTextAdapt: true,
designSize: isLandscape
@ -35,7 +39,6 @@ class IndexPage extends StatelessWidget {
title: GloablConfig.DOMAIN_NAME,
getPages: RouteConfig.getPages,
initialRoute: getInitialRoute(),
// initialRoute: RouteConfig.onboarding,
debugShowCheckedModeBanner: false,
builder: (_, widget) {
return Obx(() => MediaQuery(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,15 +1,41 @@
import 'package:flutter/material.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';
class LandingController extends GetxController {
RxInt currentIndex = 0.obs;
RxBool showCreateBtn = true.obs;
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
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 {
CategoryInput({super.key});
final controller = Get.put(NewInventoryInoutController());
final controller = Get.find<NewInventoryInoutController>();
@override
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 {
DateTimeInput({super.key});
final controller = Get.put(NewInventoryInoutController());
final controller = Get.find<NewInventoryInoutController>();
@override
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';
class DescriptionInput extends StatelessWidget {
final controller = Get.put(NewInventoryInoutController());
final controller = Get.find<NewInventoryInoutController>();
DescriptionInput({super.key});
@override
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 {
SelectImageList({super.key});
final controller = Get.put(NewInventoryInoutController());
final controller = Get.find<NewInventoryInoutController>();
@override
Widget build(BuildContext context) {
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 {
LabelInput({super.key});
final controller = Get.put(NewInventoryInoutController());
final controller = Get.find<NewInventoryInoutController>();
@override
Widget build(BuildContext context) {
return Padding(

View File

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

View File

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

View File

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

View File

@ -27,28 +27,7 @@ class AppInfoService extends GetxService {
final scale = RxDouble(1.0);
final isLarge = 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 {
LoggerUtil()
.info("[service-appInfo] Register app-related information service");

View File

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

View File

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:dio/dio.dart' as Dio;
import 'package:get/get.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/widgets/tap_to_dismiss_keyboard.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 '../util/util.dart';
class AuthStore extends GetxController {
class AuthStore extends GetxService {
static AuthStore get to => Get.find();
final userInfo = UserInfoModel().obs;
@ -59,8 +60,10 @@ class AuthStore extends GetxController {
// final response = await Api.logout();
// if (response.data != null) {
LoggerUtil().info('[Store-Auth] Logout succeed.');
Get.offAllNamed(RouteConfig.login);
// }
// login界面
if (Get.currentRoute != RouteConfig.login) {
Get.offAllNamed(RouteConfig.login);
}
} catch (e) {
print(e);
} finally {
@ -92,7 +95,7 @@ class AuthStore extends GetxController {
}
await getUserInfo();
Get.offNamed(RouteConfig.home);
// getCommonInfo();
getCommonInfo();
}
} catch (e) {
await SnackBarUtil().error('账号密码错误');
@ -141,6 +144,8 @@ class AuthStore extends GetxController {
Future<void> getCommonInfo() async {
await AppInfoService.to.getAppConfig();
await Future.wait([
DictService.to.getDictTypes()
///
// 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_type.model.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';
const needCachedKey = [
@ -13,7 +14,9 @@ const needCachedKey = [
];
class DictService extends GetxService {
static DictService get to => Get.find();
Future<DictService> init() async {
if (AuthStore.to.userInfo.value.id == null) return this;
await getDictTypes();
return this;
}

View File

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