fix: iOS specific fixes (#21)

Reviewed-on: #21
This commit is contained in:
Matyáš Caras 2024-01-09 00:31:03 +01:00
parent efc003a719
commit 0dbcedd0ca
9 changed files with 75 additions and 41 deletions

View file

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

View file

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

View file

@ -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<CreateRecurringEntryView> {
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) {

View file

@ -442,6 +442,12 @@ class _HomeViewState extends State<HomeView> {
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<HomeView> {
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,
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;

View file

@ -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<SetupView> {
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<SetupView> {
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<SetupView> {
),
],
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
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:

View file

@ -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