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

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