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

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