From 3e206027de1306585399b2c300a88dd6fb0ac094 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Sat, 27 Jan 2024 22:25:46 +0100 Subject: [PATCH] Changed general modals --- .../filters/details/list_details_screen.dart | 404 ++++++++++-------- lib/screens/filters/filters.dart | 44 +- lib/screens/home/home.dart | 2 + .../home/top_items/top_items_section.dart | 60 +-- 4 files changed, 277 insertions(+), 233 deletions(-) diff --git a/lib/screens/filters/details/list_details_screen.dart b/lib/screens/filters/details/list_details_screen.dart index bbc7c41..07d3aa0 100644 --- a/lib/screens/filters/details/list_details_screen.dart +++ b/lib/screens/filters/details/list_details_screen.dart @@ -111,177 +111,6 @@ class _ListDetailsScreenState extends State { } } - List content() { - return [ - CustomListTile( - icon: Icons.shield_rounded, - title: AppLocalizations.of(context)!.currentStatus, - subtitleWidget: Text( - list!.enabled == true - ? AppLocalizations.of(context)!.enabled - : AppLocalizations.of(context)!.disabled, - style: TextStyle( - color: list.enabled == true - ? appConfigProvider.useThemeColorForStatus == true - ? Theme.of(context).colorScheme.primary - : Colors.green - : appConfigProvider.useThemeColorForStatus == true - ? Colors.grey - : Colors.red, - fontWeight: FontWeight.w500 - ), - ), - padding: widget.dialog == true - ? const EdgeInsets.symmetric( - horizontal: 24, - vertical: 8 - ) - : null, - ), - CustomListTile( - icon: Icons.badge_rounded, - title: AppLocalizations.of(context)!.name, - subtitle: list.name, - padding: widget.dialog == true - ? const EdgeInsets.symmetric( - horizontal: 24, - vertical: 8 - ) - : null, - ), - CustomListTile( - icon: Icons.link_rounded, - title: "URL", - subtitle: list.url, - padding: widget.dialog == true - ? const EdgeInsets.symmetric( - horizontal: 24, - vertical: 8 - ) - : null, - trailing: IconButton( - onPressed: () => openUrl(list!.url), - icon: const Icon(Icons.open_in_browser_rounded), - tooltip: AppLocalizations.of(context)!.openListUrl, - ), - ), - CustomListTile( - icon: Icons.list_rounded, - title: AppLocalizations.of(context)!.rules, - subtitle: list.rulesCount.toString(), - padding: widget.dialog == true - ? const EdgeInsets.symmetric( - horizontal: 24, - vertical: 8 - ) - : null, - ), - CustomListTile( - icon: Icons.shield_rounded, - title: AppLocalizations.of(context)!.listType, - subtitle: widget.type == 'whitelist' - ? AppLocalizations.of(context)!.whitelist - : AppLocalizations.of(context)!.blacklist, - padding: widget.dialog == true - ? const EdgeInsets.symmetric( - horizontal: 24, - vertical: 8 - ) - : null, - ), - if (list.lastUpdated != null) CustomListTile( - icon: Icons.schedule_rounded, - title: AppLocalizations.of(context)!.latestUpdate, - subtitle: convertTimestampLocalTimezone(list.lastUpdated!, 'dd-MM-yyyy HH:mm'), - padding: widget.dialog == true - ? const EdgeInsets.symmetric( - horizontal: 24, - vertical: 8 - ) - : null, - ), - if (widget.dialog == true) Container(height: 16) - ]; - } - - List actions() { - return [ - IconButton( - onPressed: () => { - if (width > 700 || !(Platform.isAndroid || Platform.isIOS)) { - showDialog( - context: context, - builder: (ctx) => AddListModal( - list: list, - type: widget.type, - onEdit: ({required Filter list, required String type}) async => updateList( - action: FilteringListActions.edit, - filterList: list - ), - dialog: true, - ), - ) - } - else { - showModalBottomSheet( - context: context, - useRootNavigator: true, - builder: (ctx) => AddListModal( - list: list, - type: widget.type, - onEdit: ({required Filter list, required String type}) async => updateList( - action: FilteringListActions.edit, - filterList: list - ), - dialog: false, - ), - isScrollControlled: true, - backgroundColor: Colors.transparent - ) - } - }, - icon: const Icon(Icons.edit), - tooltip: AppLocalizations.of(context)!.edit, - ), - IconButton( - onPressed: () { - showDialog( - context: context, - builder: (c) => DeleteListModal( - onConfirm: () async { - ProcessModal processModal = ProcessModal(); - processModal.open(AppLocalizations.of(context)!.deletingList); - final result = await filteringProvider.deleteList( - listUrl: list!.url, - type: widget.type, - ); - processModal.close(); - if (result == true) { - showSnacbkar( - appConfigProvider: appConfigProvider, - label: AppLocalizations.of(context)!.listDeleted, - color: Colors.green - ); - Navigator.pop(context); - } - else { - showSnacbkar( - appConfigProvider: appConfigProvider, - label: AppLocalizations.of(context)!.listNotDeleted, - color: Colors.red - ); - } - } - ) - ); - }, - icon: const Icon(Icons.delete), - tooltip: AppLocalizations.of(context)!.delete, - ), - const SizedBox(width: 10), - ]; - } - if (widget.dialog == true) { return Dialog( child: ConstrainedBox( @@ -330,7 +159,11 @@ class _ListDetailsScreenState extends State { ? AppLocalizations.of(context)!.disableList : AppLocalizations.of(context)!.enableList, ), - ...actions() + _Actions( + list: list, + type: widget.type, + updateList: (action, filterList) => updateList(action: action, filterList: filterList), + ) ], ) ], @@ -340,7 +173,12 @@ class _ListDetailsScreenState extends State { child: list != null ? SingleChildScrollView( child: Wrap( - children: content(), + children: [ + _Content( + isDialog: widget.dialog, + list: list, + ) + ], ), ) : Center( @@ -361,17 +199,27 @@ class _ListDetailsScreenState extends State { return Dialog.fullscreen( child: Scaffold( appBar: AppBar( - leading: CloseButton( - onPressed: () => Navigator.pop(context), - ), title: Text(AppLocalizations.of(context)!.listDetails), - actions: list != null ? actions() : null, + actions: list != null + ? [ + _Actions( + list: list, + type: widget.type, + updateList: (action, filterList) => updateList(action: action, filterList: filterList), + ) + ] + : null, ), body: SafeArea( child: Stack( children: [ if (list != null) ListView( - children: content(), + children: [ + _Content( + isDialog: widget.dialog, + list: list, + ) + ], ), if (list == null) Center( child: Text( @@ -410,4 +258,204 @@ class _ListDetailsScreenState extends State { ); } } +} + +class _Content extends StatelessWidget { + final Filter list; + final bool isDialog; + + const _Content({ + required this.list, + required this.isDialog + }); + + @override + Widget build(BuildContext context) { + final appConfigProvider = Provider.of(context); + + return Column( + children: [ + CustomListTile( + icon: Icons.shield_rounded, + title: AppLocalizations.of(context)!.currentStatus, + subtitleWidget: Text( + list.enabled == true + ? AppLocalizations.of(context)!.enabled + : AppLocalizations.of(context)!.disabled, + style: TextStyle( + color: list.enabled == true + ? appConfigProvider.useThemeColorForStatus == true + ? Theme.of(context).colorScheme.primary + : Colors.green + : appConfigProvider.useThemeColorForStatus == true + ? Colors.grey + : Colors.red, + fontWeight: FontWeight.w500 + ), + ), + padding: isDialog == true + ? const EdgeInsets.symmetric( + horizontal: 24, + vertical: 8 + ) + : null, + ), + CustomListTile( + icon: Icons.badge_rounded, + title: AppLocalizations.of(context)!.name, + subtitle: list.name, + padding: isDialog == true + ? const EdgeInsets.symmetric( + horizontal: 24, + vertical: 8 + ) + : null, + ), + CustomListTile( + icon: Icons.link_rounded, + title: "URL", + subtitle: list.url, + padding: isDialog == true + ? const EdgeInsets.symmetric( + horizontal: 24, + vertical: 8 + ) + : null, + trailing: IconButton( + onPressed: () => openUrl(list!.url), + icon: const Icon(Icons.open_in_browser_rounded), + tooltip: AppLocalizations.of(context)!.openListUrl, + ), + ), + CustomListTile( + icon: Icons.list_rounded, + title: AppLocalizations.of(context)!.rules, + subtitle: list.rulesCount.toString(), + padding: isDialog == true + ? const EdgeInsets.symmetric( + horizontal: 24, + vertical: 8 + ) + : null, + ), + CustomListTile( + icon: Icons.shield_rounded, + title: AppLocalizations.of(context)!.listType, + subtitle: isDialog == 'whitelist' + ? AppLocalizations.of(context)!.whitelist + : AppLocalizations.of(context)!.blacklist, + padding: isDialog == true + ? const EdgeInsets.symmetric( + horizontal: 24, + vertical: 8 + ) + : null, + ), + if (list.lastUpdated != null) CustomListTile( + icon: Icons.schedule_rounded, + title: AppLocalizations.of(context)!.latestUpdate, + subtitle: convertTimestampLocalTimezone(list.lastUpdated!, 'dd-MM-yyyy HH:mm'), + padding: isDialog == true + ? const EdgeInsets.symmetric( + horizontal: 24, + vertical: 8 + ) + : null, + ), + if (isDialog == true) Container(height: 16) + ], + ); + } +} + +class _Actions extends StatelessWidget { + final Filter? list; + final String type; + final void Function(FilteringListActions, Filter) updateList; + + const _Actions({ + required this.list, + required this.type, + required this.updateList, + }); + + @override + Widget build(BuildContext context) { + final filteringProvider = Provider.of(context); + final appConfigProvider = Provider.of(context); + + final width = MediaQuery.of(context).size.width; + + return Row( + children: [ + IconButton( + onPressed: () => { + if (width > 700 || !(Platform.isAndroid || Platform.isIOS)) { + showDialog( + context: context, + builder: (ctx) => AddListModal( + list: list, + type: type, + onEdit: ({required Filter list, required String type}) async => updateList(FilteringListActions.edit, list), + dialog: true, + ), + ) + } + else { + showModalBottomSheet( + context: context, + useRootNavigator: true, + builder: (ctx) => AddListModal( + list: list, + type: type, + onEdit: ({required Filter list, required String type}) async => updateList(FilteringListActions.edit, list), + dialog: false, + ), + isScrollControlled: true, + backgroundColor: Colors.transparent + ) + } + }, + icon: const Icon(Icons.edit), + tooltip: AppLocalizations.of(context)!.edit, + ), + IconButton( + onPressed: () { + showDialog( + context: context, + builder: (c) => DeleteListModal( + onConfirm: () async { + ProcessModal processModal = ProcessModal(); + processModal.open(AppLocalizations.of(context)!.deletingList); + final result = await filteringProvider.deleteList( + listUrl: list!.url, + type: type, + ); + processModal.close(); + if (result == true) { + showSnacbkar( + appConfigProvider: appConfigProvider, + label: AppLocalizations.of(context)!.listDeleted, + color: Colors.green + ); + Navigator.pop(context); + } + else { + showSnacbkar( + appConfigProvider: appConfigProvider, + label: AppLocalizations.of(context)!.listNotDeleted, + color: Colors.red + ); + } + } + ) + ); + }, + icon: const Icon(Icons.delete), + tooltip: AppLocalizations.of(context)!.delete, + ), + const SizedBox(width: 10), + ], + ); + } } \ No newline at end of file diff --git a/lib/screens/filters/filters.dart b/lib/screens/filters/filters.dart index c0a7e20..2ab49a3 100644 --- a/lib/screens/filters/filters.dart +++ b/lib/screens/filters/filters.dart @@ -188,31 +188,25 @@ class _FiltersState extends State { } void openListDetails(Filter filter, String type) { - showGeneralDialog( - context: context, - barrierColor: !(width > 900 || !(Platform.isAndroid | Platform.isIOS)) - ?Colors.transparent - : Colors.black54, - transitionBuilder: (context, anim1, anim2, child) { - return SlideTransition( - position: Tween( - begin: const Offset(0, 1), - end: const Offset(0, 0) - ).animate( - CurvedAnimation( - parent: anim1, - curve: Curves.easeInOutCubicEmphasized - ) - ), - child: child, - ); - }, - pageBuilder: (context, animation, secondaryAnimation) => ListDetailsScreen( - listId: filter.id, - type: type, - dialog: width > 900 || !(Platform.isAndroid | Platform.isIOS), - ), - ); + if (width > 900) { + showDialog( + context: context, + builder: (context) => ListDetailsScreen( + listId: filter.id, + type: type, + dialog: width > 900 || !(Platform.isAndroid | Platform.isIOS), + ), + ); + } + else { + Navigator.push(context, MaterialPageRoute( + builder: (context) => ListDetailsScreen( + listId: filter.id, + type: type, + dialog: width > 900 || !(Platform.isAndroid | Platform.isIOS), + ), + )); + } } List actions() { diff --git a/lib/screens/home/home.dart b/lib/screens/home/home.dart index f34a186..b74e959 100644 --- a/lib/screens/home/home.dart +++ b/lib/screens/home/home.dart @@ -227,6 +227,8 @@ class _HomeState extends State { ), TopItemsLists(order: appConfigProvider.homeTopItemsOrder), + + const SizedBox(height: 16), ], ), if (statusProvider.loadStatus == LoadStatus.error) SliverFillRemaining( diff --git a/lib/screens/home/top_items/top_items_section.dart b/lib/screens/home/top_items/top_items_section.dart index 475ffb9..da0ccd8 100644 --- a/lib/screens/home/top_items/top_items_section.dart +++ b/lib/screens/home/top_items/top_items_section.dart @@ -228,37 +228,37 @@ class TopItemsSection extends StatelessWidget { children: [ TextButton( onPressed: () => { - showGeneralDialog( - context: context, - barrierColor: !(width > 700 || !(Platform.isAndroid | Platform.isIOS)) - ?Colors.transparent - : Colors.black54, - transitionBuilder: (context, anim1, anim2, child) { - return SlideTransition( - position: Tween( - begin: const Offset(0, 1), - end: const Offset(0, 0) - ).animate( - CurvedAnimation( - parent: anim1, - curve: Curves.easeInOutCubicEmphasized - ) - ), - child: child, - ); - }, - pageBuilder: (context, animation, secondaryAnimation) => TopItemsScreen( - type: type, - title: label, - isClient: type == HomeTopItems.recurrentClients, - data: data, - withProgressBar: withProgressBar, - buildValue: buildValue, - options: menuOptions, - onTapEntry: onTapEntry, - isFullscreen: !(width > 700 || !(Platform.isAndroid | Platform.isIOS)), + if (width > 700) { + showDialog( + context: context, + builder: (context) => TopItemsScreen( + type: type, + title: label, + isClient: type == HomeTopItems.recurrentClients, + data: data, + withProgressBar: withProgressBar, + buildValue: buildValue, + options: menuOptions, + onTapEntry: onTapEntry, + isFullscreen: !(width > 700 || !(Platform.isAndroid | Platform.isIOS)), + ), ) - ) + } + else { + Navigator.push(context, MaterialPageRoute( + builder: (context) => TopItemsScreen( + type: type, + title: label, + isClient: type == HomeTopItems.recurrentClients, + data: data, + withProgressBar: withProgressBar, + buildValue: buildValue, + options: menuOptions, + onTapEntry: onTapEntry, + isFullscreen: !(width > 700 || !(Platform.isAndroid | Platform.isIOS)), + ), + )) + } }, child: Row( mainAxisSize: MainAxisSize.min,