buildChamberList function
Implementation
Widget buildChamberList(BuildContext context, ChamberController chamberController) {
return ListView.separated(
separatorBuilder: (context, index) => const Divider(),
itemCount: chamberController.chambers.length,
shrinkWrap: true,
itemBuilder: (context, index) {
Chamber chamber = chamberController.chambers.values.elementAt(index);
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 10),
leading: SizedBox(
width: 50,
child: HandledCachedNetworkImage(chamber.imgUrl.isNotEmpty ? chamber.imgUrl : AppProperties.getAppLogoUrl())
),
title: Row(
children: <Widget>[
Text(chamber.name.length > AppConstants.maxItemlistNameLength
? "${chamber.name.substring(0, AppConstants.maxItemlistNameLength).capitalizeFirst}..."
: chamber.name.capitalizeFirst),
///DEPRECATE .isFav ? const Icon(Icons.favorite, size: 10,) : SizedBox.shrink()
]),
subtitle: chamber.description.isNotEmpty ? Text(chamber.description.capitalizeFirst, maxLines: 3, overflow: TextOverflow.ellipsis,) : null,
trailing: ActionChip(
labelPadding: EdgeInsets.zero,
backgroundColor: AppColor.main25,
avatar: CircleAvatar(
backgroundColor: AppColor.white80,
child: Text(((chamber.chamberPresets?.length ?? 0)).toString(),
style: const TextStyle(color: Colors.black87),
),
),
label: Icon(AppFlavour.getAppItemIcon(), color: AppColor.white80),
onPressed: () async {
await chamberController.gotoChamberPresets(chamber);
///ADD CHAMBERPRESET SEARCH HERE
// if(!chamber.isModifiable) {
// await chamberController.gotoChamberPresets(chamber);
// } else {
// Get.toNamed(AppRouteConstants.itemSearch,
// arguments: [SpotifySearchType.song, chamber]
// );
// }
},
),
onTap: () async {
await chamberController.gotoChamberPresets(chamber);
},
onLongPress: () async {
(await showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: AppColor.main75,
title: Text(CommonTranslationConstants.itemlistName.tr,),
content: SizedBox(
height: AppTheme.fullHeight(context)*0.25,
child: Obx(()=> chamberController.isLoading.value ? const Center(child: CircularProgressIndicator())
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: chamberController.newChamberNameController,
decoration: InputDecoration(
labelText: '${AppTranslationConstants.changeName.tr}: ',
hintText: chamber.name,
),
),
TextField(
controller: chamberController.newChamberDescController,
minLines: 2,
maxLines: 5,
decoration: InputDecoration(
labelText: '${AppTranslationConstants.changeDesc.tr}: ',
hintText: chamber.description,
),
),
],
),
),
),
actions: <Widget>[
DialogButton(
color: AppColor.bondiBlue75,
onPressed: () async {
await chamberController.updateChamber(chamber.id, chamber);
Navigator.pop(ctx);
},
child: Text(AppTranslationConstants.update.tr,
style: const TextStyle(fontSize: 14),
),
),
DialogButton(
color: AppColor.bondiBlue75,
child: Text(AppTranslationConstants.remove.tr,
style: const TextStyle(fontSize: 14),
),
onPressed: () async {
if(chamberController.chambers.length == 1) {
AppAlerts.showAlert(context,
title: CommonTranslationConstants.itemlistPrefs.tr,
message: CommonTranslationConstants.cantRemoveMainItemlist.tr);
} else {
await chamberController.deleteChamber(chamber);
Navigator.pop(ctx);
}
},
),
],
),
)) ?? false;
},
);
},
);
}