From 75913280bee70738f890830df3ba651d54fb5ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Mon, 12 Feb 2024 16:32:16 +0100 Subject: [PATCH 1/4] fix: return iOS widgets only on iOS/macOS --- CHANGELOG.md | 1 + lib/pw/platformwidget.dart | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07cf67f..b6f00e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Make pie chart values more visible by adding the category's corresponding color as background - Welcome text on Setup view is now centered - Editing entries is now done by tapping the entry, instead of a dedicated button +- return iOS (Cupertino) widgets only on iOS/macOS # 1.0.0-alpha+5 - Add tests diff --git a/lib/pw/platformwidget.dart b/lib/pw/platformwidget.dart index b48c0b0..5d7d290 100644 --- a/lib/pw/platformwidget.dart +++ b/lib/pw/platformwidget.dart @@ -11,10 +11,10 @@ abstract class PlatformWidget @override Widget build(BuildContext context) { - if (Platform.isAndroid) { - return createAndroidWidget(context); - } else { + if (Platform.isIOS || Platform.isMacOS) { return createIosWidget(context); + } else { + return createAndroidWidget(context); } } From 06d25b9a0c18535d8fa045654bc6e7972a9d838c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Mon, 12 Feb 2024 18:43:57 +0100 Subject: [PATCH 2/4] fix: show actionsheet instead of inkwell on iOS --- CHANGELOG.md | 1 + lib/views/settings/graph_type.dart | 279 +++++++++++++++++++---------- 2 files changed, 186 insertions(+), 94 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6f00e7..00c4570 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Welcome text on Setup view is now centered - Editing entries is now done by tapping the entry, instead of a dedicated button - return iOS (Cupertino) widgets only on iOS/macOS +- Show action sheet in graph settings on iOS instead of InkWell # 1.0.0-alpha+5 - Add tests diff --git a/lib/views/settings/graph_type.dart b/lib/views/settings/graph_type.dart index 14d1b02..b946ba6 100644 --- a/lib/views/settings/graph_type.dart +++ b/lib/views/settings/graph_type.dart @@ -1,3 +1,6 @@ +import 'dart:io'; + +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:settings_ui/settings_ui.dart'; @@ -47,59 +50,103 @@ class _GraphTypeSettingsViewState extends State { ? AppLocalizations.of(context).barChart : AppLocalizations.of(context).lineChart, ), - onPressed: (c) => showAdaptiveDialog( - context: c, - builder: (ctx) => AlertDialog.adaptive( - title: Text(AppLocalizations.of(context).selectType), - content: SizedBox( - height: 80, - child: Column( - children: [ - SizedBox( - width: MediaQuery.of(ctx).size.width, - child: InkWell( - child: Padding( - padding: const EdgeInsets.all(8), - child: Text( - AppLocalizations.of(context).barChart, - textAlign: TextAlign.center, - ), - ), - onTap: () async { - final s = await SharedPreferences.getInstance(); - await s.setInt("yearlygraph", 1); - _yearly = 1; - if (!ctx.mounted) return; - Navigator.of(ctx).pop(); - setState(() {}); - }, + onPressed: (c) { + if (Platform.isIOS) { + // iOS does not use Material widgets => no inkwell support + showCupertinoModalPopup( + context: context, + builder: (ctx) => CupertinoActionSheet( + title: Text(AppLocalizations.of(context).selectType), + actions: [ + CupertinoActionSheetAction( + onPressed: () async { + final s = await SharedPreferences.getInstance(); + await s.setInt("yearlygraph", 1); + _yearly = 1; + if (!ctx.mounted) return; + Navigator.of(ctx).pop(); + setState(() {}); + }, + child: Text( + AppLocalizations.of(context).barChart, + textAlign: TextAlign.center, ), ), - SizedBox( - width: MediaQuery.of(context).size.width, - child: InkWell( - child: Padding( - padding: const EdgeInsets.all(8), - child: Text( - AppLocalizations.of(context).lineChart, - textAlign: TextAlign.center, - ), - ), - onTap: () async { - final s = await SharedPreferences.getInstance(); - await s.setInt("yearlygraph", 2); - _yearly = 2; - if (!ctx.mounted) return; - Navigator.of(ctx).pop(); - setState(() {}); - }, + CupertinoActionSheetAction( + onPressed: () async { + final s = await SharedPreferences.getInstance(); + await s.setInt("yearlygraph", 2); + _yearly = 2; + if (!ctx.mounted) return; + Navigator.of(ctx).pop(); + setState(() {}); + }, + child: Text( + AppLocalizations.of(context).lineChart, + textAlign: TextAlign.center, ), ), ], ), - ), - ), - ), + ); + } else { + showAdaptiveDialog( + context: c, + builder: (ctx) => AlertDialog.adaptive( + title: Text(AppLocalizations.of(context).selectType), + content: SizedBox( + height: 80, + child: Column( + children: [ + SizedBox( + width: MediaQuery.of(ctx).size.width, + child: InkWell( + child: Padding( + padding: const EdgeInsets.all(8), + child: Text( + AppLocalizations.of(context).barChart, + textAlign: TextAlign.center, + ), + ), + onTap: () async { + final s = + await SharedPreferences.getInstance(); + await s.setInt("yearlygraph", 1); + _yearly = 1; + if (!ctx.mounted) return; + Navigator.of(ctx).pop(); + setState(() {}); + }, + ), + ), + SizedBox( + width: MediaQuery.of(context).size.width, + child: InkWell( + child: Padding( + padding: const EdgeInsets.all(8), + child: Text( + AppLocalizations.of(context).lineChart, + textAlign: TextAlign.center, + ), + ), + onTap: () async { + final s = + await SharedPreferences.getInstance(); + await s.setInt("yearlygraph", 2); + _yearly = 2; + if (!ctx.mounted) return; + Navigator.of(ctx).pop(); + setState(() {}); + }, + ), + ), + ], + ), + ), + ), + ); + } + }, ), SettingsTile.navigation( title: Text(AppLocalizations.of(context).monthly), @@ -108,59 +155,103 @@ class _GraphTypeSettingsViewState extends State { ? AppLocalizations.of(context).barChart : AppLocalizations.of(context).lineChart, ), - onPressed: (c) => showAdaptiveDialog( - context: c, - builder: (ctx) => AlertDialog.adaptive( - title: Text(AppLocalizations.of(context).selectType), - content: SizedBox( - height: 80, - child: Column( - children: [ - SizedBox( - width: MediaQuery.of(ctx).size.width, - child: InkWell( - child: Padding( - padding: const EdgeInsets.all(8), - child: Text( - AppLocalizations.of(context).barChart, - textAlign: TextAlign.center, - ), - ), - onTap: () async { - final s = await SharedPreferences.getInstance(); - await s.setInt("monthlygraph", 1); - _monthly = 1; - if (!ctx.mounted) return; - Navigator.of(ctx).pop(); - setState(() {}); - }, + onPressed: (c) { + if (Platform.isIOS) { + // iOS does not use Material widgets => no inkwell support + showCupertinoModalPopup( + context: context, + builder: (ctx) => CupertinoActionSheet( + title: Text(AppLocalizations.of(context).selectType), + actions: [ + CupertinoActionSheetAction( + onPressed: () async { + final s = await SharedPreferences.getInstance(); + await s.setInt("monthlygraph", 1); + _monthly = 1; + if (!ctx.mounted) return; + Navigator.of(ctx).pop(); + setState(() {}); + }, + child: Text( + AppLocalizations.of(context).barChart, + textAlign: TextAlign.center, ), ), - SizedBox( - width: MediaQuery.of(ctx).size.width, - child: InkWell( - child: Padding( - padding: const EdgeInsets.all(8), - child: Text( - AppLocalizations.of(context).lineChart, - textAlign: TextAlign.center, - ), - ), - onTap: () async { - final s = await SharedPreferences.getInstance(); - await s.setInt("monthlygraph", 2); - _monthly = 2; - if (!ctx.mounted) return; - Navigator.of(ctx).pop(); - setState(() {}); - }, + CupertinoActionSheetAction( + onPressed: () async { + final s = await SharedPreferences.getInstance(); + await s.setInt("monthlygraph", 2); + _monthly = 2; + if (!ctx.mounted) return; + Navigator.of(ctx).pop(); + setState(() {}); + }, + child: Text( + AppLocalizations.of(context).lineChart, + textAlign: TextAlign.center, ), ), ], ), - ), - ), - ), + ); + } else { + showAdaptiveDialog( + context: c, + builder: (ctx) => AlertDialog.adaptive( + title: Text(AppLocalizations.of(context).selectType), + content: SizedBox( + height: 80, + child: Column( + children: [ + SizedBox( + width: MediaQuery.of(ctx).size.width, + child: InkWell( + child: Padding( + padding: const EdgeInsets.all(8), + child: Text( + AppLocalizations.of(context).barChart, + textAlign: TextAlign.center, + ), + ), + onTap: () async { + final s = + await SharedPreferences.getInstance(); + await s.setInt("monthlygraph", 1); + _monthly = 1; + if (!ctx.mounted) return; + Navigator.of(ctx).pop(); + setState(() {}); + }, + ), + ), + SizedBox( + width: MediaQuery.of(context).size.width, + child: InkWell( + child: Padding( + padding: const EdgeInsets.all(8), + child: Text( + AppLocalizations.of(context).lineChart, + textAlign: TextAlign.center, + ), + ), + onTap: () async { + final s = + await SharedPreferences.getInstance(); + await s.setInt("monthlygraph", 2); + _monthly = 2; + if (!ctx.mounted) return; + Navigator.of(ctx).pop(); + setState(() {}); + }, + ), + ), + ], + ), + ), + ), + ); + } + }, ), ], ), From 163a2c9b54179ee1fbbbcc228a8de8d39eb395cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Mon, 12 Feb 2024 19:02:09 +0100 Subject: [PATCH 3/4] fix: ios build tweaks --- ios/Runner.xcodeproj/project.pbxproj | 2 +- ios/Runner/Info.plist | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index be7a38d..94809f0 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -672,7 +672,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { - ARCHS = x86_64; + ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index cb4ba33..a403f42 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -39,15 +39,11 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UTExportedTypeDeclarations From b909dd27dd11014a0baeb5fef9cf0af393629fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Mon, 12 Feb 2024 19:10:16 +0100 Subject: [PATCH 4/4] fix: ios inconsistency --- ios/Runner.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 94809f0..0c5ec46 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -465,7 +465,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { - ARCHS = x86_64; + ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; @@ -647,7 +647,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { - ARCHS = x86_64; + ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";