fix: iOS specific fixes #21

Merged
hernik merged 1 commit from dev-ios into dev 2024-01-09 00:31:04 +01:00
9 changed files with 75 additions and 41 deletions

View file

@ -75,6 +75,11 @@ class MyApp extends StatelessWidget {
: lightColorScheme, : lightColorScheme,
), ),
child: const CupertinoApp( child: const CupertinoApp(
localizationsDelegates: [
AppLocalizations.delegate,
...GlobalMaterialLocalizations.delegates,
...GlobalCupertinoLocalizations.delegates,
],
title: 'Prašule', title: 'Prašule',
home: HomeView(), home: HomeView(),
), ),

View file

@ -61,7 +61,7 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
controller: controller, controller: controller,
enabled: enabled ?? true, enabled: enabled ?? true,
obscureText: obscureText, obscureText: obscureText,
prefix: (labelText == null) ? null : Text(labelText!), placeholder: labelText,
autocorrect: autocorrect, autocorrect: autocorrect,
keyboardType: keyboardType, keyboardType: keyboardType,
inputFormatters: inputFormatters, inputFormatters: inputFormatters,

View file

@ -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<void> 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)));
}
}

View file

@ -8,6 +8,7 @@ import 'package:prasule/api/wallet_entry.dart';
import 'package:prasule/api/wallet_manager.dart'; import 'package:prasule/api/wallet_manager.dart';
import 'package:prasule/pw/platformbutton.dart'; import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformfield.dart'; import 'package:prasule/pw/platformfield.dart';
import 'package:prasule/util/show_message.dart';
/// Used when user wants to add new entry /// Used when user wants to add new entry
class CreateSingleEntryView extends StatefulWidget { class CreateSingleEntryView extends StatefulWidget {
@ -190,13 +191,8 @@ class _CreateSingleEntryViewState extends State<CreateSingleEntryView> {
text: AppLocalizations.of(context).save, text: AppLocalizations.of(context).save,
onPressed: () { onPressed: () {
if (newEntry.data.name.isEmpty) { if (newEntry.data.name.isEmpty) {
ScaffoldMessenger.of(context).clearSnackBars(); showMessage(
ScaffoldMessenger.of(context).showSnackBar( AppLocalizations.of(context).errorEmptyName, context);
SnackBar(
content:
Text(AppLocalizations.of(context).errorEmptyName),
),
);
return; return;
} }
if (widget.editEntry != null) { if (widget.editEntry != null) {

View file

@ -10,6 +10,7 @@ import 'package:prasule/api/wallet_manager.dart';
import 'package:prasule/main.dart'; import 'package:prasule/main.dart';
import 'package:prasule/pw/platformbutton.dart'; import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformfield.dart'; import 'package:prasule/pw/platformfield.dart';
import 'package:prasule/util/show_message.dart';
/// Used when user wants to add new entry /// Used when user wants to add new entry
class CreateRecurringEntryView extends StatefulWidget { class CreateRecurringEntryView extends StatefulWidget {
@ -313,13 +314,8 @@ class _CreateRecurringEntryViewState extends State<CreateRecurringEntryView> {
text: AppLocalizations.of(context).save, text: AppLocalizations.of(context).save,
onPressed: () { onPressed: () {
if (newEntry.data.name.isEmpty) { if (newEntry.data.name.isEmpty) {
ScaffoldMessenger.of(context).clearSnackBars(); showMessage(
ScaffoldMessenger.of(context).showSnackBar( AppLocalizations.of(context).errorEmptyName, context);
SnackBar(
content:
Text(AppLocalizations.of(context).errorEmptyName),
),
);
return; return;
} }
if (widget.editEntry != null) { if (widget.editEntry != null) {

View file

@ -442,6 +442,12 @@ class _HomeViewState extends State<HomeView> {
TextSpan( TextSpan(
text: text:
" | ${DateFormat.MMMd(locale).format(element.date)}", " | ${DateFormat.MMMd(locale).format(element.date)}",
style: TextStyle(
color: Theme.of(context)
.colorScheme
.background
.calculateTextColor(),
),
), ),
], ],
), ),
@ -458,19 +464,29 @@ class _HomeViewState extends State<HomeView> {
final availableLanguages = await TessdataApi.getDownloadedData(); final availableLanguages = await TessdataApi.getDownloadedData();
if (availableLanguages.isEmpty) { if (availableLanguages.isEmpty) {
if (!mounted) return; if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar( await showDialog(
SnackBar( context: context,
content: Text(AppLocalizations.of(context).missingOcr), builder: (c) => PlatformDialog(
action: SnackBarAction( title: AppLocalizations.of(context).missingOcr,
label: AppLocalizations.of(context).download, actions: [
PlatformButton(
text: AppLocalizations.of(context).download,
onPressed: () { onPressed: () {
Navigator.of(context).push( Navigator.of(context).push(
platformRoute( platformRoute(
(c) => const TessdataListView(), (c) => const TessdataListView(),
), ),
); );
Navigator.of(c).pop();
}, },
), ),
PlatformButton(
text: AppLocalizations.of(context).ok,
onPressed: () {
Navigator.of(c).pop();
},
),
],
), ),
); );
return; return;

View file

@ -15,6 +15,7 @@ import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformdialog.dart'; import 'package:prasule/pw/platformdialog.dart';
import 'package:prasule/pw/platformfield.dart'; import 'package:prasule/pw/platformfield.dart';
import 'package:prasule/pw/platformroute.dart'; import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/util/show_message.dart';
import 'package:prasule/util/text_color.dart'; import 'package:prasule/util/text_color.dart';
import 'package:prasule/views/home.dart'; import 'package:prasule/views/home.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -119,12 +120,9 @@ class _SetupViewState extends State<SetupView> {
done: Text(AppLocalizations.of(context).finish), done: Text(AppLocalizations.of(context).finish),
onDone: () { onDone: () {
if (name.isEmpty) { if (name.isEmpty) {
ScaffoldMessenger.of(context) showMessage(
.clearSnackBars(); // TODO: iOS replacement AppLocalizations.of(context).errorEmptyName,
ScaffoldMessenger.of(context).showSnackBar( context,
SnackBar(
content: Text(AppLocalizations.of(context).errorEmptyName),
),
); );
return; return;
} }
@ -136,12 +134,9 @@ class _SetupViewState extends State<SetupView> {
WalletManager.saveWallet(wallet).then( WalletManager.saveWallet(wallet).then(
(value) { (value) {
if (!value) { if (!value) {
ScaffoldMessenger.of(context).clearSnackBars(); showMessage(
ScaffoldMessenger.of(context).showSnackBar( AppLocalizations.of(context).walletExists,
SnackBar( context,
content:
Text(AppLocalizations.of(context).walletExists),
),
); );
return; return;
} }
@ -254,7 +249,9 @@ class _SetupViewState extends State<SetupView> {
), ),
], ],
onChanged: (t) { onChanged: (t) {
balance = double.parse(t); final b = double.tryParse(t);
if (b == null) return;
balance = b;
}, },
), ),
), ),

View file

@ -466,6 +466,14 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" 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: font_awesome_flutter:
dependency: transitive dependency: transitive
description: description:

View file

@ -27,6 +27,7 @@ dependencies:
flutter_slidable: ^3.0.0 flutter_slidable: ^3.0.0
flutter_speed_dial: ^7.0.0 flutter_speed_dial: ^7.0.0
flutter_tesseract_ocr: ^0.4.23 flutter_tesseract_ocr: ^0.4.23
fluttertoast: ^8.2.4
grouped_list: ^5.1.2 grouped_list: ^5.1.2
image_picker: ^1.0.1 image_picker: ^1.0.1
intl: any intl: any