From 483fbea07917869f17f6d2c22722ddf052724ee8 Mon Sep 17 00:00:00 2001 From: franzap <_@franzap.com> Date: Fri, 14 Jun 2024 13:17:59 -0300 Subject: [PATCH] Better toasts --- lib/screens/app_detail_screen.dart | 32 ++++------------------- lib/utils/extensions.dart | 41 ++++++++++++++++++++++-------- lib/widgets/app_drawer.dart | 2 +- pubspec.lock | 37 +++++++++++++++++---------- pubspec.yaml | 2 +- 5 files changed, 61 insertions(+), 53 deletions(-) diff --git a/lib/screens/app_detail_screen.dart b/lib/screens/app_detail_screen.dart index 0a3875c..3287494 100644 --- a/lib/screens/app_detail_screen.dart +++ b/lib/screens/app_detail_screen.dart @@ -6,11 +6,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; import 'package:gap/gap.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:percent_indicator/linear_percent_indicator.dart'; +import 'package:toastification/toastification.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:zapstore/main.data.dart'; import 'package:zapstore/models/app.dart'; @@ -190,19 +190,8 @@ class AppDetailScreen extends HookConsumerWidget { onTap: () { Clipboard.setData(ClipboardData( text: app.latestMetadata!.hash!)); - showToast( - 'Copied APK package SHA-256 to the clipboard', - duration: Duration(seconds: 3), - animDuration: - Duration(milliseconds: 300), - animation: - StyledToastAnimation.fade, - reverseAnimation: - StyledToastAnimation.fade, - position: - StyledToastPosition.bottom, - context: context, - ); + context.showInfo( + 'Copied APK package SHA-256 to the clipboard'); }, child: Row( mainAxisSize: MainAxisSize.min, @@ -234,19 +223,8 @@ class AppDetailScreen extends HookConsumerWidget { Clipboard.setData(ClipboardData( text: app.latestMetadata! .apkSignatureHash!)); - showToast( - 'Copied APK certificate SHA-256 to the clipboard', - duration: Duration(seconds: 3), - animDuration: - Duration(milliseconds: 300), - animation: - StyledToastAnimation.fade, - reverseAnimation: - StyledToastAnimation.fade, - position: - StyledToastPosition.bottom, - context: context, - ); + context.showInfo( + 'Copied APK certificate SHA-256 to the clipboard'); }, child: Row( mainAxisSize: MainAxisSize.min, diff --git a/lib/utils/extensions.dart b/lib/utils/extensions.dart index 7d9cfef..d9c6704 100644 --- a/lib/utils/extensions.dart +++ b/lib/utils/extensions.dart @@ -1,19 +1,38 @@ import 'package:flutter/material.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:toastification/toastification.dart'; extension ContextX on BuildContext { ThemeData get theme => Theme.of(this); - void showError(String message) { - showToast( - message, - duration: Duration(seconds: 5), - textStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 18), - animDuration: Duration(milliseconds: 300), - animation: StyledToastAnimation.fade, - reverseAnimation: StyledToastAnimation.fade, - backgroundColor: Color.fromARGB(230, 244, 67, 54), - position: StyledToastPosition.center, + void showInfo(String message, {Icon? icon}) { + toastification.show( context: this, + type: ToastificationType.info, + icon: icon ?? Icon(Icons.info), + style: ToastificationStyle.fillColored, + title: Text( + message, + style: TextStyle(fontSize: 16), + ), + autoCloseDuration: const Duration(seconds: 3), + showProgressBar: false, + closeOnClick: true, + alignment: Alignment.bottomCenter, + ); + } + + void showError(String message, {Icon? icon}) { + toastification.show( + context: this, + type: ToastificationType.error, + style: ToastificationStyle.fillColored, + icon: icon ?? Icon(Icons.error), + title: Text( + message, + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + showProgressBar: false, + closeOnClick: true, + alignment: Alignment.lerp(Alignment.bottomCenter, Alignment.center, 0.25), ); } } diff --git a/lib/widgets/app_drawer.dart b/lib/widgets/app_drawer.dart index 2a7188d..a14fdce 100644 --- a/lib/widgets/app_drawer.dart +++ b/lib/widgets/app_drawer.dart @@ -82,7 +82,7 @@ class LoginContainer extends HookConsumerWidget { .then((user) { ref.settings.findOneLocalById('_')!.user.value = user; }).catchError((e) { - context.showError(e.toString()); + context.showError(e.message ?? e.toString()); }); }, builder: (context, child, callback, buttonState) { diff --git a/pubspec.lock b/pubspec.lock index 47a6e23..c0b9496 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -389,11 +389,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" - flutter_localizations: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" flutter_markdown: dependency: "direct main" description: @@ -418,14 +413,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.5.1" - flutter_styled_toast: - dependency: "direct main" - description: - name: flutter_styled_toast - sha256: e667f13a665820eb0fa8506547e47eacbcddf1948d6d3036cfd3b089bd4b0516 - url: "https://pub.dev" - source: hosted - version: "2.2.1" flutter_test: dependency: "direct dev" description: flutter @@ -524,6 +511,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.0" + iconsax_flutter: + dependency: transitive + description: + name: iconsax_flutter + sha256: "95b65699da8ea98f87c5d232f06b0debaaf1ec1332b697e4d90969ec9a93037d" + url: "https://pub.dev" + source: hosted + version: "1.0.0" image: dependency: transitive description: @@ -740,6 +735,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.1" + pausable_timer: + dependency: transitive + description: + name: pausable_timer + sha256: "6ef1a95441ec3439de6fb63f39a011b67e693198e7dae14e20675c3c00e86074" + url: "https://pub.dev" + source: hosted + version: "3.1.0+3" percent_indicator: dependency: "direct main" description: @@ -1056,6 +1059,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" + toastification: + dependency: "direct main" + description: + name: toastification + sha256: "5e751acc2fb5b8d008138dac255d62290fde4e5a24824f29809ac098c3dfe395" + url: "https://pub.dev" + source: hosted + version: "2.0.0" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 687b107..dd09bca 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,7 +25,6 @@ dependencies: http: ^1.2.1 async_button_builder: ^3.0.0+1 android_package_manager: ^0.7.1 - flutter_styled_toast: ^2.2.1 url_launcher: ^6.2.5 device_apps: ^2.2.0 purplebase: ^0.1.0 @@ -42,6 +41,7 @@ dependencies: skeletonizer: ^1.1.2+1 flutter_phoenix: ^1.1.1 percent_indicator: ^4.2.3 + toastification: ^2.0.0 dependency_overrides: purplebase: