88 lines
2.5 KiB
Dart
88 lines
2.5 KiB
Dart
import 'package:flutter_localizations/flutter_localizations.dart';
|
||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||
import 'package:get_storage/get_storage.dart';
|
||
import 'package:getx_scaffold/getx_scaffold.dart';
|
||
import 'package:ln_jq_app/common/model/base_model.dart';
|
||
import 'package:ln_jq_app/common/token_interceptor.dart';
|
||
import 'package:ln_jq_app/storage_service.dart';
|
||
|
||
import 'common/styles/theme.dart';
|
||
import 'pages/home/view.dart';
|
||
import 'pages/login/view.dart';
|
||
|
||
void main() async {
|
||
WidgetsFlutterBinding.ensureInitialized();
|
||
|
||
WidgetsBinding widgetsBinding = await init(
|
||
isDebug: false,
|
||
logTag: '小羚羚',
|
||
supportedLocales: [Locale('zh', 'CN')],
|
||
);
|
||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
||
|
||
await GetStorage.init();
|
||
await Get.putAsync(() => StorageService().init());
|
||
|
||
initHttpSet();
|
||
|
||
runApp(
|
||
GetxApp(
|
||
// 设计稿尺寸 单位:dp
|
||
designSize: const Size(390, 844),
|
||
// Getx Log
|
||
enableLog: false,
|
||
// 默认的跳转动画
|
||
defaultTransition: Transition.rightToLeft,
|
||
// 主题模式
|
||
themeMode: GlobalService.to.themeMode,
|
||
// 主题
|
||
theme: AppTheme.light,
|
||
// Dark主题
|
||
darkTheme: AppTheme.dark,
|
||
// AppTitle
|
||
title: '小羚羚',
|
||
// 首页入口
|
||
home: HomePage(),
|
||
//组件国际化
|
||
fallbackLocale: Locale('zh', 'CN'),
|
||
supportedLocales: [Locale('zh', 'CN')],
|
||
localizationsDelegates: const [
|
||
GlobalMaterialLocalizations.delegate,
|
||
GlobalWidgetsLocalizations.delegate,
|
||
GlobalCupertinoLocalizations.delegate,
|
||
],
|
||
|
||
// Builder
|
||
builder: (context, widget) {
|
||
// do something....
|
||
return widget!;
|
||
},
|
||
),
|
||
);
|
||
}
|
||
|
||
void initHttpSet() {
|
||
// 设置基础 URL
|
||
HttpService.to.setBaseUrl(AppTheme.test_service_url);
|
||
//指定请求头
|
||
HttpService.to.dio.interceptors.add(TokenInterceptor(tokenKey: 'asoco-token'));
|
||
// 设置全局响应处理器
|
||
HttpService.to.setOnResponseHandler((response) async {
|
||
try {
|
||
final baseModel = BaseModel<dynamic>.fromJson(response.data);
|
||
if (baseModel.code == 0 || baseModel.code == 200) {
|
||
return null;
|
||
} else if (baseModel.code == 401) {
|
||
await StorageService.to.clearLoginInfo();
|
||
Get.offAll(() => LoginPage());
|
||
return baseModel.message;
|
||
} else {
|
||
return baseModel.message;
|
||
}
|
||
} on Exception catch (e) {
|
||
e.printInfo();
|
||
return '服务器异常';
|
||
}
|
||
});
|
||
}
|