lundi 13 décembre 2021

Accessing widgets using global keys in dart

Ive got a Map of data type Map<String, Map<String, Key?>> in the state with data

Map<String, Map<String, Key?>> filterOption = {
"Certificate Provider": {
  "NVQ": GlobalKey(),
  "City and Guilds": GlobalKey()
},}

and I use this list to populate 2 check boxes by mapping the list to a custom checkbox widget I made .

Widget certificateProvider(
  BuildContext context, Map<String, Key?> widgetData) {
return Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: widgetData.entries
        .map(
          (entry) => CheckBox(
            label: entry.key,
            onChanged: (value) {},
            key: entry.value,
          ),
        )
        .toList());

} complete ui

A global key is from the state list above is passed to identify the checkboxes uniquely. What I want is , when The apply button is clicked... the program should use the global key to iterate through each checkbox to see if its checked or not . How can I access the checkboxed uniquely with the global key ?




Aucun commentaire:

Enregistrer un commentaire