基础组件库
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.
 
 
 
 
 

150 lines
4.8 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. import 'package:zhiying_member_upgrade/register.dart';
  21. import 'package:zhiying_equity_card/zhiying_equity_card.dart';
  22. import 'package:zhiying_official/register.dart';
  23. import 'package:zhiying_base_widget/zhiying_base_widget.dart';
  24. import 'package:zhiying_acquisition/register.dart';
  25. void main() {
  26. FlutterError.onError = (FlutterErrorDetails details) {
  27. FlutterError.dumpErrorToConsole(details);
  28. print(details.exceptionAsString());
  29. // if (kReleaseMode) exit(1);
  30. };
  31. runApp(MyApp());
  32. }
  33. class MyApp extends StatefulWidget {
  34. @override
  35. _MyAppState createState() => _MyAppState();
  36. }
  37. class _MyAppState extends State<MyApp> {
  38. Widget getErrorWidget(BuildContext context, FlutterErrorDetails error) {
  39. var erroStr = '';
  40. const bool inProduction = const bool.fromEnvironment("dart.vm.product");
  41. if (!inProduction) {
  42. erroStr = error.exceptionAsString();
  43. }
  44. return Center(
  45. child: Text(
  46. "" + erroStr,
  47. style: Theme
  48. .of(context)
  49. .textTheme
  50. .title
  51. .copyWith(color: Colors.grey[200]),
  52. ),
  53. );
  54. }
  55. @override
  56. void initState() {
  57. super.initState();
  58. print('初始化~~~~');
  59. BaseWidgetRegister.init();
  60. BusinessCollageRegister.init();
  61. NewUserFreeRegister.init();
  62. WeChatTeachRegister.init();
  63. FriendCircleRegister.init();
  64. MemberUpgradeRegister.init();
  65. EquityCardRegister.init();
  66. OfficialRegister.init();
  67. AcquisitionRegister.init();
  68. print('初始化百川');
  69. FlutterAlibc.initAlibc(version: "", appName: "").then((result) {
  70. print("白川" + '${result.errorCode} ${result.errorMessage}');
  71. });
  72. MobPushUtil.setCanPush();
  73. EventUtil.instance.on().listen((event) {});
  74. const bool inProduction = const bool.fromEnvironment("dart.vm.product");
  75. if (!inProduction) {
  76. //debug app不更新 app更新插件
  77. AppUpdateUtil.initXUpdate();
  78. }
  79. }
  80. @override
  81. Widget build(BuildContext context) {
  82. ErrorWidget.builder = (FlutterErrorDetails errorDetails) {
  83. return getErrorWidget(context, errorDetails);
  84. };
  85. return MultiProvider(
  86. providers: [
  87. ChangeNotifierProvider.value(value: UserInfoNotifier()),
  88. ],
  89. child: GestureDetector(
  90. onTap: () {
  91. FocusScopeNode currentFocus = FocusScope.of(context);
  92. if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
  93. FocusManager.instance.primaryFocus.unfocus();
  94. }
  95. },
  96. child: MaterialApp(
  97. builder: (context, child) {
  98. return MediaQuery(
  99. //设置文字大小不随系统设置改变
  100. data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
  101. child: child,
  102. );
  103. },
  104. theme: ThemeData(
  105. fontFamily: 'PingFang',
  106. primaryColor: HexColor.fromHex('#FF4242'),
  107. accentColor: HexColor.fromHex('#FF4242'),
  108. ),
  109. routes: <String, WidgetBuilder>{
  110. '/homePage': (BuildContext context) => HomeCenterPage(),
  111. },
  112. navigatorKey: navigatorKey,
  113. localizationsDelegates: [
  114. RefreshLocalizations.delegate,
  115. GlobalMaterialLocalizations.delegate,
  116. GlobalWidgetsLocalizations.delegate,
  117. CommonLocalizationsDelegate(),
  118. ],
  119. supportedLocales: [
  120. const Locale('en'),
  121. const Locale('zh'),
  122. ],
  123. localeResolutionCallback: (Locale locale, Iterable<Locale> supportedLocales) {
  124. print("change language ${locale.toString()}");
  125. return locale;
  126. },
  127. home: LaunchPage(
  128. // builder: (context) => HomePage(),
  129. ),
  130. ),
  131. ),
  132. );
  133. }
  134. }
  135. // FocusScopeNode currentFocus = FocusScope.of(context);
  136. // if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
  137. // FocusManager.instance.primaryFocus.unfocus();
  138. // }