feat: add allergies, fix stuff after flutter update

This commit is contained in:
Matyáš Caras 2023-11-28 20:09:17 +01:00
parent ce9d09275b
commit c43e03def1
Signed by: hernik
GPG Key ID: 2A3175F98820C5C6
15 changed files with 54 additions and 25 deletions

View File

@ -1,3 +1,9 @@
# 1.10.0
- Aktualizovat závislosti
- Změnit minSdk na 21
- Přidat možnost zobrazit alergeny
- Změnit fungování oznámení s aktualizací knihovny
- Žádost o oprávnění k posílání oznámení by se mělo posílat už jen v případě, že uživatel bude chtít používat funkci oznámení
# 1.9.1
- Opravit chybu s propisováním HTML do názvu obědů
# 1.9.0

View File

@ -51,7 +51,7 @@ android {
defaultConfig {
applicationId "cz.hernikplays.opencanteen"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

View File

@ -1,6 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.hernikplays.opencanteen">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
<application
android:label="OpenCanteen"
android:name="${applicationName}"

View File

@ -78,5 +78,6 @@
"errorSaving": "Při ukládání offline nastala chyba, zkuste to znovu později.",
"todayTooltip": "Přejít na dnešní jídelníček",
"settingsExperience":"Zážitek",
"settingsFunctions":"Extra funkce"
"settingsFunctions":"Extra funkce",
"showAllergens":"Zobrazovat alergeny, jsou-li dostupné"
}

View File

@ -78,5 +78,6 @@
"errorSaving": "An error occured while trying to save menu offline, try again later.",
"todayTooltip": "Go to today's meal",
"settingsExperience":"App Experience",
"settingsFunctions":"Extra Functions"
"settingsFunctions":"Extra Functions",
"showAllergens":"Show allergens, if available"
}

View File

@ -84,7 +84,7 @@ void setupNotification(SharedPreferences prefs, tz.Location l) async {
"${jidlo.varianta} - ${jidlo.nazev}",
tz.TZDateTime.from(cas, l),
const NotificationDetails(android: androidSpec),
androidAllowWhileIdle: true,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
} on StateError catch (_) {
@ -108,6 +108,7 @@ void main() async {
settings.checkOrdered = prefs.getBool("tyden") ?? false;
settings.saveOffline = prefs.getBool("oznamit") ?? false;
settings.skipWeekend = prefs.getBool("skip") ?? false;
settings.allergens = prefs.getBool("allergens") ?? false;
// notif library setup
const AndroidInitializationSettings initializationSettingsAndroid =
@ -123,7 +124,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});
@override
Widget build(BuildContext context) {

View File

@ -8,7 +8,7 @@ import 'package:opencanteen/util.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class BurzaView extends StatefulWidget {
const BurzaView({Key? key, required this.canteen}) : super(key: key);
const BurzaView({super.key, required this.canteen});
final Canteen canteen;
@override
State<BurzaView> createState() => _BurzaViewState();

View File

@ -18,7 +18,7 @@ import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class MealView extends StatefulWidget {
const MealView({Key? key, required this.canteen}) : super(key: key);
const MealView({super.key, required this.canteen});
final Canteen canteen;
@override
State<MealView> createState() => _MealViewState();
@ -90,7 +90,7 @@ class _MealViewState extends State<MealView> {
try {
uzivatel = await widget.canteen.ziskejUzivatele();
} catch (e) {
if (!widget.canteen.prihlasen) {
if (!widget.canteen.prihlasen && mounted) {
Navigator.pushReplacement(
context, platformRouter((c) => const LoginPage()));
}
@ -122,7 +122,9 @@ class _MealViewState extends State<MealView> {
const SizedBox(width: 10),
Flexible(
child: Text(
j.nazev,
(settings.allergens && j.alergeny.isNotEmpty)
? "${j.nazev} (${j.alergeny.map<String>((e) => (e.kod != null) ? e.kod.toString() : e.nazev).join(', ')})"
: j.nazev,
),
),
Text((j.naBurze)

View File

@ -1,7 +1,6 @@
import 'package:canteenlib/canteenlib.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:opencanteen/okna/welcome.dart';
import 'package:opencanteen/pw/platformbutton.dart';
@ -9,14 +8,13 @@ import 'package:opencanteen/pw/platformfield.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import '../../loginmanager.dart';
import '../../main.dart';
import '../../util.dart';
import '../pw/platformswitch.dart';
import 'jidelnicek.dart';
import 'offline_jidelnicek.dart';
class LoginPage extends StatefulWidget {
const LoginPage({Key? key}) : super(key: key);
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
@ -33,12 +31,6 @@ class _LoginPageState extends State<LoginPage> {
void initState() {
super.initState();
LoginManager.getDetails().then((r) async {
// request android notification access
flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestPermission();
if (r != null) {
// Autologin
showDialog(

View File

@ -19,7 +19,7 @@ import '../../main.dart';
import '../../util.dart';
class AndroidNastaveni extends StatefulWidget {
const AndroidNastaveni({Key? key}) : super(key: key);
const AndroidNastaveni({super.key});
@override
State<AndroidNastaveni> createState() => _AndroidNastaveniState();
@ -31,6 +31,7 @@ class _AndroidNastaveniState extends State<AndroidNastaveni> {
bool _checkWeek = false;
bool _notifyMeal = false;
bool _remember = false;
bool _allergens = false;
TimeOfDay _notifTime = TimeOfDay.now();
final TextEditingController _countController =
TextEditingController(text: "1");
@ -81,6 +82,16 @@ class _AndroidNastaveniState extends State<AndroidNastaveni> {
sections: [
SettingsSection(
tiles: [
SettingsTile.switchTile(
initialValue: _allergens,
onToggle: (value) {
_allergens = value;
settings.allergens = value;
changeSetting("allergens", _allergens);
setState(() {});
},
title: Text(AppLocalizations.of(context)!.showAllergens),
),
SettingsTile.switchTile(
initialValue: _saveOffline,
onToggle: (value) {
@ -281,6 +292,19 @@ class _AndroidNastaveniState extends State<AndroidNastaveni> {
ticker: 'today meal');
var l =
tz.getLocation(await FlutterNativeTimezone.getLocalTimezone());
var notifGranted = await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestNotificationsPermission() ??
true; // request android notification access
var granted = await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestExactAlarmsPermission() ??
true; // request android exact alarm permission
if (!granted || !notifGranted) return;
if (!mounted) return;
await flutterLocalNotificationsPlugin.zonedSchedule(
// schedules a notification
@ -289,7 +313,7 @@ class _AndroidNastaveniState extends State<AndroidNastaveni> {
"${jidlo.varianta} - ${jidlo.nazev}",
tz.TZDateTime.from(den, l),
const NotificationDetails(android: androidSpec),
androidAllowWhileIdle: true,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
} on StateError catch (_) {

View File

@ -14,7 +14,7 @@ import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class OfflineMealView extends StatefulWidget {
const OfflineMealView({Key? key}) : super(key: key);
const OfflineMealView({super.key});
@override
State<OfflineMealView> createState() => _OfflineMealViewState();
}

View File

@ -7,7 +7,7 @@ import 'package:opencanteen/okna/jidelnicek.dart';
import 'package:opencanteen/util.dart';
class WelcomePage extends StatefulWidget {
const WelcomePage({Key? key, required this.canteen}) : super(key: key);
const WelcomePage({super.key, required this.canteen});
final Canteen canteen;

View File

@ -5,7 +5,7 @@ import 'package:opencanteen/pw/platformwidget.dart';
class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
final TextEditingController? controller;
final bool? enabled;
final bool enabled;
final bool obscureText;
final String? labelText;
final bool autocorrect;
@ -16,13 +16,13 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
const PlatformField({
super.key,
this.controller,
this.enabled,
this.labelText,
this.obscureText = false,
this.autocorrect = false,
this.keyboardType,
this.inputFormatters = const [],
this.onChanged,
this.enabled = true,
this.autofillHints,
});

View File

@ -128,4 +128,5 @@ class SettingsManager {
bool skipWeekend = false;
bool checkOrdered = false;
bool saveOffline = false;
bool allergens = false;
}

View File

@ -6,7 +6,7 @@ publish_to: 'none'
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
version: 1.9.1+31
version: 1.10.0+32
environment:
sdk: ">=2.18.2 <3.0.0"