2022-04-26 18:20:42 +02:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
|
2022-04-04 20:22:30 +02:00
|
|
|
import 'package:canteenlib/canteenlib.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-04-19 16:06:03 +02:00
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
2023-09-04 20:45:45 +02:00
|
|
|
import 'package:opencanteen/main.dart';
|
2022-12-14 20:02:32 +01:00
|
|
|
import 'package:opencanteen/okna/login.dart';
|
|
|
|
import 'package:opencanteen/okna/nastaveni.dart';
|
2023-01-28 14:30:54 +01:00
|
|
|
import 'package:opencanteen/pw/platformbutton.dart';
|
|
|
|
import 'package:opencanteen/pw/platformdialog.dart';
|
2022-04-04 20:22:30 +02:00
|
|
|
import 'package:opencanteen/util.dart';
|
2022-09-26 16:46:22 +02:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2022-04-26 18:20:42 +02:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2022-05-02 12:07:47 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-04-19 16:06:03 +02:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2022-04-04 20:22:30 +02:00
|
|
|
|
2023-01-28 15:41:17 +01:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2022-04-04 20:22:30 +02:00
|
|
|
|
2023-01-28 14:30:54 +01:00
|
|
|
class MealView extends StatefulWidget {
|
2023-11-28 20:10:34 +01:00
|
|
|
const MealView({super.key, required this.canteen});
|
2022-04-04 20:22:30 +02:00
|
|
|
final Canteen canteen;
|
|
|
|
@override
|
2023-01-28 14:30:54 +01:00
|
|
|
State<MealView> createState() => _MealViewState();
|
2022-04-04 20:22:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-28 14:30:54 +01:00
|
|
|
class _MealViewState extends State<MealView> {
|
|
|
|
List<Widget> content = [const CircularProgressIndicator()];
|
|
|
|
DateTime day = DateTime.now();
|
|
|
|
String dayOWeek = "";
|
|
|
|
double balance = 0.0;
|
2022-05-26 16:35:02 +02:00
|
|
|
|
2023-01-28 14:30:54 +01:00
|
|
|
void checkWeek(BuildContext context) async {
|
2023-09-04 20:45:45 +02:00
|
|
|
if (settings.checkOrdered) {
|
2023-01-28 14:30:54 +01:00
|
|
|
// Check if user has ordered a meal in the next week
|
|
|
|
var pristi = day.add(const Duration(days: 6));
|
2022-09-12 17:13:12 +02:00
|
|
|
for (var i = 0; i < 5; i++) {
|
|
|
|
var jidelnicek = await widget.canteen
|
|
|
|
.jidelnicekDen(den: pristi.add(Duration(days: i + 1)));
|
|
|
|
if (jidelnicek.jidla.isNotEmpty &&
|
|
|
|
!jidelnicek.jidla.any((element) => element.objednano == true)) {
|
|
|
|
if (!mounted) break;
|
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
2023-01-28 15:41:17 +01:00
|
|
|
content: Text(AppLocalizations.of(context)!.noOrder),
|
2022-09-12 17:13:12 +02:00
|
|
|
duration: const Duration(seconds: 5),
|
|
|
|
action: SnackBarAction(
|
|
|
|
onPressed: () => setState(
|
|
|
|
() {
|
2023-01-28 14:30:54 +01:00
|
|
|
day = pristi.add(Duration(days: i + 1));
|
|
|
|
loadMeals();
|
2022-09-12 17:13:12 +02:00
|
|
|
},
|
|
|
|
),
|
2023-01-28 15:41:17 +01:00
|
|
|
label: AppLocalizations.of(context)!.jump,
|
2022-09-12 17:13:12 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2022-05-26 16:35:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-28 14:30:54 +01:00
|
|
|
Future<void> loadMeals() async {
|
|
|
|
content = [const CircularProgressIndicator()];
|
|
|
|
switch (day.weekday) {
|
2022-04-04 20:22:30 +02:00
|
|
|
case 2:
|
2023-01-28 15:41:17 +01:00
|
|
|
dayOWeek = AppLocalizations.of(context)!.tuesday;
|
2022-04-04 20:22:30 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2023-01-28 15:41:17 +01:00
|
|
|
dayOWeek = AppLocalizations.of(context)!.wednesday;
|
2022-04-04 20:22:30 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2023-01-28 15:41:17 +01:00
|
|
|
dayOWeek = AppLocalizations.of(context)!.thursday;
|
2022-04-04 20:22:30 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2023-01-28 15:41:17 +01:00
|
|
|
dayOWeek = AppLocalizations.of(context)!.friday;
|
2022-04-04 20:22:30 +02:00
|
|
|
break;
|
|
|
|
case 6:
|
2023-01-28 15:41:17 +01:00
|
|
|
dayOWeek = AppLocalizations.of(context)!.saturday;
|
2022-04-04 20:22:30 +02:00
|
|
|
break;
|
|
|
|
case 7:
|
2023-01-28 15:41:17 +01:00
|
|
|
dayOWeek = AppLocalizations.of(context)!.sunday;
|
2022-04-04 20:22:30 +02:00
|
|
|
break;
|
|
|
|
default:
|
2023-01-28 15:41:17 +01:00
|
|
|
dayOWeek = AppLocalizations.of(context)!.monday;
|
2022-04-04 20:22:30 +02:00
|
|
|
}
|
2023-09-04 20:45:45 +02:00
|
|
|
Uzivatel uzivatel;
|
|
|
|
try {
|
|
|
|
uzivatel = await widget.canteen.ziskejUzivatele();
|
|
|
|
} catch (e) {
|
2023-11-28 20:10:34 +01:00
|
|
|
if (!widget.canteen.prihlasen && mounted) {
|
2023-09-04 20:45:45 +02:00
|
|
|
Navigator.pushReplacement(
|
|
|
|
context, platformRouter((c) => const LoginPage()));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2023-01-28 14:30:54 +01:00
|
|
|
balance = uzivatel.kredit;
|
|
|
|
var jd = await widget.canteen.jidelnicekDen(den: day).catchError((_) {
|
2023-01-28 15:41:17 +01:00
|
|
|
showInfo(context, AppLocalizations.of(context)!.errorContacting);
|
2023-01-28 14:30:54 +01:00
|
|
|
return Jidelnicek(DateTime.now(), []);
|
|
|
|
});
|
|
|
|
setState(
|
|
|
|
() {
|
|
|
|
content = [];
|
|
|
|
if (jd.jidla.isEmpty) {
|
|
|
|
content.add(Text(
|
2023-01-28 15:41:17 +01:00
|
|
|
AppLocalizations.of(context)!.noFood,
|
2023-01-28 14:30:54 +01:00
|
|
|
style: const TextStyle(fontSize: 15),
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
for (var j in jd.jidla) {
|
|
|
|
content.add(
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 15),
|
|
|
|
child: InkWell(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(j.varianta),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Flexible(
|
|
|
|
child: Text(
|
2023-11-28 20:10:34 +01:00
|
|
|
(settings.allergens && j.alergeny.isNotEmpty)
|
|
|
|
? "${j.nazev} (${j.alergeny.map<String>((e) => (e.kod != null) ? e.kod.toString() : e.nazev).join(', ')})"
|
|
|
|
: j.nazev,
|
2022-04-05 19:48:14 +02:00
|
|
|
),
|
2023-01-28 14:30:54 +01:00
|
|
|
),
|
|
|
|
Text((j.naBurze)
|
2023-01-28 15:41:17 +01:00
|
|
|
? AppLocalizations.of(context)!.inExchange
|
2023-01-28 14:30:54 +01:00
|
|
|
: "${j.cena} Kč"),
|
|
|
|
Checkbox(
|
|
|
|
value: j.objednano,
|
2023-09-12 22:38:56 +02:00
|
|
|
side: BorderSide(
|
|
|
|
width: 2,
|
|
|
|
color: (j.lzeObjednat)
|
|
|
|
? (Colors.purple)
|
|
|
|
: (Colors.grey)),
|
|
|
|
fillColor: (j.lzeObjednat && j.objednano)
|
2023-01-28 14:30:54 +01:00
|
|
|
? MaterialStateProperty.all(Colors.purple)
|
2023-09-12 22:38:56 +02:00
|
|
|
: (j.objednano)
|
|
|
|
? MaterialStateProperty.all(Colors.grey)
|
|
|
|
: MaterialStateProperty.all(Colors.transparent),
|
2023-01-28 14:30:54 +01:00
|
|
|
onChanged: (v) async {
|
|
|
|
if (!j.lzeObjednat) {
|
2022-12-14 19:44:32 +01:00
|
|
|
showDialog(
|
2022-05-19 18:44:56 +02:00
|
|
|
context: context,
|
2023-01-28 14:30:54 +01:00
|
|
|
builder: (context) {
|
|
|
|
return PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title: AppLocalizations.of(context)!
|
|
|
|
.errorOrdering,
|
|
|
|
content:
|
|
|
|
AppLocalizations.of(context)!.cannotOrder,
|
2023-01-28 14:30:54 +01:00
|
|
|
actions: [
|
|
|
|
PlatformButton(
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.ok,
|
2022-04-05 19:48:14 +02:00
|
|
|
onPressed: () {
|
2023-01-28 14:30:54 +01:00
|
|
|
Navigator.of(context).pop();
|
2022-04-05 19:48:14 +02:00
|
|
|
},
|
2023-01-28 14:30:54 +01:00
|
|
|
)
|
2022-04-05 19:48:14 +02:00
|
|
|
],
|
2023-01-28 14:30:54 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
2022-04-05 19:48:14 +02:00
|
|
|
showDialog(
|
2022-12-14 19:44:32 +01:00
|
|
|
context: context,
|
2023-01-28 14:30:54 +01:00
|
|
|
barrierDismissible: false,
|
|
|
|
builder: (_) => Dialog(
|
|
|
|
child: SizedBox(
|
|
|
|
height: 100,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
2023-01-28 15:41:17 +01:00
|
|
|
Text(AppLocalizations.of(context)!
|
|
|
|
.ordering)
|
2023-01-28 14:30:54 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-12-14 19:44:32 +01:00
|
|
|
),
|
|
|
|
);
|
2023-01-28 14:30:54 +01:00
|
|
|
widget.canteen.objednat(j).then((_) {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
loadMeals();
|
|
|
|
}).catchError(
|
|
|
|
(o) {
|
|
|
|
Navigator.of(context, rootNavigator: true)
|
|
|
|
.pop();
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (bc) => PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title: AppLocalizations.of(context)!
|
|
|
|
.errorOrdering,
|
2023-01-28 14:30:54 +01:00
|
|
|
content: o.toString(),
|
|
|
|
actions: [
|
|
|
|
PlatformButton(
|
2023-01-28 15:41:17 +01:00
|
|
|
text:
|
|
|
|
AppLocalizations.of(context)!.close,
|
2023-01-28 14:30:54 +01:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(bc);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
2022-04-05 19:48:14 +02:00
|
|
|
),
|
2023-01-28 14:30:54 +01:00
|
|
|
onTap: () async {
|
|
|
|
if (!j.lzeObjednat) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title: AppLocalizations.of(context)!.errorOrdering,
|
|
|
|
content: AppLocalizations.of(context)!.cannotOrder,
|
2023-01-28 14:30:54 +01:00
|
|
|
actions: [
|
|
|
|
PlatformButton(
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.ok,
|
2023-01-28 14:30:54 +01:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: false,
|
|
|
|
builder: (_) => Dialog(
|
|
|
|
child: SizedBox(
|
|
|
|
height: 100,
|
|
|
|
child: Row(children: [
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
2023-01-28 15:41:17 +01:00
|
|
|
Text(AppLocalizations.of(context)!.ordering)
|
2023-01-28 14:30:54 +01:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
widget.canteen.objednat(j).then((_) {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
loadMeals();
|
|
|
|
}).catchError(
|
|
|
|
(o) {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (bc) => PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title:
|
|
|
|
AppLocalizations.of(context)!.errorOrdering,
|
2023-01-28 14:30:54 +01:00
|
|
|
content: o.toString(),
|
|
|
|
actions: [
|
|
|
|
PlatformButton(
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.close,
|
2023-01-28 14:30:54 +01:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(bc);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onLongPress: () async {
|
|
|
|
if (!j.objednano || j.burzaUrl == null) return;
|
|
|
|
if (!j.naBurze) {
|
|
|
|
// if not in exchange, we ask
|
|
|
|
var d = await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (bc) => PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title: AppLocalizations.of(context)!.verifyExchange,
|
2023-01-28 14:30:54 +01:00
|
|
|
actions: [
|
|
|
|
PlatformButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(bc, true);
|
|
|
|
},
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.yes,
|
2023-01-28 14:30:54 +01:00
|
|
|
),
|
|
|
|
PlatformButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(bc, false);
|
|
|
|
},
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.no,
|
2023-01-28 14:30:54 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
if (d) {
|
|
|
|
widget.canteen
|
|
|
|
.doBurzy(j)
|
|
|
|
.then((_) => loadMeals())
|
|
|
|
.catchError((o) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (bc) => PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title:
|
|
|
|
AppLocalizations.of(context)!.exchangeError,
|
2023-01-28 14:30:54 +01:00
|
|
|
content: o.toString(),
|
|
|
|
actions: [
|
|
|
|
PlatformButton(
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.close,
|
2023-01-28 14:30:54 +01:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(bc);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// else no
|
|
|
|
widget.canteen.doBurzy(j).then((_) => loadMeals());
|
|
|
|
}
|
|
|
|
},
|
2022-04-05 19:48:14 +02:00
|
|
|
),
|
2023-01-28 14:30:54 +01:00
|
|
|
),
|
|
|
|
);
|
2022-04-05 19:48:14 +02:00
|
|
|
}
|
2023-01-28 14:30:54 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
return;
|
2022-04-05 19:48:14 +02:00
|
|
|
}
|
|
|
|
|
2023-01-28 14:30:54 +01:00
|
|
|
Future<void> click(String value, BuildContext context) async {
|
2023-01-28 15:41:17 +01:00
|
|
|
if (value == AppLocalizations.of(context)!.signOut) {
|
2022-09-02 19:51:39 +02:00
|
|
|
await showDialog<bool>(
|
|
|
|
context: context,
|
2023-01-28 14:30:54 +01:00
|
|
|
builder: (c) => PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title: AppLocalizations.of(context)!.warning,
|
|
|
|
content: AppLocalizations.of(context)!.signOutWarn,
|
2022-09-02 19:51:39 +02:00
|
|
|
actions: [
|
2023-01-28 14:30:54 +01:00
|
|
|
PlatformButton(
|
2022-09-02 19:51:39 +02:00
|
|
|
onPressed: () {
|
|
|
|
const storage = FlutterSecureStorage();
|
|
|
|
storage.deleteAll();
|
2022-09-26 17:02:45 +02:00
|
|
|
Navigator.pushAndRemoveUntil(
|
|
|
|
context,
|
2023-01-28 14:30:54 +01:00
|
|
|
platformRouter((c) => const LoginPage()),
|
2022-09-26 17:02:45 +02:00
|
|
|
(route) => false);
|
2022-09-02 19:51:39 +02:00
|
|
|
},
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.yes),
|
2023-01-28 14:30:54 +01:00
|
|
|
PlatformButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.no,
|
2023-01-28 14:30:54 +01:00
|
|
|
)
|
2022-09-02 19:51:39 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2023-01-28 15:41:17 +01:00
|
|
|
} else if (value == AppLocalizations.of(context)!.review) {
|
2023-01-28 14:30:54 +01:00
|
|
|
launchUrl(
|
|
|
|
Uri.parse((Platform.isAndroid)
|
|
|
|
? "market://details?id=cz.hernikplays.opencanteen"
|
|
|
|
: "https://apps.apple.com/cz/app/opencanteen/id1621124445"),
|
2022-12-12 17:52:33 +01:00
|
|
|
mode: LaunchMode.externalApplication);
|
2023-01-28 15:41:17 +01:00
|
|
|
} else if (value == AppLocalizations.of(context)!.reportBugs) {
|
2022-10-04 17:45:31 +02:00
|
|
|
launchUrl(Uri.parse("https://forms.gle/jKN7QeFJwpaApSbC8"),
|
|
|
|
mode: LaunchMode.externalApplication);
|
2023-01-28 15:41:17 +01:00
|
|
|
} else if (value == AppLocalizations.of(context)!.about) {
|
2022-09-26 16:46:22 +02:00
|
|
|
var packageInfo = await PackageInfo.fromPlatform();
|
|
|
|
if (!mounted) return;
|
|
|
|
showAboutDialog(
|
|
|
|
context: context,
|
|
|
|
applicationName: "OpenCanteen",
|
|
|
|
applicationLegalese:
|
2023-01-28 15:41:17 +01:00
|
|
|
"${AppLocalizations.of(context)!.copyright}\n${AppLocalizations.of(context)!.license}",
|
2022-09-26 16:46:22 +02:00
|
|
|
applicationVersion: packageInfo.version,
|
|
|
|
children: [
|
2023-01-28 14:30:54 +01:00
|
|
|
PlatformButton(
|
|
|
|
onPressed: (() => launchUrl(
|
|
|
|
Uri.parse("https://git.mnau.xyz/hernik/opencanteen"),
|
|
|
|
mode: LaunchMode.externalApplication)),
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.source,
|
2023-01-28 14:30:54 +01:00
|
|
|
)
|
2022-09-26 16:46:22 +02:00
|
|
|
]);
|
2023-01-28 15:41:17 +01:00
|
|
|
} else if (value == AppLocalizations.of(context)!.settings) {
|
2023-01-28 14:30:54 +01:00
|
|
|
Navigator.push(context, platformRouter((c) => const AndroidNastaveni()));
|
2022-04-19 16:06:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-28 14:30:54 +01:00
|
|
|
void loadSettings() async {
|
2022-09-12 17:13:12 +02:00
|
|
|
if (!mounted) return;
|
2023-01-28 14:30:54 +01:00
|
|
|
checkWeek(context);
|
2022-05-16 20:26:39 +02:00
|
|
|
}
|
|
|
|
|
2023-01-28 14:30:54 +01:00
|
|
|
void saveOffline() async {
|
2023-09-04 20:45:45 +02:00
|
|
|
if (!settings.saveOffline) return;
|
|
|
|
// clear offline storage
|
|
|
|
Directory appDocDir = await getApplicationDocumentsDirectory();
|
|
|
|
for (var f in appDocDir.listSync()) {
|
|
|
|
if (f.path.contains("jidelnicek")) {
|
|
|
|
f.deleteSync();
|
|
|
|
}
|
|
|
|
}
|
2022-05-02 12:07:47 +02:00
|
|
|
var prefs = await SharedPreferences.getInstance();
|
2023-09-04 20:45:45 +02:00
|
|
|
// save X meal lists
|
|
|
|
var pocet = prefs.getInt("offline_pocet") ?? 1;
|
|
|
|
if (pocet > 7) pocet = 7;
|
|
|
|
for (var i = 0; i < pocet; i++) {
|
|
|
|
var d = day.add(Duration(days: i));
|
|
|
|
Jidelnicek? j;
|
|
|
|
try {
|
|
|
|
j = await widget.canteen.jidelnicekDen(den: d);
|
|
|
|
} catch (e) {
|
|
|
|
if (!widget.canteen.prihlasen) {
|
|
|
|
if (!mounted) return;
|
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
|
|
content: Text(AppLocalizations.of(context)!.errorSaving),
|
|
|
|
duration: const Duration(seconds: 5),
|
|
|
|
));
|
|
|
|
break;
|
2022-04-26 18:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
2023-09-04 20:45:45 +02:00
|
|
|
var soubor = File(
|
|
|
|
"${appDocDir.path}/jidelnicek_${d.year}-${d.month}-${d.day}.json");
|
|
|
|
soubor.createSync();
|
|
|
|
var jidla = [];
|
|
|
|
for (var jidlo in j!.jidla) {
|
|
|
|
jidla.add({
|
|
|
|
"nazev": jidlo.nazev,
|
|
|
|
"varianta": jidlo.varianta,
|
|
|
|
"objednano": jidlo.objednano,
|
|
|
|
"cena": jidlo.cena,
|
|
|
|
"naBurze": jidlo.naBurze,
|
|
|
|
"den": d.toString()
|
|
|
|
});
|
2022-09-06 20:02:37 +02:00
|
|
|
}
|
2023-09-04 20:45:45 +02:00
|
|
|
await soubor.writeAsString(json.encode(jidla));
|
2022-04-26 18:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-05 19:48:14 +02:00
|
|
|
@override
|
2022-05-15 16:59:55 +02:00
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
2023-01-28 14:30:54 +01:00
|
|
|
loadSettings();
|
|
|
|
saveOffline();
|
|
|
|
loadMeals();
|
2022-04-04 20:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2022-12-12 16:48:19 +01:00
|
|
|
drawer: drawerGenerator(context, widget.canteen, 1),
|
2022-04-04 20:22:30 +02:00
|
|
|
appBar: AppBar(
|
2023-01-28 15:41:17 +01:00
|
|
|
title: Text(AppLocalizations.of(context)!.menu),
|
2022-04-19 16:06:03 +02:00
|
|
|
actions: [
|
|
|
|
PopupMenuButton(
|
2023-01-28 14:30:54 +01:00
|
|
|
onSelected: ((String value) => click(value, context)),
|
2022-04-19 16:06:03 +02:00
|
|
|
itemBuilder: (BuildContext context) {
|
2022-05-15 16:59:55 +02:00
|
|
|
return {
|
2023-01-28 15:41:17 +01:00
|
|
|
AppLocalizations.of(context)!.reportBugs,
|
|
|
|
AppLocalizations.of(context)!.review,
|
|
|
|
AppLocalizations.of(context)!.settings,
|
|
|
|
AppLocalizations.of(context)!.about,
|
|
|
|
AppLocalizations.of(context)!.signOut
|
2022-05-15 16:59:55 +02:00
|
|
|
}.map((String choice) {
|
2022-04-19 16:06:03 +02:00
|
|
|
return PopupMenuItem<String>(
|
|
|
|
value: choice,
|
|
|
|
child: Text(choice),
|
|
|
|
);
|
|
|
|
}).toList();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2022-04-04 20:22:30 +02:00
|
|
|
),
|
2022-04-09 17:54:08 +02:00
|
|
|
body: RefreshIndicator(
|
2023-01-28 14:30:54 +01:00
|
|
|
onRefresh: loadMeals,
|
2022-04-09 17:54:08 +02:00
|
|
|
child: Center(
|
|
|
|
child: SizedBox(
|
2023-09-12 22:38:56 +02:00
|
|
|
width: MediaQuery.of(context).size.width,
|
2022-04-09 17:54:08 +02:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 10),
|
2023-01-28 15:41:17 +01:00
|
|
|
Text("${AppLocalizations.of(context)!.balance}$balance Kč"),
|
2023-01-28 14:30:54 +01:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
day = day.subtract(const Duration(days: 1));
|
2023-09-04 20:45:45 +02:00
|
|
|
if (day.weekday == 7 && settings.skipWeekend) {
|
2023-01-28 14:30:54 +01:00
|
|
|
day = day.subtract(const Duration(days: 2));
|
|
|
|
}
|
|
|
|
loadMeals();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.arrow_left)),
|
|
|
|
PlatformButton(
|
2022-04-09 17:54:08 +02:00
|
|
|
onPressed: () async {
|
|
|
|
var datePicked = await showDatePicker(
|
|
|
|
context: context,
|
2023-01-28 14:30:54 +01:00
|
|
|
initialDate: day,
|
|
|
|
currentDate: day,
|
2022-04-09 17:54:08 +02:00
|
|
|
firstDate: DateTime(2019, 1, 1),
|
2023-01-28 14:30:54 +01:00
|
|
|
lastDate: DateTime(day.year + 1, 12, 31),
|
2022-05-19 19:07:16 +02:00
|
|
|
locale: Localizations.localeOf(context));
|
2022-04-09 17:54:08 +02:00
|
|
|
if (datePicked == null) return;
|
|
|
|
setState(() {
|
2023-01-28 14:30:54 +01:00
|
|
|
day = datePicked;
|
|
|
|
loadMeals();
|
2022-04-09 17:54:08 +02:00
|
|
|
});
|
|
|
|
},
|
2023-01-28 14:30:54 +01:00
|
|
|
text: "${day.day}. ${day.month}. ${day.year} - $dayOWeek",
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
day = day.add(const Duration(days: 1));
|
2023-09-04 20:45:45 +02:00
|
|
|
if (day.weekday == 6 && settings.skipWeekend) {
|
2023-01-28 14:30:54 +01:00
|
|
|
day = day.add(const Duration(days: 2));
|
|
|
|
}
|
|
|
|
loadMeals();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.arrow_right),
|
|
|
|
),
|
|
|
|
Tooltip(
|
2023-01-28 15:41:17 +01:00
|
|
|
message: AppLocalizations.of(context)!.todayTooltip,
|
2023-01-28 14:30:54 +01:00
|
|
|
child: IconButton(
|
|
|
|
onPressed: () => setState(
|
|
|
|
() {
|
|
|
|
day = DateTime.now();
|
|
|
|
loadMeals();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
icon: const Icon(Icons.today),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-04-09 17:54:08 +02:00
|
|
|
SingleChildScrollView(
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
child: GestureDetector(
|
2022-04-19 15:35:40 +02:00
|
|
|
child: Container(
|
2023-09-12 22:38:56 +02:00
|
|
|
padding: const EdgeInsets.only(left: 20, right: 20),
|
2022-04-19 15:35:40 +02:00
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.onPrimary
|
|
|
|
.withOpacity(0),
|
2022-04-25 20:35:57 +02:00
|
|
|
height: MediaQuery.of(context).size.height / 1.3,
|
2023-01-28 14:30:54 +01:00
|
|
|
child: Column(children: content),
|
2022-04-19 15:35:40 +02:00
|
|
|
),
|
2022-04-09 17:54:08 +02:00
|
|
|
onHorizontalDragEnd: (details) {
|
|
|
|
if (details.primaryVelocity?.compareTo(0) == -1) {
|
|
|
|
setState(() {
|
2023-01-28 14:30:54 +01:00
|
|
|
day = day.add(const Duration(days: 1));
|
2023-09-04 20:45:45 +02:00
|
|
|
if (day.weekday == 6 && settings.skipWeekend) {
|
2023-01-28 14:30:54 +01:00
|
|
|
day = day.add(const Duration(days: 2));
|
2022-05-16 20:26:39 +02:00
|
|
|
}
|
2023-01-28 14:30:54 +01:00
|
|
|
loadMeals();
|
2022-04-09 17:54:08 +02:00
|
|
|
});
|
|
|
|
} else {
|
2023-01-28 14:30:54 +01:00
|
|
|
setState(
|
|
|
|
() {
|
|
|
|
day = day.subtract(const Duration(days: 1));
|
2023-09-04 20:45:45 +02:00
|
|
|
if (day.weekday == 7 && settings.skipWeekend) {
|
2023-01-28 14:30:54 +01:00
|
|
|
day = day.subtract(const Duration(days: 2));
|
|
|
|
}
|
|
|
|
loadMeals();
|
|
|
|
},
|
|
|
|
);
|
2022-04-09 17:54:08 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-04-04 20:22:30 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|