long1eu / flutter_i18n

This plugin create a binding between your translations from .arb files and your Flutter app.
Apache License 2.0
251 stars 55 forks source link

Don't delegated S?? #137

Closed zsanzharko closed 2 years ago

zsanzharko commented 2 years ago

My problem with delegating S, but I wrote in code, like example in Getting Started Localizely

Adding in code

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        S.delegate
      ],
      supportedLocales: S.delegate.supportedLocales,
      onGenerateTitle: (BuildContext context) => "Zholdau",
      title: S.of(context).title,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: S.of(context).title),
    );
  }
}

intl_en.arb

{
  "title" : "Helo"
}

Error exeption

======== Exception caught by widgets library =======================================================
The following assertion was thrown building MyApp(dirty):
No instance of S present in the widget tree. Did you add S.delegate in localizationsDelegates?
'package:zholdau/generated/l10n.dart':
Failed assertion: line 44 pos 12: 'instance != null'

pubspec

Flutter
sdk: ">=2.15.1 <3.0.0"

flutter_intl:
  enabled: true

intl: ^0.17.0
zsanzharko commented 2 years ago

I did not find the problem on the Internet