Skip to content

Commit

Permalink
feat: custom error toast
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jun 4, 2023
1 parent 622d938 commit 96f04c1
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/collections/spotube_icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ abstract class SpotubeIcons {
static const lightning = Icons.flash_on_rounded;
static const colorSync = FeatherIcons.activity;
static const language = FeatherIcons.globe;
static const error = FeatherIcons.alertTriangle;
}
5 changes: 4 additions & 1 deletion lib/components/root/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter/material.dart';
import 'package:motion_toast/motion_toast.dart';
import 'package:sidebarx/sidebarx.dart';

import 'package:spotube/collections/assets.gen.dart';
Expand Down Expand Up @@ -280,7 +281,9 @@ class SidebarFooter extends HookConsumerWidget {
),
IconButton(
icon: const Icon(SpotubeIcons.settings),
onPressed: () => Sidebar.goToSettings(context),
onPressed: () {
Sidebar.goToSettings(context);
},
),
],
),
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_bn.arb
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@
"success_emoji": "আমরা সফল🥳",
"success_message": "এখন আপনি সফলভাবে আপনার Spotify অ্যাকাউন্ট দিয়ে লগ ইন করেছেন। সাধুভাত আপনাকে",
"step_4": "ধাপ 4",
"step_4_steps": "কপি করা \"sp_dc\" এবং \"sp_key\" এর মান সংশ্লিষ্ট ফিল্ডে পেস্ট করুন"
"step_4_steps": "কপি করা \"sp_dc\" এবং \"sp_key\" এর মান সংশ্লিষ্ট ফিল্ডে পেস্ট করুন",
"something_went_wrong": "কিছু ভুল হয়েছে"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@
"success_emoji": "Success🥳",
"success_message": "Now you're successfully Logged In with your Spotify account. Good Job, mate!",
"step_4": "Step 4",
"step_4_steps": "Paste the copied \"sp_dc\" and \"sp_key\" values in the respective fields"
"step_4_steps": "Paste the copied \"sp_dc\" and \"sp_key\" values in the respective fields",
"something_went_wrong": "Something went wrong"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@
"success_emoji": "Succès🥳",
"success_message": "Vous êtes maintenant connecté avec succès à votre compte Spotify. Bon travail, mon ami!",
"step_4": "Étape 4",
"step_4_steps": "Collez les valeurs copiées de \"sp_dc\" et \"sp_key\" dans les champs respectifs"
"step_4_steps": "Collez les valeurs copiées de \"sp_dc\" et \"sp_key\" dans les champs respectifs",
"something_went_wrong": "Quelque chose s'est mal passé"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_hi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@
"success_emoji": "सफलता🥳",
"success_message": "अब आप अपने स्पॉटिफाई अकाउंट से सफलतापूर्वक लॉगइन हो गए हैं। अच्छा काम किया!",
"step_4": "स्टेप 4",
"step_4_steps": "कॉपी की गई \"sp_dc\" और \"sp_key\" मानों को संबंधित फील्ड में पेस्ट करें"
"step_4_steps": "कॉपी की गई \"sp_dc\" और \"sp_key\" मानों को संबंधित फील्ड में पेस्ट करें",
"something_went_wrong": "कुछ गलत हो गया"
}
5 changes: 3 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'package:spotube/provider/user_preferences_provider.dart';
import 'package:spotube/services/audio_player/audio_player.dart';
import 'package:spotube/services/youtube.dart';
import 'package:spotube/themes/theme.dart';
import 'package:spotube/utils/custom_toast_handler.dart';
import 'package:spotube/utils/persisted_state_notifier.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:system_theme/system_theme.dart';
Expand Down Expand Up @@ -119,7 +120,7 @@ Future<void> main(List<String> rawArgs) async {
enableApplicationParameters: false,
),
FileHandler(await getLogsPath(), printLogs: false),
SnackbarHandler(const Duration(seconds: 3)),
CustomToastHandler(),
],
),
releaseConfig: CatcherOptions(
Expand All @@ -134,7 +135,7 @@ Future<void> main(List<String> rawArgs) async {
await getLogsPath(),
printLogs: false,
),
SnackbarHandler(const Duration(seconds: 3)),
CustomToastHandler(),
],
),
runAppFunction: () {
Expand Down
58 changes: 58 additions & 0 deletions lib/utils/custom_toast_handler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:catcher/model/platform_type.dart';
import 'package:catcher/model/report.dart';
import 'package:catcher/model/report_handler.dart';
import 'package:flutter/material.dart';
import 'package:motion_toast/motion_toast.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/extensions/context.dart';

class CustomToastHandler extends ReportHandler {
CustomToastHandler();

@override
Future<bool> handle(Report error, BuildContext? context) async {
final theme = Theme.of(context!);

MotionToast(
primaryColor: theme.colorScheme.errorContainer,
icon: SpotubeIcons.error,
title: Text(
context.l10n.something_went_wrong,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onError,
),
),
description: Text(
error.error.toString(),
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onError,
),
),
dismissable: true,
toastDuration: const Duration(seconds: 10),
borderRadius: 10,
).show(context);
return true;
}

@override
List<PlatformType> getSupportedPlatforms() => [
PlatformType.android,
PlatformType.iOS,
PlatformType.web,
PlatformType.linux,
PlatformType.macOS,
PlatformType.windows,
];

@override
bool isContextRequired() {
return true;
}

@override
bool shouldHandleWhenRejected() {
return false;
}
}
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
motion_toast:
dependency: "direct main"
description:
name: motion_toast
sha256: f33fad8264d6d5359e41f2027d2d833614401c3983102e8f0aa13ccbbdcdeecd
url: "https://pub.dev"
source: hosted
version: "2.6.8"
mutex:
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 @@ -102,6 +102,7 @@ dependencies:
device_preview: ^1.1.0
media_kit_native_event_loop: ^1.0.4
dbus: ^0.7.8
motion_toast: ^2.6.8

dev_dependencies:
build_runner: ^2.3.2
Expand Down

0 comments on commit 96f04c1

Please sign in to comment.