Odstranit stránku domů (#3)

This commit is contained in:
Matyáš Caras 2022-04-19 15:35:40 +02:00
parent be4f729cc0
commit 63f4d6c056
5 changed files with 35 additions and 228 deletions

View file

@ -4,5 +4,6 @@
- Domovská obrazovka nyní zobrazuje zprávu, pokud na dnešní den není žádné jídlo v jídelníčku - Domovská obrazovka nyní zobrazuje zprávu, pokud na dnešní den není žádné jídlo v jídelníčku
- Upgrade knihovny - Upgrade knihovny
- Odhlášení přesunuto do textového menu - Odhlášení přesunuto do textového menu
- Odstraněna stránka domů, hlavní stránka je nyní jídelníček
# 0.1.0 # 0.1.0
- První verze - První verze

View file

@ -3,9 +3,27 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:opencanteen/loginmanager.dart'; import 'package:opencanteen/loginmanager.dart';
import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:opencanteen/okna/home.dart';
import 'package:canteenlib/canteenlib.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() { void main() {
runApp(const MyApp()); runApp(const MyApp());
} }
@ -88,7 +106,7 @@ class _LoginPageState extends State<LoginPage> {
Navigator.pushReplacement( Navigator.pushReplacement(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => HomePage( builder: (context) => JidelnicekPage(
user: r["user"]!, user: r["user"]!,
canteen: canteen, canteen: canteen,
)), )),
@ -213,7 +231,7 @@ class _LoginPageState extends State<LoginPage> {
Navigator.pushReplacement( Navigator.pushReplacement(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => HomePage( builder: (context) => JidelnicekPage(
user: userControl.text, user: userControl.text,
canteen: canteen, canteen: canteen,
)), )),

View file

@ -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}"),
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",
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,
),
),
),
),
),
);
}
}

View file

@ -178,7 +178,7 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
drawer: drawerGenerator(context, widget.canteen, widget.user, 2), drawer: drawerGenerator(context, widget.canteen, widget.user, 1),
appBar: AppBar( appBar: AppBar(
title: const Text('Jídelníček'), title: const Text('Jídelníček'),
), ),
@ -227,16 +227,23 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
SingleChildScrollView( SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
child: GestureDetector( child: GestureDetector(
child: Container(
color: Theme.of(context)
.colorScheme
.onPrimary
.withOpacity(0),
child: Column(children: obsah), child: Column(children: obsah),
height: MediaQuery.of(context).size.height - 160,
),
onHorizontalDragEnd: (details) { onHorizontalDragEnd: (details) {
if (details.primaryVelocity?.compareTo(0) == -1) { if (details.primaryVelocity?.compareTo(0) == -1) {
setState(() { setState(() {
den = den.subtract(const Duration(days: 1)); den = den.add(const Duration(days: 1));
nactiJidlo(); nactiJidlo();
}); });
} else { } else {
setState(() { setState(() {
den = den.add(const Duration(days: 1)); den = den.subtract(const Duration(days: 1));
nactiJidlo(); nactiJidlo();
}); });
} }

View file

@ -2,7 +2,6 @@ import 'package:canteenlib/canteenlib.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:opencanteen/okna/burza.dart'; import 'package:opencanteen/okna/burza.dart';
import 'okna/home.dart';
import 'okna/jidelnicek.dart'; import 'okna/jidelnicek.dart';
Drawer drawerGenerator( Drawer drawerGenerator(
@ -23,17 +22,6 @@ Drawer drawerGenerator(
leading: const Icon(Icons.home), leading: const Icon(Icons.home),
onTap: () => Navigator.pop(context), 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( ListTile(
leading: const Icon(Icons.store), leading: const Icon(Icons.store),
title: const Text('Burza'), 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; break;
case 3: case 3:
drawer = Drawer( drawer = Drawer(
@ -98,18 +50,8 @@ Drawer drawerGenerator(
onTap: () => Navigator.push( onTap: () => Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (c) => HomePage(canteen: canteen, user: user))), builder: (c) =>
), JidelnicekPage(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),
),
),
), ),
ListTile( ListTile(
leading: const Icon(Icons.store), leading: const Icon(Icons.store),