Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no way to use widgets that require localization #53

Closed
maks opened this issue Nov 1, 2021 · 13 comments · Fixed by #103
Closed

no way to use widgets that require localization #53

maks opened this issue Nov 1, 2021 · 13 comments · Fixed by #103
Labels
t: feat New feature or request

Comments

@maks
Copy link

maks commented Nov 1, 2021

I have widgets that make use of Flutters standard localisation mechanism and so require having localizationsDelegates and supportedLocales set on their containing MaterialApp but there is currently no way to do so for the MaterialApp widget that widgetbook uses internally.

@jenshor jenshor added the t: feat New feature or request label Nov 2, 2021
@jenshor
Copy link
Member

jenshor commented Nov 2, 2021

Yes, this is currently not implemented. We'll keep you posted on this issue 👍🏻

@maks
Copy link
Author

maks commented Nov 3, 2021

Thanks @jenshor 👍🏻 , I'll keep an eye out, as currently this is a blocker for me to try using Widgetbook.

@edTheGuy00
Copy link

I simply created a MaterilaApp wrapper widget like:

class TranslationsWrapper extends StatelessWidget {
  final Widget child;
  final String lang;

  const TranslationsWrapper({Key? key, required this.child, required this.lang})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        Translations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      locale: Locale(lang),
      supportedLocales: Translations.delegate.supportedLocales,
      home: child,
    );
  }
}

Which lets me create language specific usecases like:

 useCases: [
          WidgetbookUseCase(
            name: "Main - EN",
            builder: (ctx) {
              return TranslationsWrapper(
                child: OnBoardingScreen(),
                lang: 'en',
              );
            },
          ),
          WidgetbookUseCase(
            name: "Main - JP",
            builder: (ctx) {
              return TranslationsWrapper(
                child: OnBoardingScreen(),
                lang: 'ja',
              );
            },
          )
        ],

@maks
Copy link
Author

maks commented Nov 24, 2021

Thanks @edTheGuy00 I could have sworn I tried wrapping in a MaterialApp initially when I ran into it without sucess, but I just tried again and it does work fine! Though it would be nice to have this fixed in widgetbook so that we dont end up with nested MaterialApp widgets.

@edTheGuy00
Copy link

@maks I agree. I think the best approach would be to provide the localizations to the WidgetBook class and show a language selection on the WidgetBook app bar that allows the user to change their languages. Much better than creating separate UseCases for languages like I did.

@jenshor
Copy link
Member

jenshor commented Nov 24, 2021

@edTheGuy00 that is indeed how we plan to implement this feature, but it will probably take a while since we are currently working on other features. We'll keep you posted on the progress 👍🏻

@daniel-naegele
Copy link

Any ETA on this issue? Or is maybe a PR welcome?

@jenshor
Copy link
Member

jenshor commented Jan 12, 2022

@Butzlabben we currently have no ETA on this feature but a PR is always welcome 💙 If you are planning to work on this please be aware of our CLA

@jenshor
Copy link
Member

jenshor commented Jan 25, 2022

ETA just moved up to next week 🚀

@jenshor
Copy link
Member

jenshor commented Feb 3, 2022

We just fixed this (and many other issues) as a beta release on pub.dev. We are still adjusting the generator to the breaking changes, but the updated generator will likely land next week. Let us know what you think!

@tieorange
Copy link

Guys is there any updates on this?

How do I make it work with localizations?

@jenshor
Copy link
Member

jenshor commented Jul 25, 2022

@tieorange have a look at our documentation regarding localization. If you have issues, let us know within a new issue or via discord.

@tieorange
Copy link

Line #17 fixed an issue for me.
image

@jenshor I guess it will be great to add it to docs here above this line:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: feat New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants