main.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import 'package:common_project/common_project.dart';
  2. import 'package:common_project/config/app_info.dart';
  3. import 'package:common_project/public_view_model/locale_cubit.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_desktop_app/init.dart';
  6. import 'package:flutter_desktop_app/page/splash_page.dart';
  7. import 'package:flutter_localizations/flutter_localizations.dart';
  8. import 'package:module_login/view/login_index_page.dart';
  9. import 'package:devicelocale/devicelocale.dart' as H;
  10. import 'package:common_project/generated/l10n.dart' as D;
  11. void main() async{
  12. await GetStorage.init();
  13. MainInit.init();
  14. MainInit.routerInit();
  15. MainInit.requestInit();
  16. MainInit.rongrunInit();
  17. runApp(MainInit.getGlobalBloc(MyApp()));
  18. }
  19. class MyApp extends StatelessWidget {
  20. // This widget is the root of your application.
  21. @override
  22. Widget build(BuildContext context) {
  23. return FutureBuilder(
  24. future: H.Devicelocale.currentAsLocale,
  25. builder: (context,snapshot){
  26. Locale deviceLocale = (snapshot.connectionState == ConnectionState.done && snapshot.hasData ?
  27. snapshot.data : Locale.fromSubtags(languageCode: 'en')) as Locale;
  28. if(snapshot.hasError) {
  29. print(snapshot.error);
  30. }
  31. // Default to en on unsupported locales
  32. if (!D.S.delegate.isSupported(deviceLocale)) {
  33. deviceLocale = Locale.fromSubtags(languageCode: 'en', countryCode: deviceLocale.countryCode);
  34. }
  35. return BlocProvider<LocaleCubit>(
  36. create: (BuildContext context) => LocaleCubit(deviceLocale),
  37. key: ObjectKey(deviceLocale), // Recreate on deviceLocale change. On refresh.
  38. child: BlocBuilder<LocaleCubit, Locale>(
  39. builder: (context, locale) =>
  40. Builder(builder: (context){
  41. context.select((LocaleCubit bloc) => bloc.state.languageCode);
  42. return ScreenUtilInit(
  43. designSize: Size(AppConfig.INIT_WINDOWS_WIDTH, AppConfig.INIT_WINDOWS_HEIGHT),
  44. // allowFontScaling: false,
  45. builder: (context,widget)=> MaterialApp(
  46. navigatorKey: GlobalConstKey.navigatorKey,
  47. title: 'Flutter Demo',
  48. theme: ThemeData(
  49. primarySwatch: Colors.blue,
  50. visualDensity: VisualDensity.adaptivePlatformDensity,
  51. ),
  52. locale: locale,
  53. home: WelcomeIndexPage(),
  54. // builder: FlutterSmartDialog.init(builder: (context, child) => Scaffold(
  55. // body: GestureDetector(
  56. // onTap: () {
  57. // FocusScopeNode currentFocus = FocusScope.of(context);
  58. // if (!currentFocus.hasPrimaryFocus &&
  59. // currentFocus.focusedChild != null) {
  60. // FocusManager.instance.primaryFocus!.unfocus();
  61. // }
  62. // },
  63. // child: child,
  64. // ),
  65. // resizeToAvoidBottomInset: false,
  66. // )),
  67. //全局 点击空白处收回键盘
  68. builder: (context, child) => Scaffold(
  69. body: GestureDetector(
  70. onTap: () {
  71. FocusScopeNode currentFocus = FocusScope.of(context);
  72. if (!currentFocus.hasPrimaryFocus &&
  73. currentFocus.focusedChild != null) {
  74. FocusManager.instance.primaryFocus!.unfocus();
  75. }
  76. },
  77. child: child,
  78. ),
  79. resizeToAvoidBottomInset: false,
  80. ),
  81. localizationsDelegates: [
  82. D.S.delegate,
  83. GlobalCupertinoLocalizations.delegate,
  84. GlobalMaterialLocalizations.delegate,
  85. GlobalWidgetsLocalizations.delegate
  86. ],
  87. supportedLocales: D.S.delegate.supportedLocales,
  88. ),
  89. );
  90. }),
  91. )
  92. );
  93. },
  94. );
  95. }
  96. }