Better toasts

This commit is contained in:
franzap
2024-06-14 13:17:59 -03:00
parent b79b42d5d3
commit 483fbea079
5 changed files with 61 additions and 53 deletions
+5 -27
View File
@@ -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,
+30 -11
View File
@@ -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),
);
}
}
+1 -1
View File
@@ -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) {
+24 -13
View File
@@ -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:
+1 -1
View File
@@ -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: