diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 0b46059..18e2eb1 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -324,5 +324,6 @@ "updateFrequencyNotChanged": "Updare frecuency couldn't be changed", "updating": "Updating values...", "blockedServicesUpdated": "Blocked services updated successfully", - "blockedServicesNotUpdated": "Blocked services couldn't be updated" + "blockedServicesNotUpdated": "Blocked services couldn't be updated", + "insertDomain": "Insert a domain to check it's stauts." } \ No newline at end of file diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index af133a7..4746b5f 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -324,5 +324,6 @@ "updateFrequencyNotChanged": "La frecuencia de actualización no pudo ser cambiada", "updating": "Actualizando valores...", "blockedServicesUpdated": "Servicios bloqueados actualizados correctamente", - "blockedServicesNotUpdated": "No se pudieron actualizar los servicios bloqueados" + "blockedServicesNotUpdated": "No se pudieron actualizar los servicios bloqueados", + "insertDomain": "Inserta un dominio para comprobar su estado," } \ No newline at end of file diff --git a/lib/screens/filters/check_host_modal.dart b/lib/screens/filters/check_host_modal.dart index 4e906be..a145477 100644 --- a/lib/screens/filters/check_host_modal.dart +++ b/lib/screens/filters/check_host_modal.dart @@ -19,8 +19,6 @@ class _CheckHostModalState extends State { final TextEditingController domainController = TextEditingController(); String? domainError; - bool isChecking = false; - Widget? resultWidget; void validateDomain(String value) { @@ -33,189 +31,194 @@ class _CheckHostModalState extends State { } } + Widget checking() { + return SizedBox( + height: 30, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const CircularProgressIndicator(), + const SizedBox(width: 20), + Text(AppLocalizations.of(context)!.checkingHost) + ], + ), + ); + } + @override Widget build(BuildContext context) { final serversProvider = Provider.of(context); void checkHost() async { - setState(() => isChecking = true); + if (mounted) { + setState(() => resultWidget = checking()); - final result = await checkHostFiltered(server: serversProvider.selectedServer!, host: domainController.text); + final result = await checkHostFiltered(server: serversProvider.selectedServer!, host: domainController.text); - if (result['result'] == 'success') { - final status = getFilteredStatus(context, result['data']['reason']); - setState(() => resultWidget = Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon( - status['icon'], - size: 18, - color: status['filtered'] == true - ? Colors.red - : Colors.green, - ), - const SizedBox(width: 10), - Text( - status['label'], - style: TextStyle( - color: status['filtered'] == true - ? Colors.red - : Colors.green, - fontWeight: FontWeight.w500 - ), - ) - ], - )); + if (result['result'] == 'success') { + final status = getFilteredStatus(context, result['data']['reason']); + if (mounted) { + setState(() => resultWidget = Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + status['icon'], + size: 18, + color: status['filtered'] == true + ? Colors.red + : Colors.green, + ), + const SizedBox(width: 10), + Text( + status['label'], + style: TextStyle( + color: status['filtered'] == true + ? Colors.red + : Colors.green, + fontWeight: FontWeight.w500 + ), + ) + ], + )); + } + } + else { + if (mounted) { + setState(() => resultWidget = Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon( + Icons.cancel, + size: 18, + color: Colors.red, + ), + const SizedBox(width: 10), + Text( + AppLocalizations.of(context)!.check, + style: const TextStyle( + color: Colors.red, + fontWeight: FontWeight.w500 + ), + ) + ], + )); + } + } } - else { - setState(() => resultWidget = Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Icon( - Icons.cancel, - size: 18, - color: Colors.red, - ), - const SizedBox(width: 10), - Text( - AppLocalizations.of(context)!.check, - style: const TextStyle( - color: Colors.red, - fontWeight: FontWeight.w500 - ), - ) - ], - )); - } - - setState(() => isChecking = false); } return Padding( padding: MediaQuery.of(context).viewInsets, - child: Stack( - children: [ - AnimatedContainer( - height: resultWidget != null - ? 350 - : 310, - width: double.maxFinite, - duration: const Duration(milliseconds: 200), - curve: Curves.easeInOut, - decoration: BoxDecoration( - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(28), - topRight: Radius.circular(28), + child: Container( + height: 350, + width: double.maxFinite, + decoration: BoxDecoration( + borderRadius: const BorderRadius.only( + topLeft: Radius.circular(28), + topRight: Radius.circular(28), + ), + color: Theme.of(context).dialogBackgroundColor + ), + child: Center( + child: Column( + children: [ + const Padding( + padding: EdgeInsets.only(top: 24), + child: Icon( + Icons.shield_rounded, + size: 26, + ), ), - color: Theme.of(context).dialogBackgroundColor - ), - child: Center( - child: Column( - children: [ - const Padding( - padding: EdgeInsets.only(top: 24), - child: Icon( - Icons.shield_rounded, - size: 26, + const SizedBox(height: 20), + Text( + AppLocalizations.of(context)!.checkHostFiltered, + style: const TextStyle( + fontSize: 24 + ), + ), + const SizedBox(height: 30), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: TextFormField( + controller: domainController, + onChanged: validateDomain, + decoration: InputDecoration( + prefixIcon: const Icon(Icons.link_rounded), + border: const OutlineInputBorder( + borderRadius: BorderRadius.all( + Radius.circular(10) + ) ), + errorText: domainError, + labelText: AppLocalizations.of(context)!.domain, ), - const SizedBox(height: 20), - Text( - AppLocalizations.of(context)!.checkHostFiltered, - style: const TextStyle( - fontSize: 24 - ), + ), + ), + if (resultWidget != null) Expanded( + child: Padding( + padding: const EdgeInsets.only( + top: 20, + left: 20, + right: 20 ), - const SizedBox(height: 30), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: TextFormField( - controller: domainController, - onChanged: validateDomain, - decoration: InputDecoration( - prefixIcon: const Icon(Icons.link_rounded), - border: const OutlineInputBorder( - borderRadius: BorderRadius.all( - Radius.circular(10) - ) - ), - errorText: domainError, - labelText: AppLocalizations.of(context)!.domain, + child: resultWidget, + ), + ), + if (resultWidget == null) Expanded( + child: Padding( + padding: const EdgeInsets.only( + top: 20, + left: 20, + right: 20 + ), + child: Center( + child: Text( + AppLocalizations.of(context)!.insertDomain, + style: TextStyle( + fontSize: 16, + color: Theme.of(context).primaryColor ), ), ), - if (resultWidget != null) Padding( + ) + ), + Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Padding( padding: const EdgeInsets.only( - top: 20, - left: 20, + bottom: 20, right: 20 ), - child: resultWidget, - ), - Expanded( - child: Column( + child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - Padding( - padding: const EdgeInsets.all(20), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: Text(AppLocalizations.of(context)!.close), - ), - const SizedBox(width: 20), - TextButton( - onPressed: checkHost, - child: Text(AppLocalizations.of(context)!.check), - ), - ], + TextButton( + onPressed: () => Navigator.pop(context), + child: Text(AppLocalizations.of(context)!.close), + ), + const SizedBox(width: 20), + TextButton( + onPressed: domainController.text != '' && domainError == null + ? () => checkHost() + : null, + child: Text( + AppLocalizations.of(context)!.check, + style: TextStyle( + color: domainController.text != '' && domainError == null + ? Theme.of(context).primaryColor + : Colors.grey + ), ), - ) + ), ], ), ) ], - ), - ), + ) + ], ), - AnimatedOpacity( - opacity: isChecking == true ? 1 : 0, - duration: const Duration(milliseconds: 250), - curve: Curves.easeInOut, - child: IgnorePointer( - ignoring: isChecking == true ? false : true, - child: Container( - height: 310, - width: double.maxFinite, - decoration: BoxDecoration( - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(28), - topRight: Radius.circular(28), - ), - color: Colors.black.withOpacity(0.8) - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const CircularProgressIndicator( - color: Colors.white, - ), - const SizedBox(height: 30), - Text( - AppLocalizations.of(context)!.checkingHost, - style: const TextStyle( - color: Colors.white, - fontSize: 22 - ), - ) - ], - ), - ), - ), - ) - ], + ), ), ); }