Home > OS >  The named parameter 'builder' is required, but there's no corresponding argument and
The named parameter 'builder' is required, but there's no corresponding argument and

Time:09-24

I'm trying to add one alert box for language selection, but couldn't figure out the builder error I'm facing. it was working fine with flutter older version but not with 2.2.3 version of flutter Thanks

for the help Looking forward for the solution

The named parameter 'builder' is required, but there's no corresponding argument. The named parameter 'child' isn't defined. Undefined name 'Utils'.

this three error i m getting

   Future <void> _languageCheck() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();

    final firstRun = prefs.getBool("firstRunLanguage");
    (firstRun ?? false)
        ? () {}
        : await showDialog(
        barrierDismissible: false,
        context: context,
        child: AlertDialog(content: LanguageDialog()));
    await prefs.setBool('firstRunLanguage', true);
  }

Widget

class LanguageDialog extends StatefulWidget {
  @override
  _LanguageDialogState createState() => _LanguageDialogState();
}

class _LanguageDialogState extends State<LanguageDialog> {
  var langCode = "en";

  void getLanguage() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    langCode = prefs.getString("language") ?? kAdvanceConfig['DefaultLanguage'];
    printLog("langCode-->$langCode");
    setState(() {});
  }

  @override
  void initState() {
    super.initState();
    getLanguage();
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> list = [];
    List<Map<String, dynamic>> languages = Utils.getLanguagesList(context);
    for (var i = 0; i < languages.length; i  ) {
      // if (langCode == languages[i]["code"]) {
      //   print(languages[i]["code"]);
      // }
      list.add(
        ListTile(
          leading: Image.asset(
            languages[i]["icon"],
            width: 30,
            height: 20,
            fit: BoxFit.cover,
          ),
          title: Text(languages[i]["name"]),
          trailing: langCode == languages[i]["code"]
              ? const Icon(
            Icons.radio_button_checked,
            color: Colors.teal,
          )
              : const Icon(
            Icons.radio_button_off,
            color: Colors.teal,
          ),
          onTap: () async {
            setState(() {
              langCode = languages[i]["code"];
            });
            await Provider.of<AppModel>(context, listen: false)
                .changeLanguage(languages[i]["code"], context);
          },
        ),
      );
      if (i < languages.length - 1) {
        list.add(
          Divider(
            color: Theme.of(context).primaryColorLight,
            height: 1.0,
            indent: 75,
            //endIndent: 20,
          ),
        );
      }
    }
    return SingleChildScrollView(
      child: Column(
        children: [
          ...list,
          const LinearProgressIndicator(),
          FlatButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: const Text("OK")),
        ],
      ),
    );
  }
}

CodePudding user response:

showDialog doesn't have child, use its builder like

     await showDialog(
            barrierDismissible: false,
            context: context,
            builder: (context) => // here 
             AlertDialog(content: LanguageDialog()))

More on showDialog

CodePudding user response:

You used showDialog() method which has a required parameter caller builder so you must provide the builder argument so try like below


Future <void> _languageCheck(BuildContext context) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();

    final firstRun = prefs.getBool("firstRunLanguage");
    (firstRun ?? false)
        ? () {}
        : await showDialog(
        barrierDismissible: false,
        context: context,
        /// this builder parameter is required
        builder:(context) => AlertDialog(content: LanguageDialog()));
    await prefs.setBool('firstRunLanguage', true);
  }

  • Related