From 192d43579bc0632c3907df0c7617f592b081b5a3 Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Sun, 26 Mar 2023 10:59:21 -0700 Subject: [PATCH 1/4] Remove unnecessary space --- lib/widgets/wide_card.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/wide_card.dart b/lib/widgets/wide_card.dart index 5567b07..3d5b4f2 100644 --- a/lib/widgets/wide_card.dart +++ b/lib/widgets/wide_card.dart @@ -29,7 +29,7 @@ class WideCard extends StatelessWidget { if (onTap != null) { return InkWell( - onTap: onTap!, + onTap: onTap!, child: Ink( decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), From e449522bc7e7bb8c6b2b857a6227ad83d7cd9fc1 Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Sun, 26 Mar 2023 11:12:14 -0700 Subject: [PATCH 2/4] Add long press support --- lib/widgets/stacked_card.dart | 72 +++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/lib/widgets/stacked_card.dart b/lib/widgets/stacked_card.dart index 6ba3d9e..23537f9 100644 --- a/lib/widgets/stacked_card.dart +++ b/lib/widgets/stacked_card.dart @@ -7,43 +7,65 @@ class StackedCard extends StatelessWidget { required this.header, required this.title, this.fullWidth, + this.onLongPress, }) : super(key: key); final String header; final String title; final bool? fullWidth; + final GestureTapCallback? onLongPress; @override Widget build(BuildContext context) { - final width = (MediaQuery.of(context).size.width - 50); + final baseWidth = (MediaQuery.of(context).size.width - 50); + final width = + fullWidth != null && fullWidth! ? baseWidth + 10 : baseWidth / 2; - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15), - color: getPrimaryColor(context), - ), - width: fullWidth != null && fullWidth! ? width + 10 : width / 2, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - header.toUpperCase(), - style: const TextStyle( - fontSize: 12, - ), + final widgetContent = Padding( + padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + header.toUpperCase(), + style: const TextStyle( + fontSize: 12, ), - Text( - title, - style: const TextStyle( - fontSize: 20, - ), + ), + Text( + title, + style: const TextStyle( + fontSize: 20, ), - ], - ), + ), + ], ), ); + + if (onLongPress != null) { + return InkWell( + onLongPress: onLongPress!, + child: Ink( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: getPrimaryColor(context), + ), + child: SizedBox( + width: width, + child: widgetContent, + ), + ), + ); + } else { + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: getPrimaryColor(context), + ), + width: width, + child: widgetContent, + ); + } } } From 363d156161d86a1581b7fe250dfe23119699cb68 Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Sun, 26 Mar 2023 11:19:44 -0700 Subject: [PATCH 3/4] Add destructive colour --- lib/theme.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/theme.dart b/lib/theme.dart index 973a23e..cc67bdc 100644 --- a/lib/theme.dart +++ b/lib/theme.dart @@ -14,6 +14,8 @@ const inactiveTabLightColor = Color.fromRGBO(0, 0, 0, .25); const activeTabDarkColor = Color(0xFFFFFFFF); const inactiveTabDarkColor = Color.fromRGBO(255, 255, 255, .45); +const destructiveActionColor = Color(0xFFEF4444); + bool isDark(BuildContext context) => Theme.of(context).brightness == Brightness.dark; From 09f775d61082d53c5bfa1e7f8cb6603c04b4a69b Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Sun, 26 Mar 2023 11:19:59 -0700 Subject: [PATCH 4/4] Add deletion support --- lib/screens/quran.dart | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/lib/screens/quran.dart b/lib/screens/quran.dart index 77f145a..2f31fef 100644 --- a/lib/screens/quran.dart +++ b/lib/screens/quran.dart @@ -31,6 +31,8 @@ class _QuranScreenState extends State { bool showHelp = false; + int deletingHistoryEntry = -1; + @override void initState() { super.initState(); @@ -67,6 +69,69 @@ class _QuranScreenState extends State { } startingAyah = lastEntry[1] < currentSurahAyahs ? lastEntry[1] + 1 : 1; + } else { + startingSurah = -1; + startingAyah = 0; + + endingSurah = -1; + endingAyah = 0; + } + } + + void confirmEntryDelete() { + if (deletingHistoryEntry != -1) { + showDialog( + context: context, + builder: (BuildContext context) { + final entry = history[deletingHistoryEntry]; + final date = DateTime.parse(entry[0].toString()); + final hijriDate = HijriCalendar.fromDate(date); + + final starting = (entry[1] as List)[0].split("-"); + final ending = (entry[1] as List)[1].split("-"); + + return AlertDialog( + title: const Text("Confirm Entry Deletion"), + content: SingleChildScrollView( + child: Wrap( + runSpacing: 15, + children: [ + const Text( + "Are you sure you want to delete the following entry?"), + StackedCard( + header: + "${DateFormat.MMMMd().format(date)} / ${hijriDate.longMonthName} ${hijriDate.hDay}", + title: + "${surahs[int.parse(starting[0]) - 1]["name"].toString()} ${starting[1]} - ${surahs[int.parse(ending[0]) - 1]["name"].toString()} ${ending[1]}", + fullWidth: true, + ), + ], + ), + ), + actions: [ + TextButton( + child: const Text( + "Delete", + style: TextStyle( + color: destructiveActionColor, + ), + ), + onPressed: () { + setState(() { + history.removeAt(deletingHistoryEntry); + setStartingEntry(); + }); + + quran.put("history", history); + deletingHistoryEntry = -1; + + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); } } @@ -213,6 +278,11 @@ class _QuranScreenState extends State { title: "${surahs[int.parse(starting[0]) - 1]["name"].toString()} ${starting[1]} - ${surahs[int.parse(ending[0]) - 1]["name"].toString()} ${ending[1]}", fullWidth: true, + onLongPress: () { + deletingHistoryEntry = + history.indexOf(entry); + confirmEntryDelete(); + }, ); }, ).toList(),