Skip to content

Commit

Permalink
fix snakebar with toast in iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-ishita-g committed Jun 6, 2024
1 parent c2bda07 commit d97ecfe
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
10 changes: 10 additions & 0 deletions app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,9 @@ PODS:
- Flutter (1.0.0)
- flutter_timezone (0.0.1):
- Flutter
- fluttertoast (0.0.2):
- Flutter
- Toast
- google_sign_in_ios (0.0.1):
- AppAuth (>= 1.7.4)
- Flutter
Expand Down Expand Up @@ -1194,6 +1197,7 @@ PODS:
- sqflite (0.0.3):
- Flutter
- FlutterMacOS
- Toast (4.1.1)
- TOCropViewController (2.7.4)

DEPENDENCIES:
Expand All @@ -1205,6 +1209,7 @@ DEPENDENCIES:
- firebase_storage (from `.symlinks/plugins/firebase_storage/ios`)
- Flutter (from `Flutter`)
- flutter_timezone (from `.symlinks/plugins/flutter_timezone/ios`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/darwin`)
- image_cropper (from `.symlinks/plugins/image_cropper/ios`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
Expand Down Expand Up @@ -1242,6 +1247,7 @@ SPEC REPOS:
- nanopb
- PromisesObjC
- RecaptchaInterop
- Toast
- TOCropViewController

EXTERNAL SOURCES:
Expand All @@ -1261,6 +1267,8 @@ EXTERNAL SOURCES:
:path: Flutter
flutter_timezone:
:path: ".symlinks/plugins/flutter_timezone/ios"
fluttertoast:
:path: ".symlinks/plugins/fluttertoast/ios"
google_sign_in_ios:
:path: ".symlinks/plugins/google_sign_in_ios/darwin"
image_cropper:
Expand Down Expand Up @@ -1303,6 +1311,7 @@ SPEC CHECKSUMS:
FirebaseStorage: 44f4e25073f6fa0d4d8c09f5bec299ee9e4eb985
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_timezone: ffb07bdad3c6276af8dada0f11978d8a1f8a20bb
fluttertoast: e9a18c7be5413da53898f660530c56f35edfba9c
google_sign_in_ios: 07375bfbf2620bc93a602c0e27160d6afc6ead38
GoogleSignIn: d4281ab6cf21542b1cfaff85c191f230b399d2db
GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15
Expand All @@ -1321,6 +1330,7 @@ SPEC CHECKSUMS:
share_plus: 8875f4f2500512ea181eef553c3e27dba5135aad
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
Toast: 1f5ea13423a1e6674c4abdac5be53587ae481c4e
TOCropViewController: 80b8985ad794298fb69d3341de183f33d1853654

PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796
Expand Down
25 changes: 18 additions & 7 deletions app/lib/ui/components/error_snakebar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';

void showErrorSnackBar(BuildContext context, Object error) {
HapticFeedback.mediumImpact();
Expand All @@ -11,13 +14,21 @@ void showSnackBar(
String text, {
SnackBarLength length = SnackBarLength.short,
}) {
final snackBar = SnackBar(
content: Text(text),
behavior: SnackBarBehavior.floating,
duration: Duration(seconds: length.seconds),
);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
if (Platform.isIOS) {
Fluttertoast.showToast(
msg: text,
timeInSecForIosWeb: length.seconds,
gravity: ToastGravity.BOTTOM,
);
} else {
final snackBar = SnackBar(
content: Text(text),
behavior: SnackBarBehavior.floating,
duration: Duration(seconds: length.seconds),
);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}

enum SnackBarLength {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class _ContactSupportScreenState extends ConsumerState<ContactSupportScreen> {
context.l10n.contact_support_submit_title,
onPressed: () {
notifier.submitSupportRequest();
showErrorSnackBar(context, state.error.toString());
},
),
);
Expand Down
8 changes: 8 additions & 0 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
fluttertoast:
dependency: "direct main"
description:
name: fluttertoast
sha256: "7eae679e596a44fdf761853a706f74979f8dd3cd92cf4e23cae161fda091b847"
url: "https://pub.dev"
source: hosted
version: "8.2.6"
freezed:
dependency: "direct dev"
description:
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies:
cached_network_image: ^3.3.1
image_picker: ^1.1.1
image_cropper: ^6.0.0
fluttertoast: ^8.2.6

# auth
firebase_auth: ^4.20.0
Expand Down

0 comments on commit d97ecfe

Please sign in to comment.