2022-04-05 19:48:14 +02:00
|
|
|
import 'package:canteenlib/canteenlib.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-12-14 20:02:32 +01:00
|
|
|
import 'package:opencanteen/okna/login.dart';
|
2023-01-28 14:30:54 +01:00
|
|
|
import 'package:opencanteen/pw/platformbutton.dart';
|
|
|
|
import 'package:opencanteen/pw/platformdialog.dart';
|
2022-04-05 19:48:14 +02:00
|
|
|
import 'package:opencanteen/util.dart';
|
|
|
|
|
2023-01-28 15:41:17 +01:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2022-04-05 19:48:14 +02:00
|
|
|
|
2022-12-14 20:02:32 +01:00
|
|
|
class BurzaView extends StatefulWidget {
|
2023-11-28 20:10:34 +01:00
|
|
|
const BurzaView({super.key, required this.canteen});
|
2022-04-05 19:48:14 +02:00
|
|
|
final Canteen canteen;
|
|
|
|
@override
|
2022-12-14 20:02:32 +01:00
|
|
|
State<BurzaView> createState() => _BurzaViewState();
|
2022-04-05 19:48:14 +02:00
|
|
|
}
|
|
|
|
|
2022-12-14 20:02:32 +01:00
|
|
|
class _BurzaViewState extends State<BurzaView> {
|
2023-01-28 14:30:54 +01:00
|
|
|
List<Widget> content = [];
|
|
|
|
double balance = 0.0;
|
|
|
|
|
|
|
|
Future<void> loadExchange(BuildContext context) async {
|
|
|
|
content = [const CircularProgressIndicator()];
|
|
|
|
var uzivatel = await widget.canteen.ziskejUzivatele().catchError((o) {
|
2022-04-05 19:48:14 +02:00
|
|
|
if (!widget.canteen.prihlasen) {
|
|
|
|
Navigator.pushReplacement(
|
2023-01-28 14:30:54 +01:00
|
|
|
context, platformRouter((c) => const LoginPage()));
|
|
|
|
}
|
|
|
|
return Uzivatel(kredit: 0);
|
|
|
|
});
|
|
|
|
balance = uzivatel.kredit;
|
|
|
|
var burza = await widget.canteen.ziskatBurzu();
|
|
|
|
setState(() {
|
|
|
|
content = [];
|
|
|
|
if (burza.isEmpty) {
|
|
|
|
content = [
|
|
|
|
Text(
|
2023-01-28 15:41:17 +01:00
|
|
|
AppLocalizations.of(context)!.noExchange,
|
2023-01-28 14:30:54 +01:00
|
|
|
style: const TextStyle(fontSize: 20),
|
|
|
|
),
|
2023-01-28 15:41:17 +01:00
|
|
|
Text(AppLocalizations.of(context)!.pullToReload)
|
2023-01-28 14:30:54 +01:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
for (var b in burza) {
|
|
|
|
content.add(
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 15),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text("${b.den.day}. ${b.den.month}."),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
b.nazev,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text("${b.pocet}x"),
|
|
|
|
PlatformButton(
|
|
|
|
onPressed: () {
|
|
|
|
widget.canteen.objednatZBurzy(b).then(
|
|
|
|
(a) {
|
|
|
|
if (a) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title: AppLocalizations.of(context)!.ordered,
|
|
|
|
content:
|
|
|
|
AppLocalizations.of(context)!.orderSuccess,
|
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,
|
|
|
|
builder: (context) => PlatformDialog(
|
2023-01-28 15:41:17 +01:00
|
|
|
title:
|
|
|
|
AppLocalizations.of(context)!.cannotOrder,
|
|
|
|
content:
|
|
|
|
AppLocalizations.of(context)!.errorOrdering,
|
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(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
loadExchange(context);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
2023-01-28 15:41:17 +01:00
|
|
|
text: AppLocalizations.of(context)!.order,
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2023-01-28 14:30:54 +01:00
|
|
|
loadExchange(context);
|
2022-04-05 19:48:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2022-12-12 16:48:19 +01:00
|
|
|
drawer: drawerGenerator(context, widget.canteen, 3),
|
2022-04-05 19:48:14 +02:00
|
|
|
appBar: AppBar(
|
2023-01-28 15:41:17 +01:00
|
|
|
title: Text(AppLocalizations.of(context)!.exchange),
|
2022-04-05 19:48:14 +02:00
|
|
|
),
|
|
|
|
body: RefreshIndicator(
|
|
|
|
child: Center(
|
2022-05-17 18:14:14 +02:00
|
|
|
child: SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width - 50,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 10),
|
2023-01-28 15:41:17 +01:00
|
|
|
Text("${AppLocalizations.of(context)!.balance}$balance Kč"),
|
2022-05-17 18:14:14 +02:00
|
|
|
const SizedBox(height: 10),
|
|
|
|
SingleChildScrollView(
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
child: SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height / 1.3,
|
2023-01-28 14:30:54 +01:00
|
|
|
child: Column(children: content),
|
2022-05-17 18:14:14 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-04-05 19:48:14 +02:00
|
|
|
),
|
|
|
|
),
|
2023-01-28 14:30:54 +01:00
|
|
|
onRefresh: () => loadExchange(context)),
|
2022-04-05 19:48:14 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|