基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

133 line
4.0 KiB

  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_alibc/flutter_alibc.dart';
  6. import 'package:flutter_localizations/flutter_localizations.dart';
  7. import 'package:provider/provider.dart';
  8. import 'package:pull_to_refresh/pull_to_refresh.dart';
  9. import 'package:zhiying_base_widget/pages/home_page/home_page.dart';
  10. import 'package:zhiying_base_widget/pages/launch_page/launch_page.dart';
  11. import 'package:zhiying_base_widget/register.dart';
  12. import 'package:zhiying_comm/util/update/app_update_util.dart';
  13. import 'package:zhiying_comm/zhiying_comm.dart';
  14. import 'util/localizations_delegate.dart';
  15. import 'package:zhiying_base_widget/utils/mob_push_util.dart';
  16. import 'package:zhiying_business_college/register.dart';
  17. import 'package:zhiying_new_user_free/register.dart';
  18. import 'package:zhiying_wechat_teacher/register.dart';
  19. import 'package:zhiying_moments/register.dart';
  20. void main() {
  21. FlutterError.onError = (FlutterErrorDetails details) {
  22. FlutterError.dumpErrorToConsole(details);
  23. print(details.exceptionAsString());
  24. // if (kReleaseMode) exit(1);
  25. };
  26. runApp(MyApp());
  27. }
  28. class MyApp extends StatefulWidget {
  29. @override
  30. _MyAppState createState() => _MyAppState();
  31. }
  32. class _MyAppState extends State<MyApp> {
  33. Widget getErrorWidget(BuildContext context, FlutterErrorDetails error) {
  34. var erroStr='';
  35. const bool inProduction = const bool.fromEnvironment("dart.vm.product");
  36. if ( !inProduction) {
  37. erroStr=error.exceptionAsString();
  38. }
  39. return Center(
  40. child: Text(
  41. "走神了~"+erroStr,
  42. style: Theme
  43. .of(context)
  44. .textTheme
  45. .title
  46. .copyWith(color: Colors.redAccent),
  47. ),
  48. );
  49. }
  50. @override
  51. void initState() {
  52. super.initState();
  53. print('初始化~~~~');
  54. BaseWidgetRegister.init();
  55. BusinessCollageRegister.init();
  56. NewUserFreeRegister.init();
  57. WeChatTeachRegister.init();
  58. FriendCircleRegister.init();
  59. print('初始化百川');
  60. FlutterAlibc.initAlibc(version: "", appName: "").then((result) {
  61. print("白川" + '${result.errorCode} ${result.errorMessage}');
  62. });
  63. MobPushUtil.setCanPush();
  64. // app更新插件
  65. AppUpdateUtil.initXUpdate();
  66. }
  67. @override
  68. Widget build(BuildContext context) {
  69. ErrorWidget.builder = (FlutterErrorDetails errorDetails) {
  70. return getErrorWidget(context, errorDetails);
  71. };
  72. return MultiProvider(
  73. providers: [
  74. ChangeNotifierProvider.value(value: UserInfoNotifier()),
  75. ],
  76. child: MaterialApp(
  77. builder: (context,child){
  78. return MediaQuery(
  79. //设置文字大小不随系统设置改变
  80. data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
  81. child: child,
  82. );
  83. },
  84. theme: ThemeData(
  85. fontFamily: 'PingFang',
  86. primaryColor: HexColor.fromHex('#FF4242'),
  87. accentColor: HexColor.fromHex('#FF4242'),
  88. ),
  89. routes: <String, WidgetBuilder>{
  90. '/homePage': (BuildContext context) => HomePage(),
  91. },
  92. navigatorKey: navigatorKey,
  93. localizationsDelegates: [
  94. RefreshLocalizations.delegate,
  95. GlobalMaterialLocalizations.delegate,
  96. GlobalWidgetsLocalizations.delegate,
  97. CommonLocalizationsDelegate(),
  98. ],
  99. supportedLocales: [
  100. const Locale('en'),
  101. const Locale('zh'),
  102. ],
  103. localeResolutionCallback: (Locale locale, Iterable<Locale> supportedLocales) {
  104. print("change language ${locale.toString()}");
  105. return locale;
  106. },
  107. home: GestureDetector(
  108. onTap: () {
  109. FocusScopeNode currentFocus = FocusScope.of(context);
  110. if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
  111. FocusManager.instance.primaryFocus.unfocus();
  112. }
  113. },
  114. child: LaunchPage(
  115. // builder: (context) => HomePage(),
  116. ),
  117. ),
  118. ),
  119. );
  120. }
  121. }