100 lines
3.2 KiB
Dart
100 lines
3.2 KiB
Dart
/*
|
|
* @Author: wangyang 1147192855@qq.com
|
|
* @Date: 2022-06-15 17:58:30
|
|
* @LastEditors: wangyang 1147192855@qq.com
|
|
* @LastEditTime: 2022-08-03 11:53:08
|
|
* @FilePath: \marking_app\lib\main.dart
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
*/
|
|
import 'dart:async';
|
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:marking_app/utils/index.dart';
|
|
import 'package:marking_app/utils/the_global.dart';
|
|
import 'package:marking_app/routes/RouterManager.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
void main() {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
RouterManager.initRouter();
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
|
overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]); // 屏幕刘海
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); // 屏幕强制竖屏
|
|
// OrientationHelper.setEnabledSystemUIOverlays(SystemUiOverlay.values);
|
|
|
|
runApp(ProviderScope(child: MyApp()));
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
late final StreamSubscription<ConnectivityResult> subscription;
|
|
late bool networkSituation = true; // 网络情况
|
|
@override
|
|
void initState() {
|
|
networkMonitoring();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
subscription.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
/// 网络监控
|
|
void networkMonitoring() async {
|
|
subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
|
|
if (ConnectivityResult.none == result) {
|
|
ToastUtils.showInfo('无法连接网络');
|
|
networkSituation = false;
|
|
} else {
|
|
if (!networkSituation) {
|
|
if (ConnectivityResult.mobile == result) {
|
|
ToastUtils.showInfo('当前为移动网络,请注意网络使用情况', duration: const Duration(milliseconds: 500));
|
|
} else {
|
|
ToastUtils.showSuccess('网络恢复正常');
|
|
}
|
|
}
|
|
networkSituation = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ScreenUtilInit(
|
|
designSize: const Size(375, 812),
|
|
minTextAdapt: true,
|
|
splitScreenMode: true,
|
|
builder: (context1, child) {
|
|
return MaterialApp(
|
|
title: '远轩阅卷系统',
|
|
navigatorKey: TheGlobal.navigatorKey,
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
primarySwatch: createMaterialColor(const Color.fromRGBO(46, 91, 255, 1)),
|
|
// textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp,),
|
|
textTheme: TextTheme(
|
|
bodyLarge: TextStyle(fontSize: 14.sp, color: Colors.black87),
|
|
),
|
|
),
|
|
onGenerateRoute: RouterManager.generator, //全局注册
|
|
builder: EasyLoading.init(),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|