showBottomModal static method

dynamic showBottomModal(
  1. BuildContext context, {
  2. double? height,
})

Show a bottom modal to switch languages

Implementation

static showBottomModal(BuildContext context, {double? height}) async {
  List<Map<String, String>> list = await getLanguageList();
  Map<String, dynamic>? currentLang = await currentLanguage();
  showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return SafeArea(
            child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text("Select your language".tr())
                .headingMedium(context)
                .alignCenter()
                .paddingOnly(top: 16, bottom: 8),
            Flexible(
              fit: FlexFit.tight,
              child: SizedBox(
                height: height ?? MediaQuery.of(context).size.height / 2,
                child: ListView(
                  children: list.map((Map<String, String> meta) {
                    MapEntry<String, String> data = meta.entries.first;
                    bool isChecked = false;
                    if (currentLang != null &&
                        data.key == currentLang.entries.first.key) {
                      isChecked = true;
                    }
                    return ListTile(
                      title: Text(data.value),
                      trailing: isChecked ? Icon(Icons.check) : null,
                      onTap: () async {
                        await NyLocalization.instance
                            .setLanguage(context, language: data.key);

                        // store the language
                        await storeLanguage(object: {data.key: data.value});

                        updateState(state,
                            data: {"action": "refresh-page", "data": {}});
                        Navigator.pop(context);
                      },
                    );
                  }).toList(),
                ),
              ),
            )
          ],
        ));
      });
}