使用多提供程序颤振进行本地化,显示没有此类方法错误



当我尝试在颤振中使用提供程序进行本地化时,它没有显示这样的方法错误。

我也使用提供程序使用谷歌和fb以及电子邮件身份验证进行身份验证,但同时我还需要在应用程序中实现本地化,如下所示。

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:rewahub/AppLanguage.dart';
import 'package:rewahub/locator.dart';
import 'package:rewahub/models/auth_model.dart';
import 'app_localizations.dart';
import 'views/login_page.dart';
import 'views/main_page.dart';
void main() async{
  AppLanguagemodel appLanguagemodel = AppLanguagemodel();
  await appLanguagemodel.fetchLocale();
  setupLocator();
  runApp(MyApp(appLanguagemodel:appLanguagemodel,));
}
class MyApp extends StatelessWidget {
  final AppLanguagemodel appLanguagemodel;
  MyApp({this.appLanguagemodel});
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
         builder: (_) => appLanguagemodel,
         child: Consumer<AppLanguagemodel>(builder: (context, appmodel, child) {
        return MaterialApp(
          //locale: model.fetchLocale(),
          locale: appmodel.appLocal,
          supportedLocales: [
            Locale('en', 'US'),
            Locale('ar', ''),
          ],
          localizationsDelegates: [
           AppLocalizations.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
          home: LogInPage(),
        );
      }),
        ),
   ChangeNotifierProvider(builder: (_) => locator<AuthModel>()),
      ],

      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        // initialRoute: '/',
        //onGenerateRoute: Router.generateRoute,
        home: ScreensController(),
      ),
    );
  }
}
class ScreensController extends StatelessWidget {
  final StreamController<bool> _verificationNotifier =

  @override
  Widget build(BuildContext context) {
   final user = Provider.of<AuthModel>(context);
    switch (user.status) {
      case Status.Unauthenticated:
       // return LanguageSelect();
      case Status.Authenticating:
        return LogInPage();
      case Status.Authenticated:
        return MainPage();
      default:
        return LogInPage();
    }
  }
}

它会像

  runApp(MultiProvider(
  providers: [
    ChangeNotifierProvider.value(value: CurrentData()),
    ChangeNotifierProvider.value(value: AppProvider()),
    ChangeNotifierProvider.value(value: UserProvider.initialize()),
  ],
 child:  Consumer<CurrentData>(
   builder: (context, provider, child) => MaterialApp(
     debugShowCheckedModeBanner: false,
     //title: 'Flutter App Localization with Provider demo',
     locale: Provider.of<CurrentData>(context).locale,
     home: ScreensController(),
     localizationsDelegates: [
       const AppLocalizationDelegate(),
       GlobalMaterialLocalizations.delegate,
       GlobalWidgetsLocalizations.delegate,
     ],
     supportedLocales: [
       const Locale('en'),
       const Locale('ar'),
       const Locale('fr'),
       const Locale('es'),
       const Locale('ru'),
     ],
   ),
 ),
 ));

相关内容

  • 没有找到相关文章

最新更新