diff --git a/lib/main.dart b/lib/main.dart index 19f6961..9a86716 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -75,6 +75,11 @@ class MyApp extends StatelessWidget { : lightColorScheme, ), child: const CupertinoApp( + localizationsDelegates: [ + AppLocalizations.delegate, + ...GlobalMaterialLocalizations.delegates, + ...GlobalCupertinoLocalizations.delegates, + ], title: 'PraĊĦule', home: HomeView(), ), diff --git a/lib/pw/platformfield.dart b/lib/pw/platformfield.dart index 331b8f8..710e534 100644 --- a/lib/pw/platformfield.dart +++ b/lib/pw/platformfield.dart @@ -61,7 +61,7 @@ class PlatformField extends PlatformWidget { controller: controller, enabled: enabled ?? true, obscureText: obscureText, - prefix: (labelText == null) ? null : Text(labelText!), + placeholder: labelText, autocorrect: autocorrect, keyboardType: keyboardType, inputFormatters: inputFormatters, diff --git a/lib/util/show_message.dart b/lib/util/show_message.dart new file mode 100644 index 0000000..b705449 --- /dev/null +++ b/lib/util/show_message.dart @@ -0,0 +1,15 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +/// Shows either SnackBar on Android or Toast on iOS +Future showMessage(String message, BuildContext context) async { + if (Platform.isIOS) { + await Fluttertoast.showToast(msg: message, toastLength: Toast.LENGTH_LONG); + } else { + ScaffoldMessenger.of(context).clearSnackBars(); + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(content: Text(message))); + } +} diff --git a/lib/views/create_entry.dart b/lib/views/create_entry.dart index 3640241..1b27c8c 100644 --- a/lib/views/create_entry.dart +++ b/lib/views/create_entry.dart @@ -8,6 +8,7 @@ import 'package:prasule/api/wallet_entry.dart'; import 'package:prasule/api/wallet_manager.dart'; import 'package:prasule/pw/platformbutton.dart'; import 'package:prasule/pw/platformfield.dart'; +import 'package:prasule/util/show_message.dart'; /// Used when user wants to add new entry class CreateSingleEntryView extends StatefulWidget { @@ -190,13 +191,8 @@ class _CreateSingleEntryViewState extends State { text: AppLocalizations.of(context).save, onPressed: () { if (newEntry.data.name.isEmpty) { - ScaffoldMessenger.of(context).clearSnackBars(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: - Text(AppLocalizations.of(context).errorEmptyName), - ), - ); + showMessage( + AppLocalizations.of(context).errorEmptyName, context); return; } if (widget.editEntry != null) { diff --git a/lib/views/create_recur_entry.dart b/lib/views/create_recur_entry.dart index 6047980..1ad51a6 100644 --- a/lib/views/create_recur_entry.dart +++ b/lib/views/create_recur_entry.dart @@ -10,6 +10,7 @@ import 'package:prasule/api/wallet_manager.dart'; import 'package:prasule/main.dart'; import 'package:prasule/pw/platformbutton.dart'; import 'package:prasule/pw/platformfield.dart'; +import 'package:prasule/util/show_message.dart'; /// Used when user wants to add new entry class CreateRecurringEntryView extends StatefulWidget { @@ -313,13 +314,8 @@ class _CreateRecurringEntryViewState extends State { text: AppLocalizations.of(context).save, onPressed: () { if (newEntry.data.name.isEmpty) { - ScaffoldMessenger.of(context).clearSnackBars(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: - Text(AppLocalizations.of(context).errorEmptyName), - ), - ); + showMessage( + AppLocalizations.of(context).errorEmptyName, context); return; } if (widget.editEntry != null) { diff --git a/lib/views/home.dart b/lib/views/home.dart index f18722a..6b31dac 100644 --- a/lib/views/home.dart +++ b/lib/views/home.dart @@ -442,6 +442,12 @@ class _HomeViewState extends State { TextSpan( text: " | ${DateFormat.MMMd(locale).format(element.date)}", + style: TextStyle( + color: Theme.of(context) + .colorScheme + .background + .calculateTextColor(), + ), ), ], ), @@ -458,19 +464,29 @@ class _HomeViewState extends State { final availableLanguages = await TessdataApi.getDownloadedData(); if (availableLanguages.isEmpty) { if (!mounted) return; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(AppLocalizations.of(context).missingOcr), - action: SnackBarAction( - label: AppLocalizations.of(context).download, - onPressed: () { - Navigator.of(context).push( - platformRoute( - (c) => const TessdataListView(), - ), - ); - }, - ), + await showDialog( + context: context, + builder: (c) => PlatformDialog( + title: AppLocalizations.of(context).missingOcr, + actions: [ + PlatformButton( + text: AppLocalizations.of(context).download, + onPressed: () { + Navigator.of(context).push( + platformRoute( + (c) => const TessdataListView(), + ), + ); + Navigator.of(c).pop(); + }, + ), + PlatformButton( + text: AppLocalizations.of(context).ok, + onPressed: () { + Navigator.of(c).pop(); + }, + ), + ], ), ); return; diff --git a/lib/views/setup.dart b/lib/views/setup.dart index e273149..e8749e3 100644 --- a/lib/views/setup.dart +++ b/lib/views/setup.dart @@ -15,6 +15,7 @@ import 'package:prasule/pw/platformbutton.dart'; import 'package:prasule/pw/platformdialog.dart'; import 'package:prasule/pw/platformfield.dart'; import 'package:prasule/pw/platformroute.dart'; +import 'package:prasule/util/show_message.dart'; import 'package:prasule/util/text_color.dart'; import 'package:prasule/views/home.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -119,12 +120,9 @@ class _SetupViewState extends State { done: Text(AppLocalizations.of(context).finish), onDone: () { if (name.isEmpty) { - ScaffoldMessenger.of(context) - .clearSnackBars(); // TODO: iOS replacement - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(AppLocalizations.of(context).errorEmptyName), - ), + showMessage( + AppLocalizations.of(context).errorEmptyName, + context, ); return; } @@ -136,12 +134,9 @@ class _SetupViewState extends State { WalletManager.saveWallet(wallet).then( (value) { if (!value) { - ScaffoldMessenger.of(context).clearSnackBars(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: - Text(AppLocalizations.of(context).walletExists), - ), + showMessage( + AppLocalizations.of(context).walletExists, + context, ); return; } @@ -254,7 +249,9 @@ class _SetupViewState extends State { ), ], onChanged: (t) { - balance = double.parse(t); + final b = double.tryParse(t); + if (b == null) return; + balance = b; }, ), ), diff --git a/pubspec.lock b/pubspec.lock index 5e8710d..30c6e96 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -466,6 +466,14 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + sha256: dfdde255317af381bfc1c486ed968d5a43a2ded9c931e87cbecd88767d6a71c1 + url: "https://pub.dev" + source: hosted + version: "8.2.4" font_awesome_flutter: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 38afb3c..f79b64d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: flutter_slidable: ^3.0.0 flutter_speed_dial: ^7.0.0 flutter_tesseract_ocr: ^0.4.23 + fluttertoast: ^8.2.4 grouped_list: ^5.1.2 image_picker: ^1.0.1 intl: any