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

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