123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import 'package:common_project/common_project.dart';
- import 'package:common_project/config/app_info.dart';
- import 'package:common_project/public_view_model/locale_cubit.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_desktop_app/init.dart';
- import 'package:flutter_desktop_app/page/splash_page.dart';
- import 'package:flutter_localizations/flutter_localizations.dart';
- import 'package:module_login/view/login_index_page.dart';
- import 'package:devicelocale/devicelocale.dart' as H;
- import 'package:common_project/generated/l10n.dart' as D;
- void main() async{
- await GetStorage.init();
- MainInit.init();
- MainInit.routerInit();
- MainInit.requestInit();
- MainInit.rongrunInit();
- runApp(MainInit.getGlobalBloc(MyApp()));
- }
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return FutureBuilder(
- future: H.Devicelocale.currentAsLocale,
- builder: (context,snapshot){
- Locale deviceLocale = (snapshot.connectionState == ConnectionState.done && snapshot.hasData ?
- snapshot.data : Locale.fromSubtags(languageCode: 'en')) as Locale;
- if(snapshot.hasError) {
- print(snapshot.error);
- }
- // Default to en on unsupported locales
- if (!D.S.delegate.isSupported(deviceLocale)) {
- deviceLocale = Locale.fromSubtags(languageCode: 'en', countryCode: deviceLocale.countryCode);
- }
- return BlocProvider<LocaleCubit>(
- create: (BuildContext context) => LocaleCubit(deviceLocale),
- key: ObjectKey(deviceLocale), // Recreate on deviceLocale change. On refresh.
- child: BlocBuilder<LocaleCubit, Locale>(
- builder: (context, locale) =>
- Builder(builder: (context){
- context.select((LocaleCubit bloc) => bloc.state.languageCode);
- return ScreenUtilInit(
- designSize: Size(AppConfig.INIT_WINDOWS_WIDTH, AppConfig.INIT_WINDOWS_HEIGHT),
- // allowFontScaling: false,
- builder: (context,widget)=> MaterialApp(
- navigatorKey: GlobalConstKey.navigatorKey,
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- visualDensity: VisualDensity.adaptivePlatformDensity,
- ),
- locale: locale,
- home: WelcomeIndexPage(),
- // builder: FlutterSmartDialog.init(builder: (context, child) => Scaffold(
- // body: GestureDetector(
- // onTap: () {
- // FocusScopeNode currentFocus = FocusScope.of(context);
- // if (!currentFocus.hasPrimaryFocus &&
- // currentFocus.focusedChild != null) {
- // FocusManager.instance.primaryFocus!.unfocus();
- // }
- // },
- // child: child,
- // ),
- // resizeToAvoidBottomInset: false,
- // )),
- //全局 点击空白处收回键盘
- builder: (context, child) => Scaffold(
- body: GestureDetector(
- onTap: () {
- FocusScopeNode currentFocus = FocusScope.of(context);
- if (!currentFocus.hasPrimaryFocus &&
- currentFocus.focusedChild != null) {
- FocusManager.instance.primaryFocus!.unfocus();
- }
- },
- child: child,
- ),
- resizeToAvoidBottomInset: false,
- ),
- localizationsDelegates: [
- D.S.delegate,
- GlobalCupertinoLocalizations.delegate,
- GlobalMaterialLocalizations.delegate,
- GlobalWidgetsLocalizations.delegate
- ],
- supportedLocales: D.S.delegate.supportedLocales,
- ),
- );
- }),
- )
- );
- },
- );
- }
- }
|