Improved check host modal

This commit is contained in:
Juan Gilsanz Polo 2022-10-11 19:12:09 +02:00
parent 5d908549e1
commit 568f2ea4d7
3 changed files with 162 additions and 157 deletions

View file

@ -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."
}

View file

@ -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,"
}

View file

@ -19,8 +19,6 @@ class _CheckHostModalState extends State<CheckHostModal> {
final TextEditingController domainController = TextEditingController();
String? domainError;
bool isChecking = false;
Widget? resultWidget;
void validateDomain(String value) {
@ -33,17 +31,33 @@ class _CheckHostModalState extends State<CheckHostModal> {
}
}
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<ServersProvider>(context);
void checkHost() async {
setState(() => isChecking = true);
if (mounted) {
setState(() => resultWidget = checking());
final result = await checkHostFiltered(server: serversProvider.selectedServer!, host: domainController.text);
if (result['result'] == 'success') {
final status = getFilteredStatus(context, result['data']['reason']);
if (mounted) {
setState(() => resultWidget = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
@ -67,7 +81,9 @@ class _CheckHostModalState extends State<CheckHostModal> {
],
));
}
}
else {
if (mounted) {
setState(() => resultWidget = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
@ -87,21 +103,15 @@ class _CheckHostModalState extends State<CheckHostModal> {
],
));
}
setState(() => isChecking = false);
}
}
}
return Padding(
padding: MediaQuery.of(context).viewInsets,
child: Stack(
children: [
AnimatedContainer(
height: resultWidget != null
? 350
: 310,
child: Container(
height: 350,
width: double.maxFinite,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(28),
@ -144,7 +154,8 @@ class _CheckHostModalState extends State<CheckHostModal> {
),
),
),
if (resultWidget != null) Padding(
if (resultWidget != null) Expanded(
child: Padding(
padding: const EdgeInsets.only(
top: 20,
left: 20,
@ -152,12 +163,33 @@ class _CheckHostModalState extends State<CheckHostModal> {
),
child: resultWidget,
),
Expanded(
child: Column(
),
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
),
),
),
)
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.all(20),
padding: const EdgeInsets.only(
bottom: 20,
right: 20
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
@ -167,56 +199,27 @@ class _CheckHostModalState extends State<CheckHostModal> {
),
const SizedBox(width: 20),
TextButton(
onPressed: checkHost,
child: Text(AppLocalizations.of(context)!.check),
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
),
)
],
),
),
),
)
],
),
);
}
}