Odstranit stránku domů (#3)
This commit is contained in:
parent
be4f729cc0
commit
63f4d6c056
5 changed files with 35 additions and 228 deletions
|
@ -4,5 +4,6 @@
|
|||
- Domovská obrazovka nyní zobrazuje zprávu, pokud na dnešní den není žádné jídlo v jídelníčku
|
||||
- Upgrade knihovny
|
||||
- Odhlášení přesunuto do textového menu
|
||||
- Odstraněna stránka domů, hlavní stránka je nyní jídelníček
|
||||
# 0.1.0
|
||||
- První verze
|
|
@ -3,9 +3,27 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
|||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:opencanteen/loginmanager.dart';
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:opencanteen/okna/home.dart';
|
||||
import 'package:canteenlib/canteenlib.dart';
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
@ -88,7 +106,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => HomePage(
|
||||
builder: (context) => JidelnicekPage(
|
||||
user: r["user"]!,
|
||||
canteen: canteen,
|
||||
)),
|
||||
|
@ -213,7 +231,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => HomePage(
|
||||
builder: (context) => JidelnicekPage(
|
||||
user: userControl.text,
|
||||
canteen: canteen,
|
||||
)),
|
||||
|
|
|
@ -1,161 +0,0 @@
|
|||
import 'package:canteenlib/canteenlib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:opencanteen/main.dart';
|
||||
import 'package:opencanteen/util.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({Key? key, required this.user, required this.canteen})
|
||||
: super(key: key);
|
||||
|
||||
final String user;
|
||||
final Canteen canteen;
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
double kredit = 0.0;
|
||||
Jidelnicek? dnes;
|
||||
Jidlo? jidloDnes;
|
||||
List<Widget> obsah = [];
|
||||
|
||||
Future<void> nactiJidlo() async {
|
||||
obsah = [];
|
||||
widget.canteen.ziskejUzivatele().then((kr) {
|
||||
widget.canteen.jidelnicekDen().then((jd) {
|
||||
setState(() {
|
||||
kredit = kr.kredit;
|
||||
dnes = jd;
|
||||
if (jd.jidla.isEmpty) {
|
||||
obsah = [
|
||||
const Text(
|
||||
"Žádné jídlo pro dnešní den",
|
||||
style: TextStyle(fontSize: 20),
|
||||
)
|
||||
];
|
||||
}
|
||||
for (var j in jd.jidla) {
|
||||
if (j.objednano) jidloDnes = j;
|
||||
obsah.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(j.varianta),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: Text(
|
||||
j.nazev,
|
||||
),
|
||||
),
|
||||
Text("${j.cena} Kč"),
|
||||
Checkbox(
|
||||
value: j.objednano,
|
||||
fillColor: (j.lzeObjednat)
|
||||
? MaterialStateProperty.all(Colors.blue)
|
||||
: MaterialStateProperty.all(Colors.grey),
|
||||
onChanged: (v) => setState(() {
|
||||
// TODO exception handling
|
||||
if (!j.lzeObjednat) return;
|
||||
widget.canteen.objednat(j);
|
||||
nactiJidlo();
|
||||
}))
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}).catchError((o) {
|
||||
if (!widget.canteen.prihlasen) {
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (c) => const LoginPage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void kliknuti(String value) {
|
||||
switch (value) {
|
||||
case 'Odhlásit se':
|
||||
const storage = FlutterSecureStorage();
|
||||
storage.deleteAll();
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (c) => const LoginPage()));
|
||||
break;
|
||||
case 'Nahlásit chybu':
|
||||
launch("https://github.com/hernikplays/opencanteen/issues/new/choose");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
nactiJidlo();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
drawer: drawerGenerator(context, widget.canteen, widget.user, 1),
|
||||
appBar: AppBar(
|
||||
title: const Text("Domů"),
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
onSelected: kliknuti,
|
||||
itemBuilder: (BuildContext context) {
|
||||
return {'Nahlásit chybu', 'Odhlásit se'}.map((String choice) {
|
||||
return PopupMenuItem<String>(
|
||||
value: choice,
|
||||
child: Text(choice),
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: nactiJidlo,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height / 1.5,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Text(
|
||||
"${widget.user} - $kredit kč",
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Text(
|
||||
"Dnes je ${DateTime.now().day}. ${DateTime.now().month}.",
|
||||
style: const TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: Column(children: obsah),
|
||||
),
|
||||
],
|
||||
),
|
||||
width: MediaQuery.of(context).size.width - 50,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -178,7 +178,7 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
drawer: drawerGenerator(context, widget.canteen, widget.user, 2),
|
||||
drawer: drawerGenerator(context, widget.canteen, widget.user, 1),
|
||||
appBar: AppBar(
|
||||
title: const Text('Jídelníček'),
|
||||
),
|
||||
|
@ -227,16 +227,23 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
|||
SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: GestureDetector(
|
||||
child: Column(children: obsah),
|
||||
child: Container(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimary
|
||||
.withOpacity(0),
|
||||
child: Column(children: obsah),
|
||||
height: MediaQuery.of(context).size.height - 160,
|
||||
),
|
||||
onHorizontalDragEnd: (details) {
|
||||
if (details.primaryVelocity?.compareTo(0) == -1) {
|
||||
setState(() {
|
||||
den = den.subtract(const Duration(days: 1));
|
||||
den = den.add(const Duration(days: 1));
|
||||
nactiJidlo();
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
den = den.add(const Duration(days: 1));
|
||||
den = den.subtract(const Duration(days: 1));
|
||||
nactiJidlo();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import 'package:canteenlib/canteenlib.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:opencanteen/okna/burza.dart';
|
||||
|
||||
import 'okna/home.dart';
|
||||
import 'okna/jidelnicek.dart';
|
||||
|
||||
Drawer drawerGenerator(
|
||||
|
@ -23,17 +22,6 @@ Drawer drawerGenerator(
|
|||
leading: const Icon(Icons.home),
|
||||
onTap: () => Navigator.pop(context),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.restaurant),
|
||||
title: const Text('Jídelníček'),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
JidelnicekPage(canteen: canteen, user: user),
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.store),
|
||||
title: const Text('Burza'),
|
||||
|
@ -48,42 +36,6 @@ Drawer drawerGenerator(
|
|||
),
|
||||
);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
// Jidelnicek page
|
||||
drawer = Drawer(
|
||||
child: ListView(
|
||||
children: [
|
||||
const DrawerHeader(
|
||||
child: Text("OpenCanteen"),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text("Domů"),
|
||||
leading: const Icon(Icons.home),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (c) => HomePage(canteen: canteen, user: user))),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.restaurant),
|
||||
selected: true,
|
||||
title: const Text('Jídelníček'),
|
||||
onTap: () => Navigator.pop(context),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.store),
|
||||
title: const Text('Burza'),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BurzaPage(canteen: canteen, user: user),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
drawer = Drawer(
|
||||
|
@ -98,18 +50,8 @@ Drawer drawerGenerator(
|
|||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (c) => HomePage(canteen: canteen, user: user))),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.restaurant),
|
||||
title: const Text('Jídelníček'),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
JidelnicekPage(canteen: canteen, user: user),
|
||||
),
|
||||
),
|
||||
builder: (c) =>
|
||||
JidelnicekPage(canteen: canteen, user: user))),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.store),
|
||||
|
|
Reference in a new issue