简体   繁体   中英

having an error with context & provider when calling a showSlideDialog

First I have created these Radio Buttons and they are working well

 Widget buildRadioLanguageListTile(
          Languages langvalue, String txt, BuildContext ctx2) {
        return RadioListTile(
            value: langvalue,
            groupValue:
                Provider.of<LanguageProvider>(ctx2, listen: true).currentLang,
            onChanged: (langvalue) =>
                Provider.of<LanguageProvider>(ctx2, listen: false)
                    .changeLanguage(langvalue),
            title: Text(
              txt,
              style: Theme.of(ctx2).textTheme.bodyText1,
            ));
      }


      ListView(
            Column(
         mainAxisSize: MainAxisSize.min, children: <Widget>[
          buildRadioLanguageListTile(
              Languages.English, txt.getTexts("english"), context),
          buildRadioLanguageListTile(
              Languages.Arabic, txt.getTexts("arabic"), context),
          buildRadioLanguageListTile(
              Languages.Turkish, txt.getTexts("turkish"), context),
        ]);

        

Until now everything is working well, but I want to put those buttons inside a showSlideDialog as the following:

import 'package:slide_popup_dialog/slide_popup_dialog.dart' as slideDialog;


void _showDialog() {   // here the problem begin
slideDialog.showSlideDialog(
  context: context,
  child: Column(
    children: [
        buildRadioLanguageListTile(
              Languages.English, lan.getTexts("english"), context),
          buildRadioLanguageListTile(
              Languages.Arabic, lan.getTexts("arabic"), context),
          buildRadioLanguageListTile(
              Languages.Turkish, lan.getTexts("turkish"), context),
    ],
  ),
);}



.
.
.

                      InkWell(
                      child: Container(
                        child: Text("language"),
                      ),
                      onTap:  _showDialog,  // calling _showDialog
                    )

Now I am getting this error:

Tried to listen to a value exposed with provider, from outside of the widget tree.

This is likely caused by an event handler (like a button's onPressed) that called
Provider.of without passing `listen: false`.

To fix, write:
Provider.of<LanguageProvider>(context, listen: false);

It is unsupported because may pointlessly rebuild the widget associated to the
event handler, when the widget tree doesn't care about the value.

The context used was: GeneralSetting(dependencies: [_InheritedProviderScope<LanguageProvider>, _LocalizationsScope-[GlobalKey#41a3d], _InheritedProviderScope<ThemeProvider>, _InheritedTheme])

I think there is an error in dealing with the provider or the context. How can I fix this issue?

the problem was with the context for the parts of my code. surly there are many errors but I solved the problem by using the showModalBottomSheet which has a context and builder.

  showModalBottomSheet(
      context: context,
      builder: (context) {
        return Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
          buildRadioLanguageListTile(
              Languages.English, txt.getTexts("english"), context),
          buildRadioLanguageListTile(
              Languages.Arabic, txt.getTexts("arabic"), context),
          buildRadioLanguageListTile(
              Languages.Turkish, txt.getTexts("turkish"), context),
        ]);
      });

and the rest of the code is the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM