showAlertChangeLanguage method

Future showAlertChangeLanguage({
  1. required BuildContext context,
  2. required String title,
  3. required String btnNegative,
})

Show alert to change language

Implementation

Future<dynamic> showAlertChangeLanguage(
    {required BuildContext context,
    required String title,
    required String btnNegative}) async {
  List<Map<dynamic, dynamic>> out = this.getListLanguage();

  return await showDialog(
      context: context,
      builder: (context) => AlertDialog(
            title: Text(title),
            actions: <Widget>[
              TextButton(
                  child: Text(btnNegative),
                  onPressed: () => Navigator.pop(context)),
            ],
            content: Container(
              width: MediaQuery.of(context).size.height * 0.8,
              height: MediaQuery.of(context).size.height * 0.3,
              child: ListView.builder(
                itemCount: out.length,
                itemBuilder: (BuildContext context, int index) {
                  return Material(
                    color: currentValue['config']['prefix'] ==
                            out[index]['prefix']
                        ? Colors.blueAccent[700]
                        : Colors.transparent,
                    child: ListTile(
                      leading: CountryPickerUtils.getDefaultFlagImage(Country(
                          isoCode: out[index]['iso_code'],
                          iso3Code: '',
                          name: '',
                          phoneCode: '')),
                      selected: currentValue['config']['prefix'] ==
                          out[index]['prefix'],
                      title: Text(
                        out[index]['title'].toString(),
                        style: TextStyle(
                            color: currentValue['config']['prefix'] ==
                                    out[index]['prefix']
                                ? Colors.white
                                : Colors.black),
                      ),
                      onTap: () {
                        changeLanguage(out[index]['prefix']);
                        Navigator.pop(context);
                      },
                    ),
                  );
                },
              ),
            ),
          ));
}