fix: show actionsheet instead of inkwell on iOS

This commit is contained in:
Matyáš Caras 2024-02-12 18:43:57 +01:00
parent 75913280be
commit 06d25b9a0c
Signed by untrusted user who does not match committer: hernik
GPG key ID: 2A3175F98820C5C6
2 changed files with 186 additions and 94 deletions

View file

@ -19,6 +19,7 @@
- Welcome text on Setup view is now centered - Welcome text on Setup view is now centered
- Editing entries is now done by tapping the entry, instead of a dedicated button - Editing entries is now done by tapping the entry, instead of a dedicated button
- return iOS (Cupertino) widgets only on iOS/macOS - return iOS (Cupertino) widgets only on iOS/macOS
- Show action sheet in graph settings on iOS instead of InkWell
# 1.0.0-alpha+5 # 1.0.0-alpha+5
- Add tests - Add tests

View file

@ -1,3 +1,6 @@
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:settings_ui/settings_ui.dart'; import 'package:settings_ui/settings_ui.dart';
@ -47,59 +50,103 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
? AppLocalizations.of(context).barChart ? AppLocalizations.of(context).barChart
: AppLocalizations.of(context).lineChart, : AppLocalizations.of(context).lineChart,
), ),
onPressed: (c) => showAdaptiveDialog<void>( onPressed: (c) {
context: c, if (Platform.isIOS) {
builder: (ctx) => AlertDialog.adaptive( // iOS does not use Material widgets => no inkwell support
title: Text(AppLocalizations.of(context).selectType), showCupertinoModalPopup<void>(
content: SizedBox( context: context,
height: 80, builder: (ctx) => CupertinoActionSheet(
child: Column( title: Text(AppLocalizations.of(context).selectType),
children: [ actions: [
SizedBox( CupertinoActionSheetAction(
width: MediaQuery.of(ctx).size.width, onPressed: () async {
child: InkWell( final s = await SharedPreferences.getInstance();
child: Padding( await s.setInt("yearlygraph", 1);
padding: const EdgeInsets.all(8), _yearly = 1;
child: Text( if (!ctx.mounted) return;
AppLocalizations.of(context).barChart, Navigator.of(ctx).pop();
textAlign: TextAlign.center, setState(() {});
), },
), child: Text(
onTap: () async { AppLocalizations.of(context).barChart,
final s = await SharedPreferences.getInstance(); textAlign: TextAlign.center,
await s.setInt("yearlygraph", 1);
_yearly = 1;
if (!ctx.mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
), ),
), ),
SizedBox( CupertinoActionSheetAction(
width: MediaQuery.of(context).size.width, onPressed: () async {
child: InkWell( final s = await SharedPreferences.getInstance();
child: Padding( await s.setInt("yearlygraph", 2);
padding: const EdgeInsets.all(8), _yearly = 2;
child: Text( if (!ctx.mounted) return;
AppLocalizations.of(context).lineChart, Navigator.of(ctx).pop();
textAlign: TextAlign.center, setState(() {});
), },
), child: Text(
onTap: () async { AppLocalizations.of(context).lineChart,
final s = await SharedPreferences.getInstance(); textAlign: TextAlign.center,
await s.setInt("yearlygraph", 2);
_yearly = 2;
if (!ctx.mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
), ),
), ),
], ],
), ),
), );
), } else {
), showAdaptiveDialog<void>(
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( SettingsTile.navigation(
title: Text(AppLocalizations.of(context).monthly), title: Text(AppLocalizations.of(context).monthly),
@ -108,59 +155,103 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
? AppLocalizations.of(context).barChart ? AppLocalizations.of(context).barChart
: AppLocalizations.of(context).lineChart, : AppLocalizations.of(context).lineChart,
), ),
onPressed: (c) => showAdaptiveDialog<void>( onPressed: (c) {
context: c, if (Platform.isIOS) {
builder: (ctx) => AlertDialog.adaptive( // iOS does not use Material widgets => no inkwell support
title: Text(AppLocalizations.of(context).selectType), showCupertinoModalPopup<void>(
content: SizedBox( context: context,
height: 80, builder: (ctx) => CupertinoActionSheet(
child: Column( title: Text(AppLocalizations.of(context).selectType),
children: [ actions: [
SizedBox( CupertinoActionSheetAction(
width: MediaQuery.of(ctx).size.width, onPressed: () async {
child: InkWell( final s = await SharedPreferences.getInstance();
child: Padding( await s.setInt("monthlygraph", 1);
padding: const EdgeInsets.all(8), _monthly = 1;
child: Text( if (!ctx.mounted) return;
AppLocalizations.of(context).barChart, Navigator.of(ctx).pop();
textAlign: TextAlign.center, setState(() {});
), },
), child: Text(
onTap: () async { AppLocalizations.of(context).barChart,
final s = await SharedPreferences.getInstance(); textAlign: TextAlign.center,
await s.setInt("monthlygraph", 1);
_monthly = 1;
if (!ctx.mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
), ),
), ),
SizedBox( CupertinoActionSheetAction(
width: MediaQuery.of(ctx).size.width, onPressed: () async {
child: InkWell( final s = await SharedPreferences.getInstance();
child: Padding( await s.setInt("monthlygraph", 2);
padding: const EdgeInsets.all(8), _monthly = 2;
child: Text( if (!ctx.mounted) return;
AppLocalizations.of(context).lineChart, Navigator.of(ctx).pop();
textAlign: TextAlign.center, setState(() {});
), },
), child: Text(
onTap: () async { AppLocalizations.of(context).lineChart,
final s = await SharedPreferences.getInstance(); textAlign: TextAlign.center,
await s.setInt("monthlygraph", 2);
_monthly = 2;
if (!ctx.mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
), ),
), ),
], ],
), ),
), );
), } else {
), showAdaptiveDialog<void>(
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(() {});
},
),
),
],
),
),
),
);
}
},
), ),
], ],
), ),