konguele
konguele

Reputation: 3

My app in Dart is not able to select languages properly

I hope you can help me. I am developing an app in Dart with Flutter from Visual Studio.

I've added some languages and in one language I'm getting the following error, the rest works correctly. I have added some parts of the code where I think the problem lies, if you need me to add anything else, let me know:

    ════════ Exception caught by widgets ═══════════════════════════════════════════
The following message was thrown:
Warning: This application's locale, ga, is not supported by all of its localization delegates.

• A MaterialLocalizations delegate that supports the ga locale was not found.
• A CupertinoLocalizations delegate that supports the ga locale was not found.

The declared supported locales for this app are: es, ca, eu, ga, en, fr, it, de

See https://flutter.dev/to/internationalization/ for more information about configuring an app's locale, supportedLocales, and localizationsDelegates parameters.

════════ Exception caught by widgets library ═══════════════════════════════════
Looking up a deactivated widget's ancestor is unsafe.
The relevant error-causing widget was:
    MaterialApp MaterialApp:file:///C:/Users/kol69/myapp/lib/main.dart:52:12
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
No MaterialLocalizations found.
The ancestors of this widget were:
    : Scaffold
        dependencies: [Directionality, InheritedCupertinoTheme, MediaQuery, UnmanagedRestorationScope, _InheritedTheme, _LocalizationsScope-[GlobalKey#fa09e], _ScaffoldMessengerScope]
        state: ScaffoldState#7fb38(tickers: tracking 2 tickers)
    : HomePage
        dependencies: [MediaQuery, _LocalizationsScope-[GlobalKey#fa09e]]
        state: _HomePageState#e4134
    : MaterialApp
        state: _MaterialAppState#e27ca
    : MoneyfyApp
        state: _MoneyfyAppState#8e2e3
    ...
The relevant error-causing widget was:
    AppBar AppBar:file:///C:/Users/kol69/myapp/lib/screens/home_page.dart:288:15
════════════════════════════════════════════════════════════════════════════════

According to the error the problem is on line 288 of home_page.dart which is the following: AppBar AppBar:file:///C:/Users/kol69/myapp/lib/screens/home_page.dart:288:15

  return Scaffold(
  appBar: AppBar(
    title: Text(AppLocalizations.of(context)?.appTitle ?? 'MyApp'), // Usar traducción
    actions: [
      custom.CustomDropdownMenu(
        isLoggedIn: widget.isLoggedIn, // Usar el valor de isLoggedIn
        username: widget.username, // Usar el valor de username
        changeLanguage: widget.changeLanguage, // Pasar la función changeLanguage
      ),
    ],
  ),

It also indicates line 52 of main.dart: MaterialApp MaterialApp:file:///C:/Users/kol69/myapp/lib/main.dart:52:12

    @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Myapp', // Cambiado a 'Myapp'
      theme: ThemeData(
        primaryColor: Color(0xFF3A0CA3),
        scaffoldBackgroundColor: Color(0xFFF7F7F7),
        // Configurar la fuente Libre Baskerville como fuente predeterminada
        fontFamily: 'LibreBaskerville', // Nombre de la familia de fuentes definida en pubspec.yaml
        textTheme: TextTheme(
          displayLarge: TextStyle(fontSize: 32.0, fontWeight: FontWeight.bold),
          displayMedium: TextStyle(fontSize: 28.0, fontWeight: FontWeight.bold),
          displaySmall: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
          headlineMedium: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
          headlineSmall: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
          titleLarge: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),
          bodyLarge: TextStyle(fontSize: 16.0),
          bodyMedium: TextStyle(fontSize: 14.0),
          bodySmall: TextStyle(fontSize: 12.0),
        ),
      ),
      home: HomePage(
        isLoggedIn: false,
        username: '',
        changeLanguage: _changeLanguage, // Pasar la función _changeLanguage
      ),
      // Configurar localizaciones
      localizationsDelegates: [
        AppLocalizationsDelegate(), // Delegado personalizado para AppLocalizations
        GlobalMaterialLocalizations.delegate, // Delegado para Material Localizations
        GlobalWidgetsLocalizations.delegate, // Delegado para Widgets Localizations
        GlobalCupertinoLocalizations.delegate, // Delegado para Cupertino Localizations
      ],
      supportedLocales: [
        Locale('es', ''), // Spanish
        Locale('ca', ''), // Catalan
        Locale('eu', ''), // Euskera
        Locale('ga', ''), // Galego
        Locale('en', ''), // English
        Locale('fr', ''), // Français
        Locale('it', ''), // Italiano
        Locale('de', ''), // Deustch
      ],

Upvotes: 0

Views: 38

Answers (2)

JTO Informatique
JTO Informatique

Reputation: 45

The Galego language "ga" is not supported by Flutter. See this page to find all supported languages:

https://api.flutter.dev/flutter/flutter_localizations/GlobalMaterialLocalizations-class.html

Upvotes: 1

Ivo
Ivo

Reputation: 23277

The list of delegates at localizationsDelegates must support all languages mentioned at supportedLocales.

The error states that both MaterialLocalizations and CupertinoLocalizations don't support the ga locale so you are not allowed to use them.

So you are not allowed to use GlobalMaterialLocalizations.delegate and GlobalCupertinoLocalizations.delegate.

You can read more about how to support a locale that is not supported here:

https://api.flutter.dev/flutter/material/MaterialApp/localizationsDelegates.html

Upvotes: 1

Related Questions