Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1378 Update Talawa to give a meaningful message if the URL isn't available. #1380

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9c563eb
feat: Add proper error handling if url not available.
Ayush0Chaudhary Dec 30, 2022
fc5bd1a
Fix #1378 Update Talawa to give a meaningful message if the URL isn't…
Ayush0Chaudhary Dec 30, 2022
32863e8
fixes the failed checks.
Ayush0Chaudhary Dec 31, 2022
9a91238
Make the suggested changes
Ayush0Chaudhary Dec 31, 2022
efe6e04
Add error widget
Ayush0Chaudhary Jan 6, 2023
8bce450
Add custom error snackbar for Talawa
Ayush0Chaudhary Jan 6, 2023
3f8a9da
Make the notif bar scrollable.
Ayush0Chaudhary Jan 9, 2023
14507d5
Remove the useless part
Ayush0Chaudhary Jan 10, 2023
962423d
Add dialog box with scroll instead of snackbar
Ayush0Chaudhary Jan 19, 2023
bca1fc7
added the custom widget
Ayush0Chaudhary Jan 25, 2023
828a750
added the custom widget
Ayush0Chaudhary Jan 25, 2023
7548d22
Completed the request changes.
Ayush0Chaudhary Jan 25, 2023
9d43643
removed all the warnings
Ayush0Chaudhary Jan 25, 2023
dd7552e
Merge branch 'develop' into Ayush0Chaudhary/url-err-handling
Ayush0Chaudhary Jan 26, 2023
e4b9b80
changed the app-setting test
Ayush0Chaudhary Jan 26, 2023
01432d1
Add test for custom error widget and did err-handling in qrScan
Ayush0Chaudhary Jan 26, 2023
732f22e
removed all warnings
Ayush0Chaudhary Jan 26, 2023
be4e8a3
Update build.gradle
Ayush0Chaudhary Jan 27, 2023
9a897dc
Delete google-services.json
Ayush0Chaudhary Jan 27, 2023
f0a960e
Update build.gradle
Ayush0Chaudhary Jan 27, 2023
451f658
Delete GoogleService-Info.plist
Ayush0Chaudhary Jan 27, 2023
21b2544
Delete firebase_app_id_file.json
Ayush0Chaudhary Jan 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/services/database_mutation_functions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/locator.dart';
Expand Down Expand Up @@ -37,7 +39,10 @@ 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
.showTalawaErrorDialog("Server not running/wrong url");
});
}
return false;
}
Expand Down
28 changes: 28 additions & 0 deletions lib/services/navigation_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:flutter/material.dart';

import 'package:talawa/widgets/talawa_error_dialog.dart';
import 'package:talawa/widgets/talawa_error_widget.dart';

class NavigationService {
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

Expand Down Expand Up @@ -62,6 +65,31 @@ class NavigationService {
);
}

void showTalawaErrorWidget(
String errorMessage, {
Duration duration = const Duration(seconds: 2),
}) {
ScaffoldMessenger.of(navigatorKey.currentContext!).showSnackBar(SnackBar(
padding: EdgeInsets.zero,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you refactor this into a reusable stateless widget that takes message as the parameter?
That way we can ensure snackbars are consistent across the app

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also probably want to change to a auto sized text as well, incase the message is long or complex

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the changes you asked for, please check the PR

content: TalawaErrorWidget(
errorMessage: errorMessage,
),
// backgroundColor: Colors.grey,
backgroundColor: const Color.fromRGBO(65, 65, 66, 1),
));
}

void showTalawaErrorDialog(String errorMessage) {
showDialog(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the same with this error dialog please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done the same for it too.

context: navigatorKey.currentContext!,
barrierColor: Colors.transparent,
barrierDismissible: false,
builder: (BuildContext context) {
return TalawaErrorDialog(errorMessage);
},
);
}

void pop() {
return navigatorKey.currentState!.pop();
}
Expand Down
21 changes: 17 additions & 4 deletions lib/view_model/pre_auth_view_models/set_url_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/utils/validators.dart';
Expand Down Expand Up @@ -87,8 +88,10 @@ class SetUrlViewModel extends BaseModel {
graphqlConfig.getOrgUrl();
navigationService.pushScreen(navigateTo, arguments: argument);
} else {
navigationService
.showSnackBar("URL doesn't exist/no connection please check");
// navigationService
// .showSnackBar("URL doesn't exist/no connection please check");
navigationService.showTalawaErrorWidget(
"URL doesn't exist/no connection please check");
}
}
}
Expand Down Expand Up @@ -165,9 +168,19 @@ class SetUrlViewModel extends BaseModel {
graphqlConfig.getOrgUrl();
Navigator.pop(navigationService.navigatorKey.currentContext!);
navigationService.pushScreen('/selectOrg', arguments: orgId);
} on CameraException catch (e) {
debugPrint(e.toString());
navigationService.showTalawaErrorWidget("The Camera is not working");
} on QrEmbeddedImageException catch (e) {
debugPrint(e.toString());
navigationService.showTalawaErrorDialog("The QR is not Working");
} on QrUnsupportedVersionException catch (e) {
debugPrint(e.toString());
navigationService
.showTalawaErrorDialog("This QR version is not Supported.");
} on Exception catch (e) {
print(e);
print('invalid app qr');
debugPrint(e.toString());
navigationService.showTalawaErrorWidget("This QR is not for the App");
}
}
});
Expand Down
7 changes: 6 additions & 1 deletion lib/widgets/organization_list.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
Expand All @@ -16,6 +18,7 @@ class OrganizationList extends StatelessWidget {
@override
Widget build(BuildContext context) {
model.organizations = [];
int noOfRefetch = 0;
return GraphQLProvider(
client: ValueNotifier<GraphQLClient>(graphqlConfig.clientToQuery()),
child: Query(
Expand All @@ -34,13 +37,15 @@ class OrganizationList extends StatelessWidget {
if (result.hasException) {
final isException = databaseFunctions.encounteredExceptionOrError(
result.exception!,
showSnackBar: false,
showSnackBar: noOfRefetch == 0,
);
if (isException != null) {
if (isException) {
refetch!();
noOfRefetch++;
} else {
refetch!();
noOfRefetch++;
}
}
} else {
Expand Down
35 changes: 35 additions & 0 deletions lib/widgets/talawa_error_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';

class TalawaErrorDialog extends StatelessWidget {
const TalawaErrorDialog(this.errorMessage, {Key? key}) : super(key: key);
final String errorMessage;
@override
Widget build(BuildContext context) {
return SizedBox(
child: AlertDialog(
title: const Text(
"Error",
style: TextStyle(color: Colors.red),
),
content: SizedBox(
width: 200,
height: 75,
child: AutoSizeText(
errorMessage,
style: const TextStyle(fontSize: 20),
maxLines: 3,
),
),
actions: <Widget>[
TextButton(
child: const Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
);
}
}
40 changes: 40 additions & 0 deletions lib/widgets/talawa_error_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';

class TalawaErrorWidget extends StatelessWidget {
const TalawaErrorWidget({Key? key, required this.errorMessage})
: super(key: key);
final String errorMessage;
@override
Widget build(BuildContext context) {
return Row(
children: [
Container(
width: 20,
height: 80,
decoration: const BoxDecoration(color: Colors.red),
),
const SizedBox(
width: 10,
),
const Icon(
Icons.error,
color: Colors.red,
size: 35,
),
const SizedBox(
width: 10,
),
Expanded(
flex: 1,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Text(
errorMessage,
style: const TextStyle(color: Colors.white),
),
),
)
],
);
}
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.9.0"
auto_size_text:
dependency: "direct main"
description:
name: auto_size_text
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
boolean_selector:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
auto_size_text: ^3.0.0
cached_network_image: ^3.1.0
connectivity_plus: ^2.3.1
cupertino_icons: ^1.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:hive/hive.dart';
import 'package:mockito/mockito.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/utils/validators.dart';
Expand Down Expand Up @@ -89,8 +90,8 @@ Future<void> main() async {

await model.checkURLandNavigate('/', 'arguments');

verify(navigationService
.showSnackBar("URL doesn't exist/no connection please check"));
verify(navigationService.showTalawaErrorWidget(
"URL doesn't exist/no connection please check"));
});

testWidgets('Check if scanQR() is working fine', (tester) async {
Expand Down Expand Up @@ -123,7 +124,82 @@ Future<void> main() async {
.onQRViewCreated(controller);
});

testWidgets('Check if _onQRViewCreated() is working fine when throws',
testWidgets(
'Check if _onQRViewCreated() is working fine when throws CameraException',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestWidget(model),
navigatorKey: navigationService.navigatorKey,
),
);

final controller = MockQRViewController();
when(controller.scannedDataStream).thenAnswer((_) async* {
yield Barcode('qr?orgId=1&scan', BarcodeFormat.qrcode, null);
});
// when(controller.stopCamera())
// .thenThrow(Exception({"errorType": "error"}));

when(controller.stopCamera())
.thenThrow(CameraException("200", "cameraException"));
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();

(tester.widget(find.byType(QRView)) as QRView)
.onQRViewCreated(controller);
});
testWidgets(
'Check if _onQRViewCreated() is working fine when throws QrEmbeddedImageException',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestWidget(model),
navigatorKey: navigationService.navigatorKey,
),
);

final controller = MockQRViewController();
when(controller.scannedDataStream).thenAnswer((_) async* {
yield Barcode('qr?orgId=1&scan', BarcodeFormat.qrcode, null);
});
// when(controller.stopCamera())
// .thenThrow(Exception({"errorType": "error"}));

when(controller.stopCamera())
.thenThrow(QrEmbeddedImageException("error"));
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();

(tester.widget(find.byType(QRView)) as QRView)
.onQRViewCreated(controller);
});
testWidgets(
'Check if _onQRViewCreated() is working fine when throws QrUnsupportedVersionException',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestWidget(model),
navigatorKey: navigationService.navigatorKey,
),
);

final controller = MockQRViewController();
when(controller.scannedDataStream).thenAnswer((_) async* {
yield Barcode('qr?orgId=1&scan', BarcodeFormat.qrcode, null);
});
// when(controller.stopCamera())
// .thenThrow(Exception({"errorType": "error"}));

when(controller.stopCamera()).thenThrow(QrUnsupportedVersionException(0));
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();

(tester.widget(find.byType(QRView)) as QRView)
.onQRViewCreated(controller);
});
testWidgets(
'Check if _onQRViewCreated() is working fine when throws Exception',
(tester) async {
await tester.pumpWidget(
MaterialApp(
Expand All @@ -136,8 +212,10 @@ Future<void> main() async {
when(controller.scannedDataStream).thenAnswer((_) async* {
yield Barcode('qr?orgId=1&scan', BarcodeFormat.qrcode, null);
});
when(controller.stopCamera()).thenThrow(Exception());
// when(controller.stopCamera())
// .thenThrow(Exception({"errorType": "error"}));

when(controller.stopCamera()).thenThrow(Exception(0));
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hive/hive.dart';
import 'package:mockito/mockito.dart';
import 'package:provider/provider.dart';
import 'package:talawa/constants/constants.dart';
import 'package:talawa/constants/custom_theme.dart';
import 'package:talawa/models/language/language_model.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/user/user_info.dart';
import 'package:talawa/router.dart' as router;
import 'package:talawa/services/graphql_config.dart';
import 'package:talawa/services/navigation_service.dart';
Expand Down Expand Up @@ -90,14 +85,14 @@ Future<void> main() async {
locator<GraphqlConfig>().test();
locator<SizeConfig>().test();

final Directory dir = Directory('temporaryPath');
Hive
..init(dir.path)
..registerAdapter(UserAdapter())
..registerAdapter(OrgInfoAdapter());
await Hive.openBox<User>('currentUser');
await Hive.openBox<OrgInfo>('currentOrg');
await Hive.openBox('url');
// final Directory dir = Directory('temporaryPath');
// Hive
// ..init(dir.path)
// ..registerAdapter(UserAdapter())
// ..registerAdapter(OrgInfoAdapter());
// await Hive.openBox<User>('currentUser');
// await Hive.openBox<OrgInfo>('currentOrg');
// await Hive.openBox('url');
group('Setting Page Screen Widget Test in dark mode', () {
testWidgets("Testing if Settings Screen shows up", (tester) async {
await tester.pumpWidget(createChangePassScreenDark());
Expand Down
1 change: 0 additions & 1 deletion test/widget_tests/widgets/custom_alert_dialog_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
// import 'package:talawa/locator.dart' as loc;
import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/utils/app_localization.dart';
Expand Down
Loading