fix: replace platformdialog with adaptive dialog
This commit is contained in:
parent
91be906894
commit
7fed91e811
8 changed files with 85 additions and 105 deletions
|
@ -2,6 +2,7 @@
|
|||
# 1.0.0-alpha+5
|
||||
- Add tests
|
||||
- Add searching through entries to homepage
|
||||
- Replace `PlatformDialog` with `AlertDialog.adaptive`
|
||||
# 1.0.0-alpha+4
|
||||
- Fix OCR downloads
|
||||
# 1.0.0-alpha+3
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
// ignore_for_file: public_member_api_docs
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:prasule/pw/platformwidget.dart';
|
||||
|
||||
/// A [PlatformWidget] implementation of a dialog
|
||||
class PlatformDialog extends PlatformWidget<AlertDialog, CupertinoAlertDialog> {
|
||||
const PlatformDialog(
|
||||
{required this.title, super.key, this.content, this.actions = const [],});
|
||||
final String title;
|
||||
final Widget? content;
|
||||
final List<Widget> actions;
|
||||
|
||||
@override
|
||||
AlertDialog createAndroidWidget(BuildContext context) => AlertDialog(
|
||||
title: Text(title),
|
||||
content:
|
||||
(content != null) ? SingleChildScrollView(child: content) : null,
|
||||
actions: actions,
|
||||
);
|
||||
|
||||
@override
|
||||
CupertinoAlertDialog createIosWidget(BuildContext context) =>
|
||||
CupertinoAlertDialog(
|
||||
title: Text(title),
|
||||
content:
|
||||
(content != null) ? SingleChildScrollView(child: content) : null,
|
||||
actions: actions,
|
||||
);
|
||||
}
|
|
@ -21,7 +21,6 @@ import 'package:prasule/api/wallet_manager.dart';
|
|||
import 'package:prasule/main.dart';
|
||||
import 'package:prasule/network/tessdata.dart';
|
||||
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/drawer.dart';
|
||||
|
@ -448,12 +447,15 @@ class _HomeViewState extends State<HomeView> {
|
|||
.onError,
|
||||
icon: Icons.delete,
|
||||
onPressed: (c) {
|
||||
showDialog(
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (cx) => PlatformDialog(
|
||||
title: AppLocalizations.of(
|
||||
context,
|
||||
).sureDialog,
|
||||
builder: (cx) =>
|
||||
AlertDialog.adaptive(
|
||||
title: Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).sureDialog,
|
||||
),
|
||||
content: Text(
|
||||
AppLocalizations.of(context)
|
||||
.deleteSure,
|
||||
|
@ -595,10 +597,10 @@ class _HomeViewState extends State<HomeView> {
|
|||
final availableLanguages = await TessdataApi.getDownloadedData();
|
||||
if (availableLanguages.isEmpty) {
|
||||
if (!mounted) return;
|
||||
await showDialog(
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => PlatformDialog(
|
||||
title: AppLocalizations.of(context).missingOcr,
|
||||
builder: (c) => AlertDialog.adaptive(
|
||||
title: Text(AppLocalizations.of(context).missingOcr),
|
||||
actions: [
|
||||
PlatformButton(
|
||||
text: AppLocalizations.of(context).download,
|
||||
|
@ -628,10 +630,10 @@ class _HomeViewState extends State<HomeView> {
|
|||
List<bool>.filled(availableLanguages.length, false);
|
||||
selectedLanguages[0] = true;
|
||||
|
||||
await showDialog(
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => StatefulBuilder(
|
||||
builder: (ctx, setState) => PlatformDialog(
|
||||
builder: (ctx, setState) => AlertDialog.adaptive(
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
|
@ -652,10 +654,10 @@ class _HomeViewState extends State<HomeView> {
|
|||
logger.i(selected);
|
||||
if (!mounted) return;
|
||||
unawaited(
|
||||
showDialog(
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => PlatformDialog(
|
||||
title: AppLocalizations.of(context).ocrLoading,
|
||||
builder: (c) => AlertDialog.adaptive(
|
||||
title: Text(AppLocalizations.of(context).ocrLoading),
|
||||
),
|
||||
barrierDismissible: false,
|
||||
),
|
||||
|
@ -723,7 +725,7 @@ class _HomeViewState extends State<HomeView> {
|
|||
child: const Text("Cancel"),
|
||||
),
|
||||
],
|
||||
title: AppLocalizations.of(context).ocrSelect,
|
||||
title: Text(AppLocalizations.of(context).ocrSelect),
|
||||
content: Column(
|
||||
children: [
|
||||
...List.generate(
|
||||
|
|
|
@ -11,7 +11,6 @@ import 'package:prasule/api/recurring_entry.dart';
|
|||
import 'package:prasule/api/wallet.dart';
|
||||
import 'package:prasule/api/wallet_manager.dart';
|
||||
import 'package:prasule/pw/platformbutton.dart';
|
||||
import 'package:prasule/pw/platformdialog.dart';
|
||||
import 'package:prasule/pw/platformroute.dart';
|
||||
import 'package:prasule/util/drawer.dart';
|
||||
import 'package:prasule/util/text_color.dart';
|
||||
|
@ -215,9 +214,10 @@ class _RecurringEntriesViewState extends State<RecurringEntriesView> {
|
|||
onPressed: (c) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (cx) => PlatformDialog(
|
||||
title:
|
||||
AppLocalizations.of(context).sureDialog,
|
||||
builder: (cx) => AlertDialog.adaptive(
|
||||
title: Text(
|
||||
AppLocalizations.of(context).sureDialog,
|
||||
),
|
||||
content: Text(
|
||||
AppLocalizations.of(context).deleteSure,
|
||||
),
|
||||
|
|
|
@ -12,7 +12,6 @@ import 'package:prasule/api/wallet.dart';
|
|||
import 'package:prasule/api/wallet_manager.dart';
|
||||
import 'package:prasule/main.dart';
|
||||
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/text_color.dart';
|
||||
|
@ -147,9 +146,9 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
|
|||
.getBool("useMaterialYou") ??
|
||||
false;
|
||||
if (!context.mounted) return;
|
||||
await showDialog(
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => PlatformDialog(
|
||||
builder: (c) => AlertDialog.adaptive(
|
||||
actions: [
|
||||
PlatformButton(
|
||||
text: AppLocalizations.of(context).done,
|
||||
|
@ -158,8 +157,8 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
|
|||
},
|
||||
),
|
||||
],
|
||||
title:
|
||||
AppLocalizations.of(context).pickColor,
|
||||
title: Text(
|
||||
AppLocalizations.of(context).pickColor),
|
||||
content: Column(
|
||||
children: [
|
||||
ColorPicker(
|
||||
|
@ -215,9 +214,9 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
|
|||
final controller = TextEditingController(
|
||||
text: selectedWallet!.categories[i].name,
|
||||
);
|
||||
showDialog(
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => PlatformDialog(
|
||||
builder: (c) => AlertDialog.adaptive(
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
|
@ -243,8 +242,8 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
|
|||
),
|
||||
),
|
||||
],
|
||||
title: AppLocalizations.of(context)
|
||||
.setupCategoriesEditingName,
|
||||
title: Text(AppLocalizations.of(context)
|
||||
.setupCategoriesEditingName),
|
||||
content: SizedBox(
|
||||
width: 400,
|
||||
child:
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:prasule/pw/platformdialog.dart';
|
||||
import 'package:settings_ui/settings_ui.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
@ -50,10 +49,10 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
|
|||
? AppLocalizations.of(context).barChart
|
||||
: AppLocalizations.of(context).lineChart,
|
||||
),
|
||||
onPressed: (c) => showDialog(
|
||||
onPressed: (c) => showAdaptiveDialog(
|
||||
context: c,
|
||||
builder: (ctx) => PlatformDialog(
|
||||
title: AppLocalizations.of(context).selectType,
|
||||
builder: (ctx) => AlertDialog.adaptive(
|
||||
title: Text(AppLocalizations.of(context).selectType),
|
||||
content: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
|
@ -110,8 +109,8 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
|
|||
),
|
||||
onPressed: (c) => showDialog(
|
||||
context: c,
|
||||
builder: (ctx) => PlatformDialog(
|
||||
title: AppLocalizations.of(context).selectType,
|
||||
builder: (ctx) => AlertDialog.adaptive(
|
||||
title: Text(AppLocalizations.of(context).selectType),
|
||||
content: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
|
|
|
@ -9,7 +9,6 @@ import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart';
|
|||
import 'package:prasule/main.dart';
|
||||
import 'package:prasule/network/tessdata.dart';
|
||||
import 'package:prasule/pw/platformbutton.dart';
|
||||
import 'package:prasule/pw/platformdialog.dart';
|
||||
|
||||
/// Used to manage downloaded Tessdata for OCR
|
||||
class TessdataListView extends StatefulWidget {
|
||||
|
@ -62,10 +61,11 @@ class _TessdataListViewState extends State<TessdataListView> {
|
|||
final lang = _tessdata[i].keys.first;
|
||||
if (_tessdata[i][lang]!) {
|
||||
// deleting data
|
||||
await showDialog(
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (context) => PlatformDialog(
|
||||
title: AppLocalizations.of(context).sureDialog,
|
||||
builder: (context) => AlertDialog.adaptive(
|
||||
title:
|
||||
Text(AppLocalizations.of(context).sureDialog),
|
||||
content: Text(
|
||||
AppLocalizations.of(context).deleteOcr(lang),
|
||||
),
|
||||
|
@ -98,11 +98,11 @@ class _TessdataListViewState extends State<TessdataListView> {
|
|||
final progressStream = StreamController<double>();
|
||||
|
||||
unawaited(
|
||||
showDialog(
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => PlatformDialog(
|
||||
title: AppLocalizations.of(context)
|
||||
.langDownloadDialog(lang),
|
||||
builder: (c) => AlertDialog.adaptive(
|
||||
title: Text(AppLocalizations.of(context)
|
||||
.langDownloadDialog(lang)),
|
||||
content: StreamBuilder(
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState ==
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
// ignore_for_file: inference_failure_on_function_invocation
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:currency_picker/currency_picker.dart';
|
||||
import 'package:dynamic_color/dynamic_color.dart';
|
||||
import 'package:flex_color_picker/flex_color_picker.dart';
|
||||
|
@ -12,7 +14,6 @@ import 'package:prasule/api/category.dart';
|
|||
import 'package:prasule/api/wallet.dart';
|
||||
import 'package:prasule/api/wallet_manager.dart';
|
||||
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';
|
||||
|
@ -118,11 +119,22 @@ class _SetupViewState extends State<SetupView> {
|
|||
next: Text(AppLocalizations.of(context).next),
|
||||
back: Text(AppLocalizations.of(context).back),
|
||||
done: Text(AppLocalizations.of(context).finish),
|
||||
onDone: () {
|
||||
onDone: () async {
|
||||
if (name.isEmpty) {
|
||||
showMessage(
|
||||
AppLocalizations.of(context).errorEmptyName,
|
||||
context,
|
||||
unawaited(
|
||||
showMessage(
|
||||
AppLocalizations.of(context).errorEmptyName,
|
||||
context,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (await WalletManager.exists(name) && context.mounted) {
|
||||
unawaited(
|
||||
showMessage(
|
||||
AppLocalizations.of(context).walletExists,
|
||||
context,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -131,25 +143,19 @@ class _SetupViewState extends State<SetupView> {
|
|||
currency: _selectedCurrency,
|
||||
categories: categories,
|
||||
);
|
||||
WalletManager.saveWallet(wallet).then(
|
||||
(value) {
|
||||
if (!value) {
|
||||
showMessage(
|
||||
AppLocalizations.of(context).walletExists,
|
||||
context,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (widget.newWallet) {
|
||||
Navigator.of(context).pop();
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pushReplacement(
|
||||
platformRoute(
|
||||
(c) => const HomeView(),
|
||||
),
|
||||
);
|
||||
},
|
||||
await WalletManager.saveWallet(wallet);
|
||||
|
||||
if (widget.newWallet && context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
unawaited(
|
||||
Navigator.of(context).pushReplacement(
|
||||
platformRoute(
|
||||
(c) => const HomeView(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
pages: [
|
||||
|
@ -298,9 +304,9 @@ class _SetupViewState extends State<SetupView> {
|
|||
.getBool("useMaterialYou") ??
|
||||
false;
|
||||
if (!context.mounted) return;
|
||||
await showDialog(
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => PlatformDialog(
|
||||
builder: (c) => AlertDialog.adaptive(
|
||||
actions: [
|
||||
PlatformButton(
|
||||
text: AppLocalizations.of(context)
|
||||
|
@ -310,8 +316,10 @@ class _SetupViewState extends State<SetupView> {
|
|||
},
|
||||
),
|
||||
],
|
||||
title: AppLocalizations.of(context)
|
||||
.pickColor,
|
||||
title: Text(
|
||||
AppLocalizations.of(context)
|
||||
.pickColor,
|
||||
),
|
||||
content: Column(
|
||||
children: [
|
||||
ColorPicker(
|
||||
|
@ -363,9 +371,9 @@ class _SetupViewState extends State<SetupView> {
|
|||
final controller = TextEditingController(
|
||||
text: categories[i].name,
|
||||
);
|
||||
showDialog(
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => PlatformDialog(
|
||||
builder: (c) => AlertDialog.adaptive(
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
|
@ -390,8 +398,10 @@ class _SetupViewState extends State<SetupView> {
|
|||
),
|
||||
),
|
||||
],
|
||||
title: AppLocalizations.of(context)
|
||||
.setupCategoriesEditingName,
|
||||
title: Text(
|
||||
AppLocalizations.of(context)
|
||||
.setupCategoriesEditingName,
|
||||
),
|
||||
content: SizedBox(
|
||||
width: 400,
|
||||
child: PlatformField(
|
||||
|
|
Loading…
Reference in a new issue