|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:get/get_navigation/src/root/get_material_app.dart';
|
|
|
|
import 'package:get_storage/get_storage.dart';
|
|
|
|
import 'package:problem_check_system/app/routes/app_pages.dart';
|
|
|
|
import 'package:problem_check_system/app/routes/app_routes.dart'; // 导入路由常量
|
|
|
|
import 'package:problem_check_system/app/bindings/initial_binding.dart';
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
// 确保 Flutter Binding 已初始化
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// 设置应用为竖屏模式
|
|
|
|
SystemChrome.setPreferredOrientations([
|
|
|
|
DeviceOrientation.portraitUp,
|
|
|
|
DeviceOrientation.portraitDown,
|
|
|
|
]);
|
|
|
|
// 初始化 GetStorage,这是关键步骤
|
|
|
|
await GetStorage.init();
|
|
|
|
// Add this line
|
|
|
|
await ScreenUtil.ensureScreenSize();
|
|
|
|
|
|
|
|
runApp(const MainApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MainApp extends StatelessWidget {
|
|
|
|
const MainApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
// 填入设计稿中设备的屏幕尺寸, 单位dp
|
|
|
|
return ScreenUtilInit(
|
|
|
|
designSize: const Size(375, 812),
|
|
|
|
minTextAdapt: true,
|
|
|
|
splitScreenMode: true,
|
|
|
|
builder: (context, _) {
|
|
|
|
// 使用 _ 忽略 child 参数
|
|
|
|
return GetMaterialApp(
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
// --- 关键配置 ---
|
|
|
|
localizationsDelegates: const [
|
|
|
|
// 必需:用于 Material 组件库的本地化
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
// 必需:用于 Widgets 库的本地化
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
// 必需:用于 iOS 风格组件的本地化
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
],
|
|
|
|
supportedLocales: const [
|
|
|
|
Locale('zh', 'CN'), // 支持中文
|
|
|
|
],
|
|
|
|
title: '问题检查系统', // 使用更有意义的应用标题
|
|
|
|
theme: ThemeData(
|
|
|
|
useMaterial3: true,
|
|
|
|
|
|
|
|
// 【推荐】使用 colorSchemeSeed 从一个种子颜色生成完整的 M3 调色板
|
|
|
|
colorScheme: ColorScheme.fromSeed(
|
|
|
|
seedColor: const Color(0xFF3B82F6),
|
|
|
|
),
|
|
|
|
|
|
|
|
// (可选) 如果想进一步定制 NavigationBar 的主题
|
|
|
|
navigationBarTheme: NavigationBarThemeData(
|
|
|
|
// 1. 在主题中设置你想要的高度
|
|
|
|
height: 48, // 比如我们想让它更高,设置为 70
|
|
|
|
// 2. 【关键】增大图标尺寸,让内容撑满新高度
|
|
|
|
// 使用 MaterialStateProperty.resolveWith 来响应不同状态(如下拉、聚焦等)
|
|
|
|
iconTheme: WidgetStateProperty.resolveWith((states) {
|
|
|
|
// 你可以根据状态返回不同的 IconThemeData
|
|
|
|
return IconThemeData(
|
|
|
|
size: 24, // 将图标大小从默认的 24 增大到 28
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
// 标签行为:控制标签是否总是显示
|
|
|
|
labelBehavior:
|
|
|
|
NavigationDestinationLabelBehavior.onlyShowSelected,
|
|
|
|
// backgroundColor: Colors.white,
|
|
|
|
// 指示器的颜色
|
|
|
|
indicatorColor: const Color.fromARGB(88, 19, 214, 12),
|
|
|
|
// 【核心】使用 indicatorShape 属性并传入我们的自定义类
|
|
|
|
// indicatorShape: const CustomIndicatorShape(
|
|
|
|
// // 在这里调整你想要的宽度
|
|
|
|
// // horizontalPadding: 24.0, // 让指示器变得更窄
|
|
|
|
// // horizontalPadding: 8.0, // 让指示器变得更宽
|
|
|
|
// horizontalPadding: 0, // 让指示器宽度接近内容宽度
|
|
|
|
// ),
|
|
|
|
// 标签文本样式
|
|
|
|
labelTextStyle: WidgetStateProperty.all(
|
|
|
|
TextStyle(
|
|
|
|
fontSize: 12.sp,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
color: Colors.blue,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// 仅使用 GetX 路由系统
|
|
|
|
initialRoute: AppRoutes.login, // 使用路由常量作为初始页面
|
|
|
|
initialBinding: InitialBinding(), // 如果有全局绑定,继续保留
|
|
|
|
getPages: AppPages.routes, // 绑定所有路由
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|