From 7690d5f1bc88233bdf77f1b1667fc58a54111171 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Sun, 8 Oct 2023 00:13:00 +0200 Subject: [PATCH] Refactor blocked services modal --- .../filters/blocked_services_screen.dart | 100 ++++++++++++------ lib/screens/filters/filters.dart | 23 +--- 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/lib/screens/filters/blocked_services_screen.dart b/lib/screens/filters/blocked_services_screen.dart index 75d941b..cefdda5 100644 --- a/lib/screens/filters/blocked_services_screen.dart +++ b/lib/screens/filters/blocked_services_screen.dart @@ -1,5 +1,7 @@ // ignore_for_file: use_build_context_synchronously +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -12,11 +14,11 @@ import 'package:adguard_home_manager/providers/filtering_provider.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart'; class BlockedServicesScreen extends StatefulWidget { - final bool dialog; + final bool fullScreen; const BlockedServicesScreen({ Key? key, - required this.dialog + required this.fullScreen }) : super(key: key); @override @@ -180,7 +182,40 @@ class _BlockedServicesScreenStateWidget extends State { } } - if (widget.dialog == true) { + if (widget.fullScreen == true) { + return Dialog.fullscreen( + child: Scaffold( + appBar: AppBar( + leading: CloseButton(onPressed: () => Navigator.pop(context)), + title: Text(AppLocalizations.of(context)!.blockedServices), + actions: [ + IconButton( + onPressed: updateBlockedServices, + icon: const Icon( + Icons.save_rounded + ), + tooltip: AppLocalizations.of(context)!.save, + ), + const SizedBox(width: 10) + ], + ), + body: RefreshIndicator( + onRefresh: () async { + final result = await filteringProvider.loadBlockedServices(); + if (result == false) { + showSnacbkar( + appConfigProvider: appConfigProvider, + label: AppLocalizations.of(context)!.blockedServicesListNotLoaded, + color: Colors.red + ); + } + }, + child: body() + ), + ), + ); + } + else { return Dialog( child: ConstrainedBox( constraints: const BoxConstraints( @@ -228,35 +263,34 @@ class _BlockedServicesScreenStateWidget extends State { ), ); } - else { - return Scaffold( - appBar: AppBar( - title: Text(AppLocalizations.of(context)!.blockedServices), - actions: [ - IconButton( - onPressed: updateBlockedServices, - icon: const Icon( - Icons.save_rounded - ), - tooltip: AppLocalizations.of(context)!.save, - ), - const SizedBox(width: 10) - ], - ), - body: RefreshIndicator( - onRefresh: () async { - final result = await filteringProvider.loadBlockedServices(); - if (result == false) { - showSnacbkar( - appConfigProvider: appConfigProvider, - label: AppLocalizations.of(context)!.blockedServicesListNotLoaded, - color: Colors.red - ); - } - }, - child: body() - ), - ); - } } +} + +void openBlockedServicesModal({ + required BuildContext context, + required double width, +}) { + 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) => BlockedServicesScreen( + fullScreen: !(width > 700 || !(Platform.isAndroid || Platform.isIOS)), + ), + ); } \ No newline at end of file diff --git a/lib/screens/filters/filters.dart b/lib/screens/filters/filters.dart index 00cc214..c4e6d9b 100644 --- a/lib/screens/filters/filters.dart +++ b/lib/screens/filters/filters.dart @@ -149,26 +149,9 @@ class _FiltersState extends State { } } - void openBlockedServicesModal() { + void openBlockedServices() { Future.delayed(const Duration(seconds: 0), () { - if (width > 700 || !(Platform.isAndroid || Platform.isIOS)) { - showDialog( - context: context, - builder: (context) => const BlockedServicesScreen( - dialog: true, - ), - barrierDismissible: false - ); - } - else { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => const BlockedServicesScreen( - dialog: false, - ), - ) - ); - } + openBlockedServicesModal(context: context, width: width); }); } @@ -312,7 +295,7 @@ class _FiltersState extends State { ) ), PopupMenuItem( - onTap: openBlockedServicesModal, + onTap: openBlockedServices, child: Row( children: [ const Icon(Icons.block),