132 lines
4.6 KiB
Dart
132 lines
4.6 KiB
Dart
import 'package:easy_refresh/easy_refresh.dart';
|
|
import 'package:flustars_flutter3/flustars_flutter3.dart' hide ScreenUtil;
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
import 'package:dreampad/app/db/db_service.dart';
|
|
import 'package:dreampad/app/lang/translation_service.dart';
|
|
import 'package:dreampad/app/theme/theme_service.dart';
|
|
import 'app/routes/app_pages.dart';
|
|
import 'app/shared/shared.dart';
|
|
|
|
Future<void> main() async {
|
|
// debugProfileBuildsEnabled = true;
|
|
// debugPaintLayerBordersEnabled = true;
|
|
// debugProfilePaintsEnabled = true;
|
|
// debugRepaintRainbowEnabled = true;
|
|
|
|
/// 确保初始化完成
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
SystemChrome.setPreferredOrientations(
|
|
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
|
|
|
|
await ScreenUtil.ensureScreenSize();
|
|
|
|
/// sp初始化
|
|
await SpUtil.getInstance();
|
|
setInitDir(initStorageDir: true);
|
|
await DirectoryUtil.getInstance();
|
|
DirectoryUtil.createStorageDirSync(category: Constant.imgDir);
|
|
DirectoryUtil.createStorageDirSync(category: Constant.dbDir);
|
|
await Device.initDeviceInfo();
|
|
await Get.putAsync(() => DbService().init());
|
|
|
|
EasyRefresh.defaultHeaderBuilder = () => const ClassicHeader(
|
|
processedDuration: Duration.zero,
|
|
showMessage: false,
|
|
showText: true,
|
|
processingText: "加载中...",
|
|
processedText: "加载成功",
|
|
readyText: "加载中...",
|
|
armedText: "释放以加载更多",
|
|
dragText: "下拉加载",
|
|
failedText: "加载失败",
|
|
noMoreText: "没有更多内容",
|
|
);
|
|
SmartDialog.config
|
|
..custom = SmartConfigCustom(
|
|
maskColor: Colors.black.withOpacity(0.35),
|
|
useAnimation: true,
|
|
)
|
|
..attach = SmartConfigAttach(
|
|
animationType: SmartAnimationType.scale,
|
|
usePenetrate: false,
|
|
)
|
|
..loading = SmartConfigLoading(
|
|
clickMaskDismiss: false,
|
|
leastLoadingTime: const Duration(milliseconds: 0),
|
|
)
|
|
..toast = SmartConfigToast(
|
|
intervalTime: const Duration(milliseconds: 100),
|
|
displayTime: const Duration(milliseconds: 3000),
|
|
alignment: Alignment.center,
|
|
clickMaskDismiss: true,
|
|
displayType: SmartToastType.last,
|
|
);
|
|
|
|
runApp(const MyApp());
|
|
|
|
const systemUiOverlayStyle = SystemUiOverlayStyle(
|
|
statusBarColor: Colors.transparent,
|
|
statusBarIconBrightness: Brightness.light,
|
|
);
|
|
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ScreenUtilInit(
|
|
designSize: const Size(1176.0, 649.0),
|
|
minTextAdapt: true,
|
|
splitScreenMode: false,
|
|
builder: (context, child) {
|
|
return GetMaterialApp(
|
|
// showPerformanceOverlay: true, //显示性能标签
|
|
// checkerboardRasterCacheImages: true,
|
|
// showSemanticsDebugger: true, // 显示语义视图
|
|
// checkerboardOffscreenLayers: true, // 检查离屏渲染
|
|
debugShowCheckedModeBanner: false, // 去除右上角debug的标签
|
|
enableLog: true,
|
|
title: "dreampad",
|
|
defaultTransition: Transition.fade,
|
|
initialRoute: AppPages.INITIAL,
|
|
getPages: AppPages.routes,
|
|
smartManagement: SmartManagement.full,
|
|
locale: const Locale('zh', 'CH'),
|
|
localizationsDelegates: const [
|
|
GlobalCupertinoLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
],
|
|
supportedLocales: const [
|
|
Locale('zh', 'CH'),
|
|
],
|
|
translations: TranslationService(),
|
|
theme: ThemeService().getTheme(),
|
|
darkTheme: ThemeService().getTheme(isDarkMode: true),
|
|
themeMode: ThemeService().getThemeMode(),
|
|
navigatorObservers: [FlutterSmartDialog.observer],
|
|
builder: FlutterSmartDialog.init(
|
|
toastBuilder: (msg) => MyToast(msg),
|
|
loadingBuilder: (msg) => MyLoading(msg),
|
|
builder: (context, Widget? child) {
|
|
// 保证文字大小不受手机系统设置影响 https://www.kikt.top/posts/flutter/layout/dynamic-text/
|
|
return MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
|
child: child!,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|