2022-05-16 20:26:39 +02:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
|
2022-04-04 20:22:30 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-05-26 16:35:02 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2022-05-31 19:55:28 +02:00
|
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
2022-04-05 19:48:14 +02:00
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2022-06-08 17:12:44 +02:00
|
|
|
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
2022-04-04 20:22:30 +02:00
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
2022-05-03 16:41:45 +02:00
|
|
|
import 'package:opencanteen/lang/lang_cz.dart';
|
2022-04-04 20:22:30 +02:00
|
|
|
import 'package:opencanteen/loginmanager.dart';
|
|
|
|
import 'package:canteenlib/canteenlib.dart';
|
2022-05-16 20:26:39 +02:00
|
|
|
import 'package:opencanteen/okna/offline_jidelnicek.dart';
|
2022-05-18 19:38:11 +02:00
|
|
|
import 'package:opencanteen/okna/welcome.dart';
|
2022-05-16 20:26:39 +02:00
|
|
|
import 'package:opencanteen/util.dart';
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
2022-05-31 19:55:28 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-06-08 11:29:53 +02:00
|
|
|
import 'package:intl/intl.dart';
|
2022-06-08 17:12:44 +02:00
|
|
|
import 'package:timezone/data/latest_all.dart' as tz;
|
|
|
|
import 'package:timezone/timezone.dart' as tz;
|
2022-04-04 20:22:30 +02:00
|
|
|
|
2022-05-03 16:41:45 +02:00
|
|
|
import 'lang/lang.dart';
|
|
|
|
import 'lang/lang_en.dart';
|
2022-04-19 15:35:40 +02:00
|
|
|
import 'okna/jidelnicek.dart';
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright (C) 2022 Matyáš Caras a přispěvatelé
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2022-05-03 16:41:45 +02:00
|
|
|
*/
|
2022-04-19 15:35:40 +02:00
|
|
|
|
2022-05-31 19:55:28 +02:00
|
|
|
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
|
|
|
FlutterLocalNotificationsPlugin();
|
|
|
|
|
2022-06-08 17:12:44 +02:00
|
|
|
void oznamitPredem(SharedPreferences prefs, tz.Location l) async {
|
2022-06-08 11:29:53 +02:00
|
|
|
String title;
|
2022-06-08 17:12:44 +02:00
|
|
|
|
|
|
|
String locale = Intl.getCurrentLocale();
|
|
|
|
switch (locale) {
|
|
|
|
case "cs_CZ":
|
|
|
|
title = LanguageCz().lunchNotif;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
title = LanguageEn().lunchNotif;
|
2022-06-08 11:29:53 +02:00
|
|
|
}
|
2022-06-08 17:12:44 +02:00
|
|
|
|
2022-06-15 20:04:30 +02:00
|
|
|
/*if (prefs.getBool("offline") ?? false) {
|
2022-06-08 11:29:53 +02:00
|
|
|
// TODO možnost brát z offline dat
|
2022-06-15 20:04:30 +02:00
|
|
|
} else {*/
|
|
|
|
// bere online
|
|
|
|
var d = await LoginManager.getDetails(); // získat údaje
|
|
|
|
if (d != null) {
|
|
|
|
var c = Canteen(d["url"]!);
|
|
|
|
if (await c.login(d["user"]!, d["pass"]!)) {
|
|
|
|
var jidla = await c.jidelnicekDen();
|
|
|
|
try {
|
2022-09-02 19:30:55 +02:00
|
|
|
var jidlo = jidla.jidla.singleWhere(
|
|
|
|
(element) => element.objednano); // získá objednané jídlo
|
|
|
|
var kdy = DateTime.parse(prefs.getString(
|
|
|
|
"oznameni_cas")!); // uložíme čas, kdy se má odeslat oznámení
|
2022-10-04 17:45:31 +02:00
|
|
|
var cas = casNaDate(
|
|
|
|
TimeOfDay(hour: kdy.hour, minute: kdy.minute),
|
|
|
|
);
|
|
|
|
if (cas.isBefore(DateTime.now())) return;
|
2022-09-02 19:30:55 +02:00
|
|
|
// data o oznámení
|
2022-06-15 20:04:30 +02:00
|
|
|
const AndroidNotificationDetails androidSpec =
|
2022-06-15 20:12:33 +02:00
|
|
|
AndroidNotificationDetails('predobedem', 'Oznámení před obědem',
|
2022-06-15 20:04:30 +02:00
|
|
|
channelDescription: 'Oznámení o dnešním jídle',
|
|
|
|
importance: Importance.max,
|
|
|
|
priority: Priority.high,
|
|
|
|
ticker: 'today meal');
|
|
|
|
const IOSNotificationDetails iOSpec =
|
|
|
|
IOSNotificationDetails(presentAlert: true, presentBadge: true);
|
2022-09-02 19:30:55 +02:00
|
|
|
|
|
|
|
// naplánovat
|
2022-06-15 20:04:30 +02:00
|
|
|
await flutterLocalNotificationsPlugin.zonedSchedule(
|
|
|
|
0,
|
|
|
|
title,
|
2022-09-02 20:19:17 +02:00
|
|
|
"${jidlo.varianta} - ${jidlo.nazev}",
|
2022-10-04 17:45:31 +02:00
|
|
|
tz.TZDateTime.from(cas, l),
|
2022-06-15 20:04:30 +02:00
|
|
|
const NotificationDetails(android: androidSpec, iOS: iOSpec),
|
|
|
|
androidAllowWhileIdle: true,
|
|
|
|
uiLocalNotificationDateInterpretation:
|
|
|
|
UILocalNotificationDateInterpretation.absoluteTime);
|
|
|
|
} on StateError catch (_) {
|
|
|
|
// nenalezeno
|
2022-06-08 11:29:53 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-15 20:04:30 +02:00
|
|
|
// }
|
2022-06-08 11:29:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:12:44 +02:00
|
|
|
void main() async {
|
|
|
|
tz.initializeTimeZones();
|
|
|
|
var l = tz.getLocation(await FlutterNativeTimezone.getLocalTimezone());
|
|
|
|
tz.setLocalLocation(l);
|
2022-05-31 19:55:28 +02:00
|
|
|
|
2022-06-08 17:12:44 +02:00
|
|
|
var prefs = await SharedPreferences.getInstance();
|
2022-05-31 19:55:28 +02:00
|
|
|
if (prefs.getBool("oznamit") ?? false) {
|
2022-06-08 17:12:44 +02:00
|
|
|
oznamitPredem(prefs, l);
|
2022-05-31 19:55:28 +02:00
|
|
|
}
|
|
|
|
|
2022-09-02 19:30:55 +02:00
|
|
|
// nastavit oznámení
|
2022-05-31 19:55:28 +02:00
|
|
|
const AndroidInitializationSettings initializationSettingsAndroid =
|
|
|
|
AndroidInitializationSettings('notif_icon');
|
|
|
|
|
|
|
|
final IOSInitializationSettings initializationSettingsIOS =
|
2022-06-08 17:12:44 +02:00
|
|
|
IOSInitializationSettings(onDidReceiveLocalNotification: (
|
|
|
|
int id,
|
|
|
|
String? title,
|
|
|
|
String? body,
|
|
|
|
String? payload,
|
|
|
|
) async {
|
|
|
|
debugPrint(body);
|
|
|
|
});
|
2022-05-31 19:55:28 +02:00
|
|
|
|
|
|
|
final InitializationSettings initializationSettings = InitializationSettings(
|
|
|
|
android: initializationSettingsAndroid,
|
|
|
|
iOS: initializationSettingsIOS,
|
|
|
|
);
|
|
|
|
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
|
|
|
|
onSelectNotification: (String? payload) async {
|
|
|
|
if (payload != null) {
|
|
|
|
debugPrint('notification payload: $payload');
|
|
|
|
}
|
|
|
|
});
|
2022-09-02 19:30:55 +02:00
|
|
|
|
2022-10-20 17:44:04 +02:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
2022-09-02 19:30:55 +02:00
|
|
|
// spustit aplikaci
|
2022-04-04 20:22:30 +02:00
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2022-04-05 19:48:14 +02:00
|
|
|
debugShowCheckedModeBanner: false,
|
2022-05-03 16:41:45 +02:00
|
|
|
localizationsDelegates: const [
|
|
|
|
AppLocalizationsDelegate(),
|
|
|
|
...GlobalMaterialLocalizations.delegates
|
|
|
|
],
|
2022-05-15 16:59:55 +02:00
|
|
|
supportedLocales: const [Locale("cs", ""), Locale("en", "")],
|
|
|
|
title: "OpenCanteen",
|
2022-04-04 20:22:30 +02:00
|
|
|
theme: ThemeData(
|
|
|
|
primarySwatch: Colors.purple,
|
|
|
|
),
|
|
|
|
darkTheme: ThemeData(
|
|
|
|
brightness: Brightness.dark,
|
|
|
|
primarySwatch: Colors.purple,
|
|
|
|
),
|
|
|
|
home: const LoginPage(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LoginPage extends StatefulWidget {
|
|
|
|
const LoginPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<LoginPage> createState() => _LoginPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LoginPageState extends State<LoginPage> {
|
|
|
|
TextEditingController userControl = TextEditingController();
|
|
|
|
TextEditingController passControl = TextEditingController();
|
|
|
|
TextEditingController canteenControl = TextEditingController();
|
|
|
|
bool rememberMe = false;
|
2022-09-12 16:49:42 +02:00
|
|
|
bool _showUrl = false;
|
|
|
|
String dropdownUrl = instance.first["url"] ?? "";
|
2022-04-04 20:22:30 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
LoginManager.getDetails().then((r) async {
|
2022-05-31 19:55:28 +02:00
|
|
|
if (Platform.isIOS) {
|
|
|
|
// žádat o oprávnění na iOS
|
|
|
|
await flutterLocalNotificationsPlugin
|
|
|
|
.resolvePlatformSpecificImplementation<
|
|
|
|
IOSFlutterLocalNotificationsPlugin>()
|
|
|
|
?.requestPermissions(
|
|
|
|
alert: true,
|
|
|
|
badge: true,
|
|
|
|
sound: true,
|
|
|
|
);
|
2022-04-04 20:22:30 +02:00
|
|
|
}
|
|
|
|
if (r != null) {
|
2022-05-31 19:55:28 +02:00
|
|
|
// Automaticky přihlásit
|
2022-04-05 19:48:14 +02:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: false,
|
|
|
|
builder: (_) => Dialog(
|
|
|
|
child: SizedBox(
|
|
|
|
height: 100,
|
2022-05-15 16:59:55 +02:00
|
|
|
child: Row(children: [
|
|
|
|
const Padding(
|
2022-04-25 20:09:13 +02:00
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
2022-05-15 16:59:55 +02:00
|
|
|
Text(Languages.of(context)!.loggingIn)
|
2022-04-05 19:48:14 +02:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
));
|
2022-04-04 20:22:30 +02:00
|
|
|
var canteen = Canteen(r["url"]!);
|
2022-05-16 20:26:39 +02:00
|
|
|
try {
|
|
|
|
var l = await canteen.login(r["user"]!, r["pass"]!);
|
|
|
|
if (!l) {
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-05-16 20:26:39 +02:00
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(Languages.of(context)!.loginFailed),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2022-05-19 18:46:19 +02:00
|
|
|
const storage = FlutterSecureStorage();
|
|
|
|
var odsouhlasil = await storage.read(key: "oc_souhlas");
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-05-19 18:46:19 +02:00
|
|
|
if (odsouhlasil == null || odsouhlasil != "ano") {
|
2022-09-26 17:02:45 +02:00
|
|
|
Navigator.pushAndRemoveUntil(
|
2022-05-19 18:46:19 +02:00
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2022-09-26 17:02:45 +02:00
|
|
|
builder: (c) => WelcomeScreen(
|
|
|
|
canteen: canteen, n: flutterLocalNotificationsPlugin),
|
|
|
|
),
|
|
|
|
(route) => false);
|
2022-05-19 18:46:19 +02:00
|
|
|
} else {
|
2022-09-26 17:02:45 +02:00
|
|
|
Navigator.pushAndRemoveUntil(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2022-05-19 18:46:19 +02:00
|
|
|
builder: (context) => JidelnicekPage(
|
2022-09-26 17:02:45 +02:00
|
|
|
canteen: canteen, n: flutterLocalNotificationsPlugin),
|
|
|
|
),
|
|
|
|
(route) => false);
|
2022-05-19 18:46:19 +02:00
|
|
|
}
|
2022-05-26 16:35:02 +02:00
|
|
|
} on PlatformException {
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-05-26 16:35:02 +02:00
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(Languages.of(context)!.corrupted),
|
|
|
|
),
|
|
|
|
);
|
2022-05-16 20:26:39 +02:00
|
|
|
} catch (_) {
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-04-04 20:22:30 +02:00
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2022-05-15 16:59:55 +02:00
|
|
|
SnackBar(
|
2022-05-16 20:26:39 +02:00
|
|
|
content: Text(Languages.of(context)!.errorContacting),
|
2022-04-04 20:22:30 +02:00
|
|
|
),
|
|
|
|
);
|
2022-05-16 20:26:39 +02:00
|
|
|
goOffline();
|
2022-04-04 20:22:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2022-04-25 20:35:57 +02:00
|
|
|
appBar: AppBar(
|
2022-05-15 16:59:55 +02:00
|
|
|
title: Text(Languages.of(context)!.logIn),
|
2022-04-26 19:50:25 +02:00
|
|
|
automaticallyImplyLeading: false,
|
2022-04-25 20:35:57 +02:00
|
|
|
),
|
|
|
|
body: Center(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width - 50,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
2022-05-15 16:59:55 +02:00
|
|
|
Text(
|
2022-05-16 20:26:39 +02:00
|
|
|
Languages.of(context)!.appName,
|
2022-04-25 20:35:57 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-05-15 16:59:55 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold, fontSize: 40),
|
2022-04-25 20:35:57 +02:00
|
|
|
),
|
2022-05-15 16:59:55 +02:00
|
|
|
Text(
|
|
|
|
Languages.of(context)!.logIn,
|
2022-04-25 20:35:57 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
TextField(
|
|
|
|
controller: userControl,
|
|
|
|
autofillHints: const [AutofillHints.username],
|
2022-05-15 16:59:55 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: Languages.of(context)!.username),
|
2022-04-25 20:35:57 +02:00
|
|
|
),
|
|
|
|
TextField(
|
|
|
|
autofillHints: const [AutofillHints.password],
|
2022-05-15 16:59:55 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: Languages.of(context)!.password),
|
2022-04-25 20:35:57 +02:00
|
|
|
controller: passControl,
|
|
|
|
obscureText: true,
|
|
|
|
),
|
2022-09-12 16:49:42 +02:00
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
DropdownButton(
|
|
|
|
isExpanded: true,
|
|
|
|
value: dropdownUrl,
|
|
|
|
items: instance.map<DropdownMenuItem<String>>((e) {
|
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
value: e["url"],
|
|
|
|
child: Text(e["name"]!),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
onChanged: (String? value) {
|
|
|
|
setState(() {
|
|
|
|
if (value == "") {
|
|
|
|
_showUrl = true;
|
|
|
|
} else {
|
|
|
|
_showUrl = false;
|
|
|
|
}
|
|
|
|
dropdownUrl = value!;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
AnimatedOpacity(
|
|
|
|
opacity: _showUrl ? 1.0 : 0.0,
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
child: TextField(
|
|
|
|
autofillHints: const [AutofillHints.url],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: Languages.of(context)!.iCanteenUrl),
|
|
|
|
keyboardType: TextInputType.url,
|
|
|
|
controller: canteenControl,
|
|
|
|
),
|
2022-04-25 20:35:57 +02:00
|
|
|
),
|
|
|
|
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
|
|
|
Switch(
|
|
|
|
value: rememberMe,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
rememberMe = value;
|
|
|
|
});
|
|
|
|
}),
|
2022-05-15 16:59:55 +02:00
|
|
|
Text(Languages.of(context)!.rememberMe)
|
2022-04-25 20:35:57 +02:00
|
|
|
]),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
2022-09-12 16:49:42 +02:00
|
|
|
var canteenUrl = (dropdownUrl == "")
|
|
|
|
? canteenControl.text
|
|
|
|
: dropdownUrl;
|
|
|
|
if (!canteenUrl.startsWith("https://") &&
|
|
|
|
!canteenUrl.startsWith("http://")) {
|
|
|
|
canteenUrl = "https://$canteenUrl";
|
2022-04-26 18:20:42 +02:00
|
|
|
}
|
2022-09-12 16:49:42 +02:00
|
|
|
var canteen = Canteen(canteenUrl);
|
2022-05-16 20:26:39 +02:00
|
|
|
try {
|
|
|
|
var l = await canteen.login(
|
|
|
|
userControl.text, passControl.text);
|
|
|
|
if (!l) {
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-05-16 20:26:39 +02:00
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content:
|
|
|
|
Text(Languages.of(context)!.loginFailed),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (rememberMe) {
|
2022-09-12 16:49:42 +02:00
|
|
|
LoginManager.setDetails(
|
|
|
|
userControl.text, passControl.text, canteenUrl);
|
2022-05-16 20:26:39 +02:00
|
|
|
}
|
2022-05-18 19:38:11 +02:00
|
|
|
// souhlas
|
|
|
|
const storage = FlutterSecureStorage();
|
|
|
|
var odsouhlasil =
|
|
|
|
await storage.read(key: "oc_souhlas");
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-05-18 19:38:11 +02:00
|
|
|
if (odsouhlasil == null || odsouhlasil != "ano") {
|
2022-09-26 17:02:45 +02:00
|
|
|
Navigator.pushAndRemoveUntil(
|
2022-05-18 19:38:11 +02:00
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2022-06-08 17:12:44 +02:00
|
|
|
builder: (c) => WelcomeScreen(
|
|
|
|
canteen: canteen,
|
2022-09-26 17:02:45 +02:00
|
|
|
n: flutterLocalNotificationsPlugin)),
|
|
|
|
(route) => false);
|
2022-05-18 19:38:11 +02:00
|
|
|
} else {
|
2022-09-26 17:02:45 +02:00
|
|
|
Navigator.pushAndRemoveUntil(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => JidelnicekPage(
|
|
|
|
canteen: canteen,
|
|
|
|
n: flutterLocalNotificationsPlugin)),
|
|
|
|
(route) => false);
|
2022-05-18 19:38:11 +02:00
|
|
|
}
|
2022-05-26 16:35:02 +02:00
|
|
|
} on PlatformException {
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-05-26 16:35:02 +02:00
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(Languages.of(context)!.corrupted),
|
|
|
|
),
|
|
|
|
);
|
2022-05-16 20:26:39 +02:00
|
|
|
} on Exception catch (_) {
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-04-25 20:35:57 +02:00
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2022-05-15 16:59:55 +02:00
|
|
|
SnackBar(
|
2022-05-16 20:26:39 +02:00
|
|
|
content:
|
|
|
|
Text(Languages.of(context)!.errorContacting),
|
2022-04-25 20:35:57 +02:00
|
|
|
),
|
|
|
|
);
|
2022-05-16 20:26:39 +02:00
|
|
|
goOffline();
|
2022-04-25 20:35:57 +02:00
|
|
|
}
|
|
|
|
},
|
2022-05-15 16:59:55 +02:00
|
|
|
child: Text(Languages.of(context)!.logIn)),
|
2022-04-25 20:35:57 +02:00
|
|
|
],
|
2022-04-04 20:22:30 +02:00
|
|
|
),
|
2022-04-25 20:35:57 +02:00
|
|
|
),
|
2022-04-04 20:22:30 +02:00
|
|
|
),
|
2022-04-25 20:35:57 +02:00
|
|
|
));
|
2022-04-04 20:22:30 +02:00
|
|
|
}
|
2022-05-16 20:26:39 +02:00
|
|
|
|
2022-09-02 19:30:55 +02:00
|
|
|
/// Získá offline soubor a zobrazí údaje
|
2022-05-16 20:26:39 +02:00
|
|
|
void goOffline() async {
|
|
|
|
Directory appDocDir = await getApplicationDocumentsDirectory();
|
|
|
|
var den = DateTime.now();
|
2022-09-06 20:02:17 +02:00
|
|
|
var soubor = File(
|
|
|
|
"${appDocDir.path}/jidelnicek_${den.year}-${den.month}-${den.day}.json");
|
2022-05-16 20:26:39 +02:00
|
|
|
if (soubor.existsSync()) {
|
|
|
|
// načteme offline jídelníček
|
|
|
|
var input = await soubor.readAsString();
|
|
|
|
var r = jsonDecode(input);
|
|
|
|
List<OfflineJidlo> jidla = [];
|
|
|
|
for (var j in r) {
|
|
|
|
jidla.add(OfflineJidlo(
|
|
|
|
nazev: j["nazev"],
|
|
|
|
varianta: j["varianta"],
|
|
|
|
objednano: j["objednano"],
|
|
|
|
cena: j["cena"],
|
|
|
|
naBurze: j["naBurze"],
|
|
|
|
den: DateTime.parse(j["den"])));
|
|
|
|
}
|
2022-09-06 20:02:17 +02:00
|
|
|
if (!mounted) return;
|
2022-09-26 17:02:45 +02:00
|
|
|
Navigator.pushAndRemoveUntil(
|
2022-05-16 20:26:39 +02:00
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2022-09-26 17:02:45 +02:00
|
|
|
builder: ((context) => OfflineJidelnicek(jidla: jidla))),
|
|
|
|
(route) => false);
|
2022-05-16 20:26:39 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-04 20:22:30 +02:00
|
|
|
}
|
2022-05-03 16:41:45 +02:00
|
|
|
|
|
|
|
class AppLocalizationsDelegate extends LocalizationsDelegate<Languages> {
|
|
|
|
const AppLocalizationsDelegate();
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool isSupported(Locale locale) => ['cs', 'en'].contains(locale.languageCode);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<Languages> load(Locale locale) => _load(locale);
|
|
|
|
|
|
|
|
static Future<Languages> _load(Locale locale) async {
|
|
|
|
switch (locale.languageCode) {
|
|
|
|
case 'cs':
|
|
|
|
return LanguageCz();
|
|
|
|
default:
|
|
|
|
return LanguageEn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool shouldReload(LocalizationsDelegate<Languages> old) => false;
|
|
|
|
}
|