feat: přidat projekt
This commit is contained in:
commit
95b26b4063
42 changed files with 5261 additions and 0 deletions
722
lib/okna/all_records.dart
Normal file
722
lib/okna/all_records.dart
Normal file
|
@ -0,0 +1,722 @@
|
|||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:denikprogramatora/okna/app.dart';
|
||||
import 'package:denikprogramatora/okna/settings.dart';
|
||||
import 'package:denikprogramatora/okna/signin_page.dart';
|
||||
import 'package:denikprogramatora/utils/devicecontainer.dart';
|
||||
import 'package:denikprogramatora/utils/input_decoration.dart';
|
||||
import 'package:denikprogramatora/utils/loading_widget.dart';
|
||||
import 'package:denikprogramatora/utils/months.dart';
|
||||
import 'package:denikprogramatora/utils/my_category.dart';
|
||||
import 'package:denikprogramatora/utils/my_container.dart';
|
||||
import 'package:denikprogramatora/utils/new_record_dialog.dart';
|
||||
import 'package:denikprogramatora/utils/programmer.dart';
|
||||
import 'package:denikprogramatora/utils/show_info_dialog.dart';
|
||||
import 'package:denikprogramatora/utils/vzhled.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:responsive_sizer/responsive_sizer.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
/*
|
||||
Copyright (C) 2022 Matyáš Caras a Richard Pavlikán
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class AllRecordsPage extends StatefulWidget {
|
||||
const AllRecordsPage({super.key});
|
||||
|
||||
@override
|
||||
State<AllRecordsPage> createState() => _AllRecordsPageState();
|
||||
}
|
||||
|
||||
class _AllRecordsPageState extends State<AllRecordsPage> {
|
||||
bool _loading = true;
|
||||
Month mesic = months[0];
|
||||
int selectedDay = DateTime.now().day;
|
||||
int year = DateTime.now().year;
|
||||
|
||||
List<MyCategory> categories = [MyCategory("Nic", "nic")];
|
||||
List<Programmer> programmers = [
|
||||
const Programmer("Nic", "nic"),
|
||||
Programmer(name, userUid)
|
||||
];
|
||||
List filterJazyky = [
|
||||
{"jazyk": "Nic", "barva": 0xff8200f3},
|
||||
];
|
||||
|
||||
late String selectedCategory;
|
||||
late String selectedProgrammer;
|
||||
bool newestToOldest = true;
|
||||
late String selectedJazyk;
|
||||
DateTime fromDate =
|
||||
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day);
|
||||
DateTime toDate =
|
||||
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day);
|
||||
|
||||
bool searchByFromDate = false;
|
||||
bool searchByToDate = false;
|
||||
|
||||
int timeHour = 0;
|
||||
int timeMinute = 0;
|
||||
int review = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (FirebaseAuth.instance.currentUser == null) {
|
||||
if (kDebugMode) print("user should not be here");
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => const SignInPage()),
|
||||
(route) => false);
|
||||
return;
|
||||
}
|
||||
|
||||
name = FirebaseAuth.instance.currentUser!.displayName!;
|
||||
|
||||
ref.collection("programmers").get().then((value) {
|
||||
for (var snap in value.docs) {
|
||||
var data = snap.data();
|
||||
|
||||
programmers.add(Programmer(data["name"], snap.id));
|
||||
}
|
||||
});
|
||||
|
||||
ref.collection("categories").get().then((value) {
|
||||
for (var snap in value.docs) {
|
||||
var data = snap.data();
|
||||
categories.add(MyCategory(data["name"], snap.id));
|
||||
}
|
||||
});
|
||||
|
||||
filterJazyky.addAll(jazyky);
|
||||
|
||||
selectedCategory = categories[0].id;
|
||||
selectedProgrammer = programmers[0].id;
|
||||
selectedJazyk = "Nic";
|
||||
|
||||
mesic = months[DateTime.now().month - 1];
|
||||
|
||||
setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 90.w,
|
||||
child: (_loading)
|
||||
? const LoadingWidget()
|
||||
: CustomScrollView(
|
||||
slivers: [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
DeviceContainer(
|
||||
mainAxisAlignmentDesktop:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MyContainer(
|
||||
width: (Device.screenType == ScreenType.mobile)
|
||||
? 90.w
|
||||
: 35.w,
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
if (name != "error") Text("Ahoj $name"),
|
||||
TextButton(
|
||||
onPressed: () => showAboutDialog(
|
||||
context: context,
|
||||
applicationName: "Kodelog",
|
||||
applicationVersion: "1.1.0",
|
||||
applicationLegalese:
|
||||
"©️ 2023 Matyáš Caras a Richard Pavlikán,\n vydáno pod licencí AGPLv3",
|
||||
children: [
|
||||
TextButton(
|
||||
child: const Text("Zdrojový kód"),
|
||||
onPressed: () => launchUrlString(
|
||||
"https://github.com/Royal-Buccaneers/kodelog"),
|
||||
)
|
||||
]),
|
||||
child: const Text(
|
||||
"Licence",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await FirebaseAuth.instance.signOut();
|
||||
// ignore: use_build_context_synchronously
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (c) =>
|
||||
const SignInPage()),
|
||||
(route) => false);
|
||||
},
|
||||
child: const Text(
|
||||
"Odhlásit se",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
MyContainer(
|
||||
width: (Device.screenType == ScreenType.mobile)
|
||||
? 90.w
|
||||
: 40.w,
|
||||
child: DeviceContainer(
|
||||
mainAxisAlignmentDesktop:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const HlavniOkno()));
|
||||
},
|
||||
child: const Text(
|
||||
"Denní přehled",
|
||||
style:
|
||||
TextStyle(color: Vzhled.textColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
"Všechny\nzáznamy",
|
||||
style: TextStyle(
|
||||
color: Vzhled.textColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const NastaveniOkno()));
|
||||
},
|
||||
child: const Text(
|
||||
"Nastavení",
|
||||
style:
|
||||
TextStyle(color: Vzhled.textColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
OutlinedButton(
|
||||
onPressed: () =>
|
||||
showCreateItemDialog(context),
|
||||
style: Vzhled.orangeCudlik,
|
||||
child: const Text(
|
||||
"Přidat záznam",
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(
|
||||
child: MyContainer(
|
||||
width: 90.w,
|
||||
child: DeviceContainer(
|
||||
mainAxisAlignmentDesktop:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(
|
||||
width:
|
||||
(Device.screenType == ScreenType.mobile)
|
||||
? 80.w
|
||||
: 40.w,
|
||||
child: Column(
|
||||
children: [
|
||||
const Text("Filtr",
|
||||
style: Vzhled.nadpis),
|
||||
const SizedBox(height: 15),
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
"Záznamy seřazené od ${newestToOldest ? "nejnovějších po nejstarší" : "nejstarších po nejnovější"}"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
newestToOldest =
|
||||
!newestToOldest;
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
"Změnit",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
DeviceContainer(
|
||||
children: [
|
||||
const Text("Kategorie"),
|
||||
const SizedBox(width: 15),
|
||||
DropdownButton(
|
||||
value: selectedCategory,
|
||||
items: categories.map((e) {
|
||||
return DropdownMenuItem(
|
||||
value: e.id,
|
||||
child: Text(e.name));
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectedCategory = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
DeviceContainer(
|
||||
children: [
|
||||
const Text("Jazyk"),
|
||||
const SizedBox(width: 15),
|
||||
DropdownButton(
|
||||
value: selectedJazyk,
|
||||
dropdownColor:
|
||||
Vzhled.backgroundColor,
|
||||
items: filterJazyky
|
||||
.map(
|
||||
(e) => DropdownMenuItem(
|
||||
value: e["jazyk"],
|
||||
child: Text(e["jazyk"]),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectedJazyk =
|
||||
(value as String?)!;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
DeviceContainer(
|
||||
children: [
|
||||
const Text("Programátor"),
|
||||
const SizedBox(width: 15),
|
||||
DropdownButton(
|
||||
value: selectedProgrammer,
|
||||
items: programmers.map((e) {
|
||||
return DropdownMenuItem(
|
||||
value: e.id,
|
||||
child: Text(e.name));
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectedProgrammer = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
DeviceContainer(
|
||||
children: [
|
||||
const Text("Strávený čas"),
|
||||
const SizedBox(width: 15),
|
||||
SizedBox(
|
||||
width: 75,
|
||||
child: TextField(
|
||||
decoration:
|
||||
inputDecoration("Hodin"),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
timeHour =
|
||||
value.trim().isEmpty
|
||||
? 0
|
||||
: int.parse(value);
|
||||
});
|
||||
},
|
||||
keyboardType:
|
||||
TextInputType.number,
|
||||
inputFormatters: <
|
||||
TextInputFormatter>[
|
||||
FilteringTextInputFormatter
|
||||
.digitsOnly
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
SizedBox(
|
||||
width: 75,
|
||||
child: TextField(
|
||||
decoration:
|
||||
inputDecoration("Minut"),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
timeMinute =
|
||||
value.trim().isEmpty
|
||||
? 0
|
||||
: int.parse(value);
|
||||
});
|
||||
},
|
||||
keyboardType:
|
||||
TextInputType.number,
|
||||
inputFormatters: <
|
||||
TextInputFormatter>[
|
||||
FilteringTextInputFormatter
|
||||
.digitsOnly
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
if (timeMinute != 0 ||
|
||||
timeHour != 0)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
timeMinute = 0;
|
||||
timeHour = 0;
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
"Zrušit filtr",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
DeviceContainer(
|
||||
children: [
|
||||
const Text("Hodnocení"),
|
||||
const SizedBox(width: 15),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment
|
||||
.spaceBetween,
|
||||
children: List.generate(
|
||||
5,
|
||||
(index) {
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
review = index + 1;
|
||||
});
|
||||
},
|
||||
icon: Icon(Icons.star,
|
||||
color: (index + 1) <=
|
||||
review
|
||||
? Colors.yellow
|
||||
: Colors.grey),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
if (review != 0)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
review = 0;
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
"Zrušit filtr",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Row(
|
||||
children: [
|
||||
const Text("Od: "),
|
||||
const SizedBox(width: 15),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showDatePicker(
|
||||
context: context,
|
||||
initialDate: fromDate,
|
||||
firstDate: DateTime(
|
||||
DateTime.now()
|
||||
.year -
|
||||
5),
|
||||
lastDate: DateTime(
|
||||
DateTime.now()
|
||||
.year +
|
||||
5))
|
||||
.then((value) {
|
||||
setState(() {
|
||||
fromDate = value!;
|
||||
searchByFromDate = true;
|
||||
});
|
||||
}).onError(
|
||||
(error, stackTrace) =>
|
||||
null);
|
||||
},
|
||||
child: Text(searchByFromDate
|
||||
? "${fromDate.day}.${fromDate.month}.${fromDate.year}"
|
||||
: "Vybrat den"),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
if (searchByFromDate)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
searchByFromDate = false;
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
("Zrušit filtr"),
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Row(
|
||||
children: [
|
||||
const Text("Do: "),
|
||||
const SizedBox(width: 15),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showDatePicker(
|
||||
context: context,
|
||||
initialDate: toDate,
|
||||
firstDate: DateTime(
|
||||
DateTime.now()
|
||||
.year -
|
||||
5),
|
||||
lastDate: DateTime(
|
||||
DateTime.now()
|
||||
.year +
|
||||
5))
|
||||
.then((value) {
|
||||
setState(() {
|
||||
toDate = value!;
|
||||
searchByToDate = true;
|
||||
});
|
||||
}).onError(
|
||||
(error, stackTrace) =>
|
||||
null);
|
||||
},
|
||||
child: Text(searchByToDate
|
||||
? "${toDate.day}.${toDate.month}.${toDate.year}"
|
||||
: "Vybrat den"),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
if (searchByToDate)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
searchByToDate = false;
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
("Zrušit filtr"),
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width:
|
||||
(Device.screenType == ScreenType.mobile)
|
||||
? 80.w
|
||||
: 40.w,
|
||||
child: StreamBuilder(
|
||||
stream: ref
|
||||
.collection("records")
|
||||
.orderBy("fromDate",
|
||||
descending: newestToOldest)
|
||||
.snapshots(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
var docs = snapshot.data!.docs;
|
||||
|
||||
if (selectedProgrammer != "nic") {
|
||||
docs = docs
|
||||
.where((element) =>
|
||||
element
|
||||
.data()["programmer"] ==
|
||||
selectedProgrammer)
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (selectedCategory != "nic") {
|
||||
docs = docs
|
||||
.where((element) => (element
|
||||
.data()[
|
||||
"categories"] as List)
|
||||
.contains(selectedCategory))
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (selectedJazyk != "Nic") {
|
||||
docs = docs
|
||||
.where((element) =>
|
||||
element.data()["language"]
|
||||
["jazyk"] ==
|
||||
selectedJazyk)
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (searchByFromDate) {
|
||||
docs = docs
|
||||
.where((d) =>
|
||||
(d.data()["fromDate"]
|
||||
as Timestamp)
|
||||
.toDate()
|
||||
.compareTo(
|
||||
fromDate) ==
|
||||
1 ||
|
||||
(d.data()["fromDate"]
|
||||
as Timestamp)
|
||||
.toDate()
|
||||
.compareTo(
|
||||
fromDate) ==
|
||||
0)
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (searchByToDate) {
|
||||
docs = docs
|
||||
.where((d) =>
|
||||
(d.data()["toDate"]
|
||||
as Timestamp)
|
||||
.toDate()
|
||||
.compareTo(
|
||||
toDate) ==
|
||||
-1 ||
|
||||
(d.data()["toDate"]
|
||||
as Timestamp)
|
||||
.toDate()
|
||||
.compareTo(
|
||||
toDate) ==
|
||||
0)
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (timeHour != 0 ||
|
||||
timeMinute != 0) {
|
||||
if (kDebugMode) {
|
||||
print(
|
||||
"${timeHour == 0 ? "" : (timeHour == 1 ? "$timeHour hodina" : "$timeHour hodin")}${timeMinute == 0 ? "" : (timeMinute == 1 ? "a $timeMinute minuta" : " a $timeMinute minut")}");
|
||||
}
|
||||
docs = docs
|
||||
.where((element) => (element
|
||||
.data()["codingTime"] ==
|
||||
"${timeHour == 0 ? "" : (timeHour == 1 ? "$timeHour hodina" : "$timeHour hodin")}${timeMinute == 0 ? "" : (timeMinute == 1 ? "a $timeMinute minuta" : " a $timeMinute minut")}"))
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (review != 0) {
|
||||
docs = docs
|
||||
.where((element) =>
|
||||
element.data()["review"] ==
|
||||
review)
|
||||
.toList();
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: List.generate(
|
||||
docs.length,
|
||||
(index) {
|
||||
var data = docs[index].data();
|
||||
|
||||
return Padding(
|
||||
padding:
|
||||
const EdgeInsets.all(8.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
const BorderRadius
|
||||
.all(
|
||||
Radius.circular(4),
|
||||
),
|
||||
color: Color(
|
||||
data["language"]
|
||||
["barva"]),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () =>
|
||||
showInfoDialog(
|
||||
context,
|
||||
data,
|
||||
docs[index].id),
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets
|
||||
.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"${(data["fromDate"] as Timestamp).toDate().year}.${(data["fromDate"] as Timestamp).toDate().month}.${(data["fromDate"] as Timestamp).toDate().day} ${(data["fromDate"] as Timestamp).toDate().hour < 10 ? "0${(data["fromDate"] as Timestamp).toDate().hour}" : (data["fromDate"] as Timestamp).toDate().hour}:${(data["fromDate"] as Timestamp).toDate().minute < 10 ? "0${(data["fromDate"] as Timestamp).toDate().minute}" : (data["fromDate"] as Timestamp).toDate().minute}"),
|
||||
const SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Text(
|
||||
" - ${data["language"]["jazyk"]}")
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
return const LoadingWidget();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
554
lib/okna/app.dart
Normal file
554
lib/okna/app.dart
Normal file
|
@ -0,0 +1,554 @@
|
|||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:denikprogramatora/okna/all_records.dart';
|
||||
import 'package:denikprogramatora/okna/settings.dart';
|
||||
import 'package:denikprogramatora/okna/signin_page.dart';
|
||||
import 'package:denikprogramatora/utils/devicecontainer.dart';
|
||||
import 'package:denikprogramatora/utils/loading_widget.dart';
|
||||
import 'package:denikprogramatora/utils/months.dart';
|
||||
import 'package:denikprogramatora/utils/my_container.dart';
|
||||
import 'package:denikprogramatora/utils/new_record_dialog.dart';
|
||||
import 'package:denikprogramatora/utils/vzhled.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:responsive_sizer/responsive_sizer.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
import '../utils/razeni.dart';
|
||||
import '../utils/show_info_dialog.dart';
|
||||
|
||||
/*
|
||||
Copyright (C) 2022 Matyáš Caras a Richard Pavlikán
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var ref = FirebaseFirestore.instance
|
||||
.collection("users")
|
||||
.doc(FirebaseAuth.instance.currentUser!.uid);
|
||||
String name = "error";
|
||||
String userUid = "error";
|
||||
|
||||
class HlavniOkno extends StatefulWidget {
|
||||
const HlavniOkno({super.key});
|
||||
|
||||
@override
|
||||
State<HlavniOkno> createState() => _HlavniOknoState();
|
||||
}
|
||||
|
||||
class _HlavniOknoState extends State<HlavniOkno> {
|
||||
bool _loading = true;
|
||||
|
||||
Month mesic = months[0];
|
||||
int selectedDay = DateTime.now().day;
|
||||
int year = DateTime.now().year;
|
||||
int vybraneRazeni = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (FirebaseAuth.instance.currentUser == null) {
|
||||
if (kDebugMode) print("user should not be here");
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => const SignInPage()),
|
||||
(route) => false);
|
||||
return;
|
||||
}
|
||||
|
||||
userUid = FirebaseAuth.instance.currentUser!.uid;
|
||||
name = FirebaseAuth.instance.currentUser!.displayName!;
|
||||
|
||||
mesic = months[DateTime.now().month - 1];
|
||||
|
||||
setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 90.w,
|
||||
child: (_loading)
|
||||
? const LoadingWidget()
|
||||
: CustomScrollView(
|
||||
slivers: [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: Column(
|
||||
children: [
|
||||
DeviceContainer(
|
||||
mainAxisAlignmentDesktop:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MyContainer(
|
||||
width: (Device.screenType == ScreenType.mobile)
|
||||
? 90.w
|
||||
: 35.w,
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
if (name != "error") Text("Ahoj $name"),
|
||||
TextButton(
|
||||
onPressed: () => showAboutDialog(
|
||||
context: context,
|
||||
applicationName: "Kodelog",
|
||||
applicationVersion: "1.1.0",
|
||||
applicationLegalese:
|
||||
"©️ 2023 Matyáš Caras a Richard Pavlikán,\n vydáno pod licencí AGPLv3",
|
||||
children: [
|
||||
TextButton(
|
||||
child: const Text("Zdrojový kód"),
|
||||
onPressed: () => launchUrlString(
|
||||
"https://github.com/Royal-Buccaneers/kodelog"),
|
||||
)
|
||||
]),
|
||||
child: const Text(
|
||||
"Licence",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await FirebaseAuth.instance.signOut();
|
||||
if (!mounted) return;
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (c) =>
|
||||
const SignInPage()),
|
||||
(route) => false);
|
||||
},
|
||||
child: const Text(
|
||||
"Odhlásit se",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
MyContainer(
|
||||
width: (Device.screenType == ScreenType.mobile)
|
||||
? 95.w
|
||||
: 45.w,
|
||||
child: DeviceContainer(
|
||||
mainAxisAlignmentDesktop:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
"Denní přehled",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Vzhled.textColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const AllRecordsPage()));
|
||||
},
|
||||
child: const Text(
|
||||
"Všechny\nzáznamy",
|
||||
style:
|
||||
TextStyle(color: Vzhled.textColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const NastaveniOkno()));
|
||||
},
|
||||
child: const Text(
|
||||
"Nastavení",
|
||||
style:
|
||||
TextStyle(color: Vzhled.textColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
OutlinedButton(
|
||||
onPressed: () =>
|
||||
showCreateItemDialog(context),
|
||||
style: Vzhled.orangeCudlik,
|
||||
child: const Text(
|
||||
"Přidat záznam",
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(
|
||||
child: MyContainer(
|
||||
width: 90.w,
|
||||
child: DeviceContainer(
|
||||
mainAxisAlignmentDesktop:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 40.w,
|
||||
child: StreamBuilder(
|
||||
stream:
|
||||
ref.collection("records").snapshots(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
var docs = snapshot.data!.docs;
|
||||
var jenMesic = docs
|
||||
.where((d) =>
|
||||
DateTime.parse(
|
||||
"$year-${(mesic.position + 1 < 10) ? "0${mesic.position + 1}" : mesic.position + 1}-${selectedDay < 10 ? "0$selectedDay" : selectedDay} 00:00:00")
|
||||
.isBefore(
|
||||
(d.data()["toDate"]
|
||||
as Timestamp)
|
||||
.toDate()) &&
|
||||
DateTime.parse(
|
||||
"$year-${(mesic.position + 1 < 10) ? "0${mesic.position + 1}" : mesic.position + 1}-${selectedDay < 10 ? "0$selectedDay" : selectedDay} 23:59:59")
|
||||
.isAfter(
|
||||
(d.data()["fromDate"]
|
||||
as Timestamp)
|
||||
.toDate()))
|
||||
.toList() // vybere pouze záznamy, které probíhají ve vybraný den
|
||||
..sort(
|
||||
razeni[vybraneRazeni],
|
||||
); // seřadíme podle vybrané metody řazení
|
||||
if (jenMesic.isEmpty) {
|
||||
return const Text(
|
||||
"Nic",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 25),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: List.generate(
|
||||
jenMesic.length,
|
||||
(index) {
|
||||
var data =
|
||||
jenMesic[index].data();
|
||||
|
||||
return Padding(
|
||||
padding:
|
||||
const EdgeInsets.all(8.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
const BorderRadius
|
||||
.all(
|
||||
Radius.circular(4),
|
||||
),
|
||||
color: Color(
|
||||
data["language"]
|
||||
["barva"]),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () =>
|
||||
showInfoDialog(
|
||||
context,
|
||||
data,
|
||||
jenMesic[index]
|
||||
.id),
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets
|
||||
.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"${(data["fromDate"] as Timestamp).toDate().hour < 10 ? "0${(data["fromDate"] as Timestamp).toDate().hour}" : (data["fromDate"] as Timestamp).toDate().hour}:${(data["fromDate"] as Timestamp).toDate().minute < 10 ? "0${(data["fromDate"] as Timestamp).toDate().minute}" : (data["fromDate"] as Timestamp).toDate().minute}"),
|
||||
const SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Text(
|
||||
" - ${data["language"]["jazyk"]}")
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
return const LoadingWidget();
|
||||
},
|
||||
),
|
||||
),
|
||||
if (Device.screenType == ScreenType.mobile)
|
||||
const SizedBox(
|
||||
height: 50,
|
||||
),
|
||||
SizedBox(
|
||||
width: 45.w,
|
||||
child: Column(
|
||||
children: [
|
||||
DeviceContainer(
|
||||
mainAxisAlignmentDesktop:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
const Text("Řazení:"),
|
||||
DropdownButton(
|
||||
items: const [
|
||||
DropdownMenuItem<int>(
|
||||
value: 0,
|
||||
child: Text(
|
||||
"Vzestupně dle času"),
|
||||
),
|
||||
DropdownMenuItem<int>(
|
||||
value: 1,
|
||||
child:
|
||||
Text("Sestupně dle času"),
|
||||
),
|
||||
DropdownMenuItem<int>(
|
||||
value: 2,
|
||||
child: Text(
|
||||
"Vzestupně dle hodnocení"),
|
||||
),
|
||||
DropdownMenuItem<int>(
|
||||
value: 3,
|
||||
child: Text(
|
||||
"Sestupně dle hodnocení"),
|
||||
),
|
||||
],
|
||||
value: vybraneRazeni,
|
||||
onChanged: (v) {
|
||||
if (v == null) return;
|
||||
|
||||
vybraneRazeni = v;
|
||||
setState(() {});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
if (Device.screenType !=
|
||||
ScreenType.mobile)
|
||||
Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment
|
||||
.spaceEvenly,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(
|
||||
() {
|
||||
if (mesic.position -
|
||||
1 !=
|
||||
-1) {
|
||||
mesic = months[
|
||||
mesic.position -
|
||||
1];
|
||||
} else {
|
||||
mesic = months[11];
|
||||
year--;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.arrow_back,
|
||||
color: Vzhled.purple),
|
||||
),
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"${mesic.name} $year",
|
||||
style: Vzhled.velkyText,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
if (mesic.position +
|
||||
1 !=
|
||||
12) {
|
||||
mesic = months[
|
||||
mesic.position +
|
||||
1];
|
||||
} else {
|
||||
mesic = months[0];
|
||||
year++;
|
||||
}
|
||||
});
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.arrow_forward,
|
||||
color: Vzhled.purple),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
calendarView()
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
if (Device.screenType == ScreenType.mobile)
|
||||
Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(
|
||||
() {
|
||||
if (mesic.position - 1 !=
|
||||
-1) {
|
||||
mesic = months[
|
||||
mesic.position - 1];
|
||||
} else {
|
||||
mesic = months[11];
|
||||
year--;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back,
|
||||
color: Vzhled.purple),
|
||||
),
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"${mesic.name} $year",
|
||||
style: Vzhled.velkyText,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
if (mesic.position + 1 !=
|
||||
12) {
|
||||
mesic = months[
|
||||
mesic.position + 1];
|
||||
} else {
|
||||
mesic = months[0];
|
||||
year++;
|
||||
}
|
||||
});
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.arrow_forward,
|
||||
color: Vzhled.purple),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
calendarView()
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget calendarView() {
|
||||
int day = 1;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(
|
||||
((mesic.days / 7) == 4
|
||||
? (Device.screenType == ScreenType.mobile)
|
||||
? 10
|
||||
: 4
|
||||
: (Device.screenType == ScreenType.mobile)
|
||||
? 11
|
||||
: 5),
|
||||
(index) {
|
||||
return Row(
|
||||
mainAxisAlignment: (Device.screenType == ScreenType.mobile)
|
||||
? MainAxisAlignment.center
|
||||
: MainAxisAlignment.start,
|
||||
children: List.generate(
|
||||
(Device.screenType == ScreenType.mobile) ? 3 : 7,
|
||||
(index) {
|
||||
int thisDay = day++;
|
||||
|
||||
if (thisDay > mesic.days) {
|
||||
return const SizedBox();
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: OutlinedButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
selectedDay = thisDay;
|
||||
});
|
||||
},
|
||||
style: OutlinedButton.styleFrom(
|
||||
textStyle: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: (selectedDay == thisDay)
|
||||
? Vzhled.purple
|
||||
: Colors.black.withOpacity(0),
|
||||
foregroundColor: (selectedDay == thisDay)
|
||||
? Vzhled.backgroundColor
|
||||
: Vzhled.textColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(30.0),
|
||||
),
|
||||
side: BorderSide(
|
||||
color: (selectedDay != thisDay)
|
||||
? Vzhled.purple
|
||||
: Colors.black.withOpacity(0))),
|
||||
child: Text(thisDay.toString()),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
306
lib/okna/settings.dart
Normal file
306
lib/okna/settings.dart
Normal file
|
@ -0,0 +1,306 @@
|
|||
import 'package:denikprogramatora/okna/app.dart';
|
||||
import 'package:denikprogramatora/okna/signin_page.dart';
|
||||
import 'package:denikprogramatora/utils/devicecontainer.dart';
|
||||
import 'package:denikprogramatora/utils/loading_widget.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:responsive_sizer/responsive_sizer.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
import '../utils/my_container.dart';
|
||||
import '../utils/new_record_dialog.dart';
|
||||
import '../utils/vzhled.dart';
|
||||
import 'all_records.dart';
|
||||
|
||||
/*
|
||||
Copyright (C) 2022 Matyáš Caras a Richard Pavlikán
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class NastaveniOkno extends StatefulWidget {
|
||||
const NastaveniOkno({super.key});
|
||||
|
||||
@override
|
||||
State<NastaveniOkno> createState() => _NastaveniOknoState();
|
||||
}
|
||||
|
||||
class _NastaveniOknoState extends State<NastaveniOkno> {
|
||||
var _loading = true;
|
||||
var name = "error";
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (FirebaseAuth.instance.currentUser == null) {
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => const SignInPage()),
|
||||
(route) => false);
|
||||
return;
|
||||
}
|
||||
name = FirebaseAuth.instance.currentUser!.displayName!;
|
||||
|
||||
setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 90.w,
|
||||
height: 100.h,
|
||||
child: (_loading)
|
||||
? const LoadingWidget()
|
||||
: Column(children: [
|
||||
DeviceContainer(
|
||||
mainAxisAlignmentDesktop: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MyContainer(
|
||||
width: (Device.screenType == ScreenType.mobile)
|
||||
? 90.w
|
||||
: 35.w,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
if (name != "error") Text("Ahoj $name"),
|
||||
TextButton(
|
||||
onPressed: () => showAboutDialog(
|
||||
context: context,
|
||||
applicationName: "Kodelog",
|
||||
applicationVersion: "1.1.0",
|
||||
applicationLegalese:
|
||||
"©️ 2023 Matyáš Caras a Richard Pavlikán,\n vydáno pod licencí AGPLv3",
|
||||
children: [
|
||||
TextButton(
|
||||
child: const Text("Zdrojový kód"),
|
||||
onPressed: () => launchUrlString(
|
||||
"https://github.com/Royal-Buccaneers/kodelog"),
|
||||
)
|
||||
]),
|
||||
child: const Text(
|
||||
"Licence",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await FirebaseAuth.instance.signOut();
|
||||
if (!mounted) return;
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (c) => const SignInPage()),
|
||||
(route) => false);
|
||||
},
|
||||
child: const Text(
|
||||
"Odhlásit se",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
MyContainer(
|
||||
width: (Device.screenType == ScreenType.mobile)
|
||||
? 90.w
|
||||
: 40.w,
|
||||
child: DeviceContainer(
|
||||
mainAxisAlignmentDesktop:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context)
|
||||
.pushReplacement(MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const HlavniOkno())),
|
||||
child: const Text(
|
||||
"Denní přehled",
|
||||
style: TextStyle(color: Vzhled.textColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const AllRecordsPage()));
|
||||
},
|
||||
child: const Text(
|
||||
"Všechny\nzáznamy",
|
||||
style: TextStyle(color: Vzhled.textColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
"Nastavení",
|
||||
style: TextStyle(
|
||||
color: Vzhled.textColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
OutlinedButton(
|
||||
onPressed: () => showCreateItemDialog(context),
|
||||
style: Vzhled.orangeCudlik,
|
||||
child: const Text(
|
||||
"Přidat záznam",
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(
|
||||
child: MyContainer(
|
||||
width: 90.w,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(
|
||||
10,
|
||||
),
|
||||
),
|
||||
color: Vzhled.purple,
|
||||
),
|
||||
width: 400,
|
||||
child: InkWell(
|
||||
onTap: () => showProgrammersDialog(context,
|
||||
jenMenit: true),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Text(
|
||||
"Upravit programátory",
|
||||
style: Vzhled.nadpis,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(
|
||||
10,
|
||||
),
|
||||
),
|
||||
color: Vzhled.purple),
|
||||
width: 400,
|
||||
child: InkWell(
|
||||
onTap: () => showCategoriesDialog(context, [],
|
||||
jenMenit: true),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Text(
|
||||
"Upravit kategorie",
|
||||
style: Vzhled.nadpis,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(
|
||||
10,
|
||||
),
|
||||
),
|
||||
color: Vzhled.purple),
|
||||
width: 400,
|
||||
child: InkWell(
|
||||
onTap: () => showEditJazyk(),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Text(
|
||||
"Oblíbený jazyk",
|
||||
style: Vzhled.nadpis,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
))
|
||||
]),
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
showEditJazyk() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
title: const Text("Oblíbený jazyk", style: Vzhled.velkyText),
|
||||
scrollable: true,
|
||||
content: SizedBox(
|
||||
width: 20.w,
|
||||
child: StreamBuilder(
|
||||
stream: ref.snapshots(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return DropdownButton(
|
||||
value: snapshot.data!.data()!["favourite"],
|
||||
dropdownColor: Vzhled.backgroundColor,
|
||||
items: jazyky
|
||||
.map(
|
||||
(e) => DropdownMenuItem(
|
||||
value: e["jazyk"],
|
||||
child: SizedBox(
|
||||
width: 17.w, child: Text(e["jazyk"])),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
ref.update({"favourite": value!});
|
||||
});
|
||||
}
|
||||
return const LoadingWidget();
|
||||
}),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
436
lib/okna/signin_page.dart
Normal file
436
lib/okna/signin_page.dart
Normal file
|
@ -0,0 +1,436 @@
|
|||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:denikprogramatora/okna/app.dart';
|
||||
import 'package:denikprogramatora/utils/loading_widget.dart';
|
||||
import 'package:denikprogramatora/utils/my_container.dart';
|
||||
import 'package:denikprogramatora/utils/vzhled.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:responsive_sizer/responsive_sizer.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
/*
|
||||
Copyright (C) 2022 Matyáš Caras a Richard Pavlikán
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class SignInPage extends StatefulWidget {
|
||||
const SignInPage({super.key});
|
||||
|
||||
@override
|
||||
State<SignInPage> createState() => _SignInPageState();
|
||||
}
|
||||
|
||||
class _SignInPageState extends State<SignInPage> {
|
||||
bool showSignIn = true;
|
||||
bool isLoading = true;
|
||||
|
||||
TextEditingController emailCon = TextEditingController();
|
||||
TextEditingController passwordCon = TextEditingController();
|
||||
TextEditingController nameCon = TextEditingController();
|
||||
|
||||
String jazyk = "C#";
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
if (FirebaseAuth.instance.currentUser != null) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => const HlavniOkno()),
|
||||
);
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: isLoading
|
||||
? const LoadingWidget()
|
||||
: Stack(
|
||||
children: [
|
||||
Center(
|
||||
child: showSignIn ? signInWidget() : registerWidget(),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 10,
|
||||
left: 10,
|
||||
child: TextButton(
|
||||
onPressed: () => showAboutDialog(
|
||||
context: context,
|
||||
applicationName: "Kodelog",
|
||||
applicationVersion: "1.1.0",
|
||||
applicationLegalese:
|
||||
"©️ 2023 Matyáš Caras a Richard Pavlikán,\n vydáno pod licencí AGPLv3",
|
||||
children: [
|
||||
TextButton(
|
||||
child: const Text("Zdrojový kód"),
|
||||
onPressed: () => launchUrlString(
|
||||
"https://github.com/Royal-Buccaneers/kodelog"),
|
||||
)
|
||||
]),
|
||||
child: const Text(
|
||||
"Licence",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget signInWidget() {
|
||||
GlobalKey<FormState> form = GlobalKey<FormState>();
|
||||
return MyContainer(
|
||||
height: 70.h,
|
||||
width: (Device.screenType == ScreenType.mobile) ? 80.w : 40.w,
|
||||
child: Form(
|
||||
key: form,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Kodelog",
|
||||
style: TextStyle(fontSize: 20.sp, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
SizedBox(
|
||||
width: (Device.screenType == ScreenType.mobile) ? 60.w : 30.w,
|
||||
child: TextFormField(
|
||||
decoration: Vzhled.inputDecoration("E-mail"),
|
||||
cursorColor: Vzhled.textColor,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autocorrect: false,
|
||||
controller: emailCon,
|
||||
onFieldSubmitted: (_) {
|
||||
if (form.currentState!.validate()) {
|
||||
signIn();
|
||||
}
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.trim().isEmpty) {
|
||||
return "Toto pole je povinné!";
|
||||
} else if (!RegExp(r'[\w\.]+@[a-z0-9]+\.[a-z]{1,3}')
|
||||
.hasMatch(value)) {
|
||||
return "Neplatný e-mail!";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
SizedBox(
|
||||
width: (Device.screenType == ScreenType.mobile) ? 60.w : 30.w,
|
||||
child: TextFormField(
|
||||
decoration: Vzhled.inputDecoration("Heslo"),
|
||||
cursorColor: Vzhled.textColor,
|
||||
autocorrect: false,
|
||||
obscureText: true,
|
||||
controller: passwordCon,
|
||||
onFieldSubmitted: (_) {
|
||||
if (form.currentState!.validate()) {
|
||||
signIn();
|
||||
}
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.trim().isEmpty) {
|
||||
return "Toto pole je povinné!";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
OutlinedButton(
|
||||
style: Vzhled.orangeCudlik,
|
||||
onPressed: () {
|
||||
if (form.currentState!.validate()) {
|
||||
signIn();
|
||||
}
|
||||
},
|
||||
child: const Text("Přihlásit se"),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
const Text("nebo"),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showSignIn = false;
|
||||
});
|
||||
},
|
||||
child: const Text("Registrovat se", style: Vzhled.textBtn),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget registerWidget() {
|
||||
GlobalKey<FormState> form = GlobalKey<FormState>();
|
||||
return MyContainer(
|
||||
width: (Device.screenType == ScreenType.mobile) ? 80.w : 40.w,
|
||||
child: Form(
|
||||
key: form,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Kodelog",
|
||||
style: TextStyle(fontSize: 20.sp, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
SizedBox(
|
||||
width: (Device.screenType == ScreenType.mobile) ? 60.w : 30.w,
|
||||
child: TextFormField(
|
||||
decoration: Vzhled.inputDecoration("Jméno"),
|
||||
cursorColor: Vzhled.textColor,
|
||||
controller: nameCon,
|
||||
onFieldSubmitted: (_) {
|
||||
if (form.currentState!.validate()) {
|
||||
signUp();
|
||||
}
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.trim().isEmpty) {
|
||||
return "Toto pole je povinné!";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
SizedBox(
|
||||
width: (Device.screenType == ScreenType.mobile) ? 60.w : 30.w,
|
||||
child: TextFormField(
|
||||
decoration: Vzhled.inputDecoration("E-mail"),
|
||||
cursorColor: Vzhled.textColor,
|
||||
controller: emailCon,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autocorrect: false,
|
||||
onFieldSubmitted: (_) {
|
||||
if (form.currentState!.validate()) {
|
||||
signUp();
|
||||
}
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.trim().isEmpty) {
|
||||
return "Toto pole je povinné!";
|
||||
} else if (!RegExp(r'[\w\.]+@[a-z0-9]+\.[a-z]{1,3}')
|
||||
.hasMatch(value)) {
|
||||
return "Neplatný e-mail!";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
SizedBox(
|
||||
width: (Device.screenType == ScreenType.mobile) ? 60.w : 30.w,
|
||||
child: TextFormField(
|
||||
decoration: Vzhled.inputDecoration("Heslo"),
|
||||
cursorColor: Vzhled.textColor,
|
||||
obscureText: true,
|
||||
controller: passwordCon,
|
||||
onFieldSubmitted: (_) {
|
||||
if (form.currentState!.validate()) {
|
||||
signUp();
|
||||
}
|
||||
},
|
||||
validator: (value) {
|
||||
if (value!.trim().isEmpty) {
|
||||
return "Toto pole je povinné!";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
"Oblíbený jazyk:",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
DropdownButton(
|
||||
value: jazyk,
|
||||
dropdownColor: Vzhled.backgroundColor,
|
||||
items: jazyky
|
||||
.map(
|
||||
(e) => DropdownMenuItem(
|
||||
value: e["jazyk"],
|
||||
child: Text(e["jazyk"]),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
jazyk = (value as String?)!;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
OutlinedButton(
|
||||
style: Vzhled.orangeCudlik,
|
||||
onPressed: () async {
|
||||
if (form.currentState!.validate()) {
|
||||
signUp();
|
||||
}
|
||||
},
|
||||
child: const Text("Registrovat se"),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
const Text("nebo"),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showSignIn = true;
|
||||
});
|
||||
},
|
||||
child: const Text("Přihlásit se", style: Vzhled.textBtn),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void signIn() {
|
||||
FirebaseAuth.instance
|
||||
.signInWithEmailAndPassword(
|
||||
email: emailCon.text, password: passwordCon.text)
|
||||
.then(
|
||||
(value) => Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => const HlavniOkno()),
|
||||
),
|
||||
)
|
||||
.onError((e, st) {
|
||||
if (e.toString().contains("firebase_auth/user-not-found")) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const AlertDialog(
|
||||
title: Text("Chyba"),
|
||||
content: Text("Váš účet neexistuje"),
|
||||
),
|
||||
);
|
||||
} else if (e.toString().contains("firebase_auth/wrong-password")) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const AlertDialog(
|
||||
title: Text("Chyba"),
|
||||
content: Text("Zadáváte špatné heslo!"),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const AlertDialog(
|
||||
title: Text("Chyba"),
|
||||
content: Text("Nastala neznámá chyba."),
|
||||
),
|
||||
);
|
||||
debugPrint(e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void signUp() {
|
||||
FirebaseAuth.instance
|
||||
.createUserWithEmailAndPassword(
|
||||
email: emailCon.text, password: passwordCon.text)
|
||||
.then(
|
||||
(value) async {
|
||||
await FirebaseFirestore.instance
|
||||
.collection("users")
|
||||
.doc(FirebaseAuth.instance.currentUser!.uid)
|
||||
.set({
|
||||
"name": nameCon.text,
|
||||
"email": emailCon.text,
|
||||
"favourite": jazyk,
|
||||
});
|
||||
value.user?.updateDisplayName(nameCon.text);
|
||||
|
||||
if (!mounted) return;
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => const HlavniOkno()),
|
||||
);
|
||||
},
|
||||
).onError((error, stackTrace) {
|
||||
if (error.toString().contains("firebase_auth/email-already-in-use")) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const AlertDialog(
|
||||
title: Text("Chyba"),
|
||||
content: Text("E-mail je již zaregistrovaný"),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const AlertDialog(
|
||||
title: Text("Chyba"),
|
||||
content: Text("Nastala neznámá chyba."),
|
||||
),
|
||||
);
|
||||
debugPrint(error.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue