Skip to content

Commit

Permalink
Merge pull request #15 from flow-mn/sadespresso/issue14
Browse files Browse the repository at this point in the history
Switch to `toastification`
  • Loading branch information
sadespresso authored Feb 11, 2024
2 parents 9644b37 + ea94f70 commit 18c6cd8
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 64 deletions.
38 changes: 16 additions & 22 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart';
import 'package:moment_dart/moment_dart.dart';
import 'package:oktoast/oktoast.dart';
import 'package:pie_menu/pie_menu.dart';

const appVersion = "0.1.2+4";
const appVersion = "0.1.3+5";

final String namedVersion = appVersion.split("+").first;
final int buildNumber = int.parse(appVersion.split("+").last);
Expand Down Expand Up @@ -99,26 +98,21 @@ class FlowState extends State<Flow> {

@override
Widget build(BuildContext context) {
return OKToast(
backgroundColor: lightTheme.colorScheme.background,
textStyle: lightTheme.textTheme.bodyMedium,
child: MaterialApp.router(
onGenerateTitle: (context) => "appName".t(context),
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
if (kDebugMode || Platform.isIOS)
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
FlowLocalizations.delegate,
],
supportedLocales: FlowLocalizations.supportedLanguages,
locale: LocalPreferences().localeOverride.value,
routerConfig: router,
theme: lightTheme,
darkTheme: darkTheme,
themeMode: _themeMode,
debugShowCheckedModeBanner: false,
),
return MaterialApp.router(
onGenerateTitle: (context) => "appName".t(context),
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
if (kDebugMode || Platform.isIOS) GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
FlowLocalizations.delegate,
],
supportedLocales: FlowLocalizations.supportedLanguages,
locale: LocalPreferences().localeOverride.value,
routerConfig: router,
theme: lightTheme,
darkTheme: darkTheme,
themeMode: _themeMode,
debugShowCheckedModeBanner: false,
);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/routes/home/profile_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,11 @@ class _ProfileTabState extends State<ProfileTab> {
if (context.mounted) {
context.showToast(
text: "sync.import.successful".t(context),
error: true,
);
}
} catch (e) {
if (context.mounted) {
context.showToast(text: e.toString(), error: true);
context.showErrorToast(error: e);
}
}
}
Expand Down
54 changes: 26 additions & 28 deletions lib/utils/toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'package:flow/theme/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:oktoast/oktoast.dart';
import 'package:toastification/toastification.dart';

extension ToastHelper on BuildContext {
ToastFuture showErrorToast({required dynamic error, Widget? icon}) =>
ToastificationItem showErrorToast({required dynamic error, Widget? icon}) =>
showToast(
text: switch (error) {
LocalizedException localizedException =>
Expand All @@ -15,45 +15,43 @@ extension ToastHelper on BuildContext {
_ => error.toString(),
},
icon: icon,
error: true,
type: ToastificationType.error,
);

ToastFuture showToast({
ToastificationItem showToast({
required String text,
bool error = false,
ToastificationType type = ToastificationType.success,
Widget? icon,
}) {
icon ??= Icon(
Symbols.error_circle_rounded_error_rounded,
color: colorScheme.error,
);

final Widget contents = Material(
elevation: 2.0,
borderRadius: BorderRadius.circular(16.0),
type: MaterialType.card,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
child: Row(
children: [
icon,
const SizedBox(width: 12.0),
Flexible(child: Text(text)),
],
),
),
);

if (error) {
if (type == ToastificationType.error) {
HapticFeedback.heavyImpact();
}

return showToastWidget(
Padding(
padding: const EdgeInsets.all(16.0),
child: contents,
),
position: const ToastPosition(align: Alignment.topCenter),
return toastification.show(
context: this,
title: Text(text),
type: type,
icon: icon,
autoCloseDuration: const Duration(seconds: 5),
alignment: Alignment.topCenter,
primaryColor: colorScheme.primary,
backgroundColor: colorScheme.background,
foregroundColor: colorScheme.onBackground,
showProgressBar: false,
style: ToastificationStyle.flat,
boxShadow: [
BoxShadow(
color: colorScheme.onBackground.withAlpha(0x40),
offset: const Offset(0.0, 1.0),
blurRadius: 4.0,
spreadRadius: -1.5,
)
],
);
}
}
40 changes: 32 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.4"
equatable:
dependency: transitive
description:
name: equatable
sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2
url: "https://pub.dev"
source: hosted
version: "2.0.5"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -461,6 +469,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
iconsax_flutter:
dependency: transitive
description:
name: iconsax_flutter
sha256: "95b65699da8ea98f87c5d232f06b0debaaf1ec1332b697e4d90969ec9a93037d"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
image:
dependency: transitive
description:
Expand Down Expand Up @@ -677,14 +693,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.0"
oktoast:
dependency: "direct main"
description:
name: oktoast
sha256: f1366c5c793ddfb8f55bc6fc3e45db43c45debf173b765fb4c5ec096cbdeb84a
url: "https://pub.dev"
source: hosted
version: "3.4.0"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -749,6 +757,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"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -1019,6 +1035,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.1"
toastification:
dependency: "direct main"
description:
name: toastification
sha256: "18293318ffcdc5b6fb10289eb18b9addfef56f053b824c320fbdddcf6a48bab1"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
typed_data:
dependency: transitive
description:
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A personal finance tracking app.

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: 0.1.2+4
version: 0.1.3+5

environment:
sdk: ">=3.1.3 <4.0.0"
Expand Down Expand Up @@ -35,7 +35,6 @@ dependencies:
moment_dart: ^1.1.1
objectbox: ^2.4.0
objectbox_flutter_libs: ^2.4.0
oktoast: ^3.4.0
path: ^1.8.3
path_provider: ^2.1.1
# pie_menu: ^3.1.3
Expand All @@ -46,20 +45,21 @@ dependencies:
share_plus: ^7.2.2
shared_preferences: ^2.2.2
simple_icons: ^10.1.3
toastification: ^1.2.0
url_launcher: ^6.2.3
uuid: ^4.2.2

dev_dependencies:
build_runner: ^2.4.8

flutter_launcher_icons: ^0.13.1

flutter_lints: ^3.0.0
flutter_test:
sdk: flutter
json_serializable: ^6.7.1
objectbox_generator: ^2.3.1

flutter_launcher_icons: ^0.13.1

flutter:
generate: true
uses-material-design: true
Expand Down

0 comments on commit 18c6cd8

Please sign in to comment.