This repository has been archived on 2024-07-21. You can view files and clone it, but cannot push or open issues or pull requests.
opencanteen/lib/util.dart

126 lines
3.6 KiB
Dart
Raw Permalink Normal View History

2022-12-12 16:48:19 +01:00
import 'dart:io';
2022-04-04 20:22:30 +02:00
import 'package:canteenlib/canteenlib.dart';
import 'package:flutter/cupertino.dart';
2022-04-04 20:22:30 +02:00
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
2022-12-14 20:02:32 +01:00
import 'package:opencanteen/okna/burza.dart';
import 'package:opencanteen/okna/jidelnicek.dart';
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
2022-12-12 16:48:19 +01:00
Drawer drawerGenerator(BuildContext context, Canteen canteen, int p) {
2022-04-04 20:22:30 +02:00
Drawer drawer = const Drawer();
switch (p) {
case 1:
// Home page
drawer = Drawer(
child: ListView(
children: [
2022-05-15 16:59:55 +02:00
DrawerHeader(
2023-01-28 15:41:17 +01:00
child: Text(AppLocalizations.of(context)!.appName),
2022-04-04 20:22:30 +02:00
),
ListTile(
selected: true,
2023-01-28 15:41:17 +01:00
title: Text(AppLocalizations.of(context)!.home),
2022-04-04 20:22:30 +02:00
leading: const Icon(Icons.home),
onTap: () => Navigator.pop(context),
),
2022-04-05 19:48:14 +02:00
ListTile(
leading: const Icon(Icons.store),
2023-01-28 15:41:17 +01:00
title: Text(AppLocalizations.of(context)!.exchange),
2022-04-05 19:48:14 +02:00
onTap: () => Navigator.push(
context,
platformRouter((context) => BurzaView(canteen: canteen)),
2022-04-05 19:48:14 +02:00
),
),
2022-04-04 20:22:30 +02:00
],
),
);
break;
2022-04-05 19:48:14 +02:00
case 3:
drawer = Drawer(
child: ListView(
children: [
2022-05-15 16:59:55 +02:00
DrawerHeader(
2023-01-28 15:41:17 +01:00
child: Text(AppLocalizations.of(context)!.appName),
2022-04-05 19:48:14 +02:00
),
ListTile(
leading: const Icon(Icons.home),
2023-01-28 15:41:17 +01:00
title: Text(AppLocalizations.of(context)!.home),
2022-04-05 19:48:14 +02:00
onTap: () => Navigator.push(
2022-12-14 20:02:32 +01:00
context,
platformRouter((c) => MealView(canteen: canteen)),
2022-12-14 20:02:32 +01:00
),
2022-04-05 19:48:14 +02:00
),
ListTile(
leading: const Icon(Icons.store),
selected: true,
2023-01-28 15:41:17 +01:00
title: Text(AppLocalizations.of(context)!.exchange),
2022-04-05 19:48:14 +02:00
onTap: () => Navigator.pop(context),
),
],
),
);
2022-04-04 20:22:30 +02:00
}
return drawer;
}
class OfflineMeal {
String name;
String variant;
bool ordered;
double price;
bool onExchange;
DateTime day;
OfflineMeal(
{required this.name,
required this.variant,
required this.ordered,
required this.price,
required this.onExchange,
required this.day});
}
/// Parses [DateTime] from [TimeOfDay]
DateTime timeToDate(TimeOfDay c) {
var now = DateTime.now();
return DateTime.parse(
"${now.year}-${(now.month < 10 ? "0" : "") + now.month.toString()}-${(now.day < 10 ? "0" : "") + now.day.toString()} ${(c.hour < 10 ? "0" : "") + c.hour.toString()}:${(c.minute < 10 ? "0" : "") + c.minute.toString()}:00");
}
/// List of instances to be used in the dropdown menu
List<Map<String, String>> instance = [
{"name": "SŠTE Brno, Olomoucká", "url": "https://stravovani.sstebrno.cz"},
{"name": "Jiné", "url": ""}
];
/// Used to display either a toas or a snackbar
void showInfo(BuildContext context, String message) {
if (Platform.isAndroid) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
duration: const Duration(seconds: 4),
),
);
} else {
Fluttertoast.showToast(
msg: message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 3,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
}
}
Route platformRouter(Widget Function(BuildContext context) builder) =>
(Platform.isAndroid)
? MaterialPageRoute(builder: builder)
: CupertinoPageRoute(builder: builder);