prefValue method

  1. @override
Widget prefValue()
override

Implementation

@override
Widget prefValue() {
  if (context != null && pref.listItems.containsKey(pref.value)) {
    switch (pref.format) {
      case Pref.FORMAT_LIST_DIALOG:
        String value = pref.listItems.containsKey([pref.value])
            ? pref.listItems[pref.value]!
            : "";
        return SizedBox(
          width: (MediaQuery.of(context!).size.width / 2) - 20.0,
          child: Text(
            value,
            maxLines: 2,
            softWrap: true,
            style: TextStyle(
              fontFamily: "Roboto",
              fontSize: 18.0,
              color: pref.enabled ? null : Colors.grey,
            ),
          ),
        );
      case Pref.FORMAT_LIST_DROPDOWN:
      default:
        List<ListMap> listData = [];
        for (int key in pref.listItems.keys) {
          String value =
              pref.listItems.containsKey(key) ? pref.listItems[key]! : "";
          listData.add(ListMap(key: key, value: value));
        }
        return SizedBox(
          width: (MediaQuery.of(context!).size.width / 2) - 20.0,
          child: DropdownButton<int>(
            isExpanded: true,
            value: pref.value,
            onChanged: (int? newValue) {
              if (callback != null && newValue != null) {
                pref.value = newValue;
                callback!(pref);
              }
            },
            items: listData.map<DropdownMenuItem<int>>((ListMap value) {
              return DropdownMenuItem<int>(
                value: value.key,
                child: Text(
                  value.value,
                  maxLines: 2,
                  softWrap: true,
                ),
              );
            }).toList(),
          ),
        );
    }
  } else {
    return const SizedBox(width: 0.0, height: 0.0);
  }
}