From c22d5937166845a2af4005c712ed0e4320ce8104 Mon Sep 17 00:00:00 2001 From: Ayush0Chaudhary Date: Sat, 31 Dec 2022 03:16:58 +0530 Subject: [PATCH] Fix #1378 Update Talawa to give a meaningful message if the URL isn't available. --- lib/services/database_mutation_functions.dart | 6 +++++- lib/utils/validators.dart | 10 ++++------ lib/widgets/organization_list.dart | 13 ++++--------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/services/database_mutation_functions.dart b/lib/services/database_mutation_functions.dart index 08bf252c34..23e1ac4507 100644 --- a/lib/services/database_mutation_functions.dart +++ b/lib/services/database_mutation_functions.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:talawa/locator.dart'; @@ -37,7 +39,9 @@ class DataBaseMutationFunctions { if (exception.linkException != null) { debugPrint(exception.linkException.toString()); if (showSnackBar) { - navigationService.showSnackBar("Server not running/wrong url"); + Timer(const Duration(seconds: 2), () { + navigationService.showSnackBar("Server not running/wrong url"); + }); } return false; } diff --git a/lib/utils/validators.dart b/lib/utils/validators.dart index ed728b6f97..0e2dc4c45c 100644 --- a/lib/utils/validators.dart +++ b/lib/utils/validators.dart @@ -2,16 +2,14 @@ import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; class Validator { - static Future validateURL( + static String? validateURL( String value, - ) async { + ) { if (value.isEmpty) { return 'Please verify URL first'; } - Uri uri = Uri.parse(value); - // final bool validURL = uri.isAbsolute; - final response = await http.get(uri); - if (response.statusCode != 200) { + final bool validURL = Uri.parse(value).isAbsolute; + if (!validURL) { return 'Enter a valid URL'; } return null; diff --git a/lib/widgets/organization_list.dart b/lib/widgets/organization_list.dart index f838ed6476..b00b6dabc7 100644 --- a/lib/widgets/organization_list.dart +++ b/lib/widgets/organization_list.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; @@ -32,17 +34,10 @@ class OrganizationList extends StatelessWidget { Future Function()? refetch, }) { if (result.hasException) { - final isException = databaseFunctions.encounteredExceptionOrError( + databaseFunctions.encounteredExceptionOrError( result.exception!, - showSnackBar: false, + showSnackBar: true, ); - if (isException != null) { - if (isException) { - refetch!(); - } else { - refetch!(); - } - } } else { if (!result.isLoading) { model.organizations = OrgInfo().fromJsonToList(