2022-04-05 19:48:14 +02:00
|
|
|
import 'package:canteenlib/canteenlib.dart';
|
2022-12-12 16:48:19 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-04-05 19:48:14 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-12-12 16:48:19 +01:00
|
|
|
import 'package:opencanteen/okna/ios/login.dart';
|
2022-04-05 19:48:14 +02:00
|
|
|
import 'package:opencanteen/util.dart';
|
|
|
|
|
2022-12-12 16:48:19 +01:00
|
|
|
import '../../lang/lang.dart';
|
2022-04-05 19:48:14 +02:00
|
|
|
|
2022-12-12 16:48:19 +01:00
|
|
|
class IOSBurza extends StatefulWidget {
|
|
|
|
const IOSBurza({Key? key, required this.canteen}) : super(key: key);
|
2022-04-05 19:48:14 +02:00
|
|
|
final Canteen canteen;
|
|
|
|
@override
|
2022-12-12 16:48:19 +01:00
|
|
|
State<IOSBurza> createState() => _IOSBurzaState();
|
2022-04-05 19:48:14 +02:00
|
|
|
}
|
|
|
|
|
2022-12-12 16:48:19 +01:00
|
|
|
class _IOSBurzaState extends State<IOSBurza> {
|
2022-04-05 19:48:14 +02:00
|
|
|
List<Widget> obsah = [];
|
|
|
|
double kredit = 0.0;
|
2022-05-15 16:59:55 +02:00
|
|
|
Future<void> nactiBurzu(BuildContext context) async {
|
2022-04-05 19:48:14 +02:00
|
|
|
obsah = [const CircularProgressIndicator()];
|
|
|
|
widget.canteen.ziskejUzivatele().then((kr) {
|
|
|
|
kredit = kr.kredit;
|
|
|
|
widget.canteen.ziskatBurzu().then((burza) {
|
|
|
|
setState(() {
|
|
|
|
obsah = [];
|
|
|
|
if (burza.isEmpty) {
|
|
|
|
obsah = [
|
2022-05-15 16:59:55 +02:00
|
|
|
Text(
|
|
|
|
Languages.of(context)!.noExchange,
|
|
|
|
style: const TextStyle(fontSize: 20),
|
2022-04-05 19:48:14 +02:00
|
|
|
),
|
2022-05-15 16:59:55 +02:00
|
|
|
Text(Languages.of(context)!.pullToReload)
|
2022-04-05 19:48:14 +02:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
for (var b in burza) {
|
|
|
|
obsah.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"),
|
2022-12-12 16:48:19 +01:00
|
|
|
CupertinoButton(
|
2022-04-05 19:48:14 +02:00
|
|
|
onPressed: () {
|
2022-04-09 17:54:08 +02:00
|
|
|
widget.canteen.objednatZBurzy(b).then((a) {
|
2022-04-12 21:20:22 +02:00
|
|
|
if (a) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
2022-12-12 16:48:19 +01:00
|
|
|
builder: (context) => CupertinoAlertDialog(
|
2022-05-15 16:59:55 +02:00
|
|
|
title: Text(Languages.of(context)!.ordered),
|
|
|
|
content: Text(
|
|
|
|
Languages.of(context)!.orderSuccess),
|
2022-04-12 21:20:22 +02:00
|
|
|
actions: [
|
2022-12-12 16:48:19 +01:00
|
|
|
CupertinoButton(
|
2022-05-15 16:59:55 +02:00
|
|
|
child: Text(Languages.of(context)!.ok),
|
2022-04-12 21:20:22 +02:00
|
|
|
onPressed: () =>
|
|
|
|
Navigator.of(context).pop(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
2022-12-12 16:48:19 +01:00
|
|
|
builder: (context) => CupertinoAlertDialog(
|
2022-05-15 16:59:55 +02:00
|
|
|
title: Text(
|
|
|
|
Languages.of(context)!.cannotOrder),
|
|
|
|
content: Text(
|
|
|
|
Languages.of(context)!.errorOrdering),
|
2022-04-12 21:20:22 +02:00
|
|
|
actions: [
|
2022-12-12 16:48:19 +01:00
|
|
|
CupertinoButton(
|
2022-05-15 16:59:55 +02:00
|
|
|
child: Text(Languages.of(context)!.ok),
|
2022-04-12 21:20:22 +02:00
|
|
|
onPressed: () =>
|
|
|
|
Navigator.of(context).pop(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-05-15 16:59:55 +02:00
|
|
|
nactiBurzu(context);
|
2022-04-05 19:48:14 +02:00
|
|
|
});
|
|
|
|
},
|
2022-05-15 16:59:55 +02:00
|
|
|
child: Text(Languages.of(context)!.order)),
|
2022-04-05 19:48:14 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).catchError((o) {
|
|
|
|
if (!widget.canteen.prihlasen) {
|
|
|
|
Navigator.pushReplacement(
|
2022-12-12 16:48:19 +01:00
|
|
|
context, MaterialPageRoute(builder: (c) => const IOSLogin()));
|
2022-04-05 19:48:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-05-15 16:59:55 +02:00
|
|
|
nactiBurzu(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(
|
2022-05-15 16:59:55 +02:00
|
|
|
title: Text(Languages.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),
|
|
|
|
Text("${Languages.of(context)!.balance}$kredit Kč"),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
SingleChildScrollView(
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
child: SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height / 1.3,
|
|
|
|
child: Column(children: obsah),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-04-05 19:48:14 +02:00
|
|
|
),
|
|
|
|
),
|
2022-05-15 16:59:55 +02:00
|
|
|
onRefresh: () => nactiBurzu(context)),
|
2022-04-05 19:48:14 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|