buildPresetsList function

Widget buildPresetsList(
  1. BuildContext context,
  2. ChamberPresetController presetController
)

Implementation

Widget buildPresetsList(BuildContext context, ChamberPresetController presetController) {
  return ListView.separated(
    separatorBuilder: (context, index) => const Divider(),
    itemCount: presetController.chamberPresets.length,
    itemBuilder: (context, index) {
      ChamberPreset chamberPreset = presetController.chamberPresets.values.elementAt(index);
      return ListTile(
          leading: HandledCachedNetworkImage(chamberPreset.imgUrl.isNotEmpty
              ? chamberPreset.imgUrl : presetController.chamber.imgUrl, enableFullScreen: false,
            width: 40,
          ),
          title: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(chamberPreset.name.isEmpty ? ""
                    : chamberPreset.name.length > AppConstants.maxAppItemNameLength
                    ? "${chamberPreset.name.substring(0,AppConstants.maxAppItemNameLength)}..."
                    : chamberPreset.name),
                const SizedBox(width:5),
                (AppConfig.instance.appInUse == AppInUse.c || (presetController.userServiceImpl.profile.type == ProfileType.appArtist && !presetController.isFixed)) ?
                RatingHeartBar(state: chamberPreset.state.toDouble()) : const SizedBox.shrink(),
              ]
          ),
          subtitle: Text(chamberPreset.description, textAlign: TextAlign.justify,),
          trailing: IconButton(
              icon: const Icon(
                  CupertinoIcons.forward
              ),
              padding: EdgeInsets.zero,
              constraints: const BoxConstraints(),
              onPressed: () {
                ChamberPreset preset = presetController.chamber.chamberPresets!.firstWhere((element) => element.id == chamberPreset.id);
                Get.toNamed(AppRouteConstants.generator,  arguments: [preset.clone()]);
              }
          ),
          onTap: () {
            if(!presetController.isFixed) {
              presetController.getChamberPresetDetails(chamberPreset);
            } else {
              ChamberPreset preset = presetController.chamber.chamberPresets!.firstWhere((element) => element.id == chamberPreset.id);
              Get.toNamed(AppRouteConstants.generator,  arguments: [preset.clone()]);
            }
          },
          onLongPress: () => presetController.chamber.isModifiable && (AppConfig.instance.appInUse != AppInUse.c || !presetController.isFixed) ? Alert(
              context: context,
              title: CommonTranslationConstants.appItemPrefs.tr,
              style: AlertStyle(
                  backgroundColor: AppColor.main50,
                  titleStyle: const TextStyle(color: Colors.white)
              ),
              content: Column(
                children: <Widget>[
                  Obx(() =>
                      DropdownButton<String>(
                        items: AppItemState.values.map((AppItemState appItemState) {
                          return DropdownMenuItem<String>(
                              value: appItemState.name,
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(appItemState.name.tr),
                                  appItemState.value == 0 ? const SizedBox.shrink() : const Text(" - "),
                                  appItemState.value == 0 ? const SizedBox.shrink() :
                                  RatingHeartBar(state: appItemState.value.toDouble(),),
                                ],
                              )
                          );
                        }).toList(),
                        onChanged: (String? newItemState) {
                          presetController.setChamberPresetState(EnumToString.fromString(ChamberPresetState.values, newItemState!) ?? ChamberPresetState.noState);
                        },
                        value: CoreUtilities.getItemState(presetController.itemState.value).name,
                        icon: const Icon(Icons.arrow_downward),
                        iconSize: 15,
                        elevation: 15,
                        style: const TextStyle(color: Colors.white),
                        dropdownColor: AppColor.getMain(),
                        underline: Container(
                          height: 1,
                          color: Colors.grey,
                        ),
                      ),
                  ),
                ],
              ),
              buttons: [
                DialogButton(
                  color: AppColor.bondiBlue75,
                  child: Text(AppTranslationConstants.update.tr,
                    style: const TextStyle(fontSize: 15),
                  ),
                  onPressed: () => {
                    presetController.updateChamberPreset(chamberPreset)
                  },
                ),
                DialogButton(
                  color: AppColor.bondiBlue75,
                  child: Text(AppTranslationConstants.remove.tr,
                    style: const TextStyle(fontSize: 15),
                  ),
                  onPressed: () async => {
                    await presetController.removePresetFromChamber(chamberPreset)
                  },
                ),
              ]
          ).show() : {}
      );
    },
  );

}