Refactor codebase resolving warnings and remove self-package imports
This commit is contained in:
59
lib/view/pages/more/countdown/addTimerDialog.dart
Normal file
59
lib/view/pages/more/countdown/addTimerDialog.dart
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AddTimerDialog extends StatefulWidget {
|
||||
const AddTimerDialog({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AddTimerDialog> createState() => _AddTimerDialogState();
|
||||
}
|
||||
|
||||
class _AddTimerDialogState extends State<AddTimerDialog> {
|
||||
DateTime selected = DateTime.now().add(const Duration(days: 1));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Timer hinzufügen"),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Timer Name"
|
||||
),
|
||||
),
|
||||
|
||||
TextButton(onPressed: () async {
|
||||
DateTime? selectedDate = await showDatePicker(context: context, initialDate: DateTime.now(), firstDate: DateTime.now(), lastDate: DateTime.now().add(const Duration(days: 365 * 10)));
|
||||
if(selectedDate == null) return;
|
||||
|
||||
setState(() {
|
||||
selected = selectedDate;
|
||||
});
|
||||
|
||||
}, child: const Text("Datum auswählen")),
|
||||
|
||||
TextButton(onPressed: () async {
|
||||
TimeOfDay? selectedTime = await showTimePicker(context: context, initialTime: TimeOfDay.fromDateTime(DateTime.now()));
|
||||
if(selectedTime == null) return;
|
||||
|
||||
setState(() {
|
||||
selected = selected.copyWith(hour: selectedTime.hour, minute: selectedTime.minute);
|
||||
});
|
||||
}, child: const Text("Zeit auswählen")),
|
||||
|
||||
Text(selected.toString())
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Abbrechen")),
|
||||
TextButton(onPressed: () {
|
||||
// TODO add timer
|
||||
}, child: const Text("Hinzufügen")),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
53
lib/view/pages/more/countdown/animatedTime.dart
Normal file
53
lib/view/pages/more/countdown/animatedTime.dart
Normal file
@ -0,0 +1,53 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:animated_digit/animated_digit.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class AnimatedTime extends StatefulWidget {
|
||||
final Duration Function() callback;
|
||||
const AnimatedTime({Key? key, required this.callback}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AnimatedTime> createState() => _AnimatedTimeState();
|
||||
}
|
||||
|
||||
class _AnimatedTimeState extends State<AnimatedTime> {
|
||||
Duration current = Duration.zero;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Timer.periodic(const Duration(seconds: 1), (Timer t) => update());
|
||||
}
|
||||
|
||||
void update() {
|
||||
setState(() {
|
||||
current = widget.callback();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
const Text("Noch "),
|
||||
buildWidget(current.inDays),
|
||||
const Text(" Tage, "),
|
||||
buildWidget(current.inHours > 24 ? current.inHours - current.inDays * 24 : current.inHours),
|
||||
const Text(":"),
|
||||
buildWidget(current.inMinutes > 60 ? current.inMinutes - current.inHours * 60 : current.inMinutes),
|
||||
const Text(":"),
|
||||
buildWidget(current.inSeconds > 60 ? current.inSeconds - current.inMinutes * 60 : current.inSeconds),
|
||||
const Text(""),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
AnimatedDigitWidget buildWidget(int value) {
|
||||
return AnimatedDigitWidget(
|
||||
value: value,
|
||||
duration: const Duration(milliseconds: 100),
|
||||
textStyle: const TextStyle(fontSize: 15),
|
||||
);
|
||||
}
|
||||
}
|
56
lib/view/pages/more/countdown/countdown.dart
Normal file
56
lib/view/pages/more/countdown/countdown.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'addTimerDialog.dart';
|
||||
import 'timer.dart';
|
||||
|
||||
class Countdown extends StatefulWidget {
|
||||
const Countdown({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Countdown> createState() => _CountdownState();
|
||||
}
|
||||
|
||||
class _CountdownState extends State<Countdown> {
|
||||
List<Timer> timers = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
timers.add(Timer(key: const Key("1"), target: DateTime.now().add(const Duration(seconds: 20)), label: "Countdown 1"));
|
||||
timers.add(Timer(key: const Key("2"), author: "goldbaja", target: DateTime.now().add(const Duration(days: 20)), label: "Sommerferien"));
|
||||
timers.add(Timer(key: const Key("3"), target: DateTime.now().add(const Duration(hours: 20)), label: "Joa"));
|
||||
|
||||
timers.sort((a, b) => a.target.compareTo(b.target));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Countdown"),
|
||||
actions: [
|
||||
IconButton(onPressed: () {
|
||||
showDialog(context: context, builder: (context) => const AddTimerDialog());
|
||||
}, icon: const Icon(Icons.add)),
|
||||
],
|
||||
),
|
||||
body: ReorderableListView(
|
||||
shrinkWrap: true,
|
||||
footer: Container(
|
||||
padding: const EdgeInsets.only(top: 30),
|
||||
child: Center(
|
||||
child: Text("Halte und Ziehe ein Element um es umzusortieren.", style: TextStyle(color: Theme.of(context).disabledColor)),
|
||||
),
|
||||
),
|
||||
onReorder: (int oldIndex, int newIndex) { },
|
||||
children: timers,
|
||||
|
||||
),
|
||||
// body: ListView.separated(
|
||||
// itemBuilder: (context, index) => timers[index],
|
||||
// separatorBuilder: (context, index) => const Divider(),
|
||||
// itemCount: timers.length
|
||||
// )
|
||||
);
|
||||
}
|
||||
}
|
54
lib/view/pages/more/countdown/timer.dart
Normal file
54
lib/view/pages/more/countdown/timer.dart
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'animatedTime.dart';
|
||||
|
||||
class Timer extends StatefulWidget {
|
||||
final DateTime target;
|
||||
final String? author;
|
||||
final String label;
|
||||
const Timer({Key? key, required this.target, this.author, required this.label}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Timer> createState() => _TimerState();
|
||||
}
|
||||
|
||||
class _TimerState extends State<Timer> {
|
||||
late bool isLocal;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
isLocal = widget.author == null;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.timer),
|
||||
title: AnimatedTime(
|
||||
callback: () {
|
||||
if(widget.target.isBefore(DateTime.now())) return Duration.zero;
|
||||
return widget.target.difference(DateTime.now());
|
||||
},
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if(!isLocal) Row(
|
||||
children: [
|
||||
const Text("5"),
|
||||
IconButton(onPressed: () {
|
||||
|
||||
}, icon: const Icon(Icons.thumb_up_outlined)),
|
||||
],
|
||||
),
|
||||
IconButton(onPressed: () {
|
||||
|
||||
}, icon: const Icon(Icons.star_outline))
|
||||
],
|
||||
),
|
||||
subtitle: Text("${widget.label}${!isLocal ? "\ngeteilt von ${widget.author}" : ""}"),
|
||||
);
|
||||
}
|
||||
}
|
170
lib/view/pages/more/gradeAverages/gradeAverage.dart
Normal file
170
lib/view/pages/more/gradeAverages/gradeAverage.dart
Normal file
@ -0,0 +1,170 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GradeAverage extends StatefulWidget {
|
||||
const GradeAverage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<GradeAverage> createState() => _GradeAverageState();
|
||||
}
|
||||
|
||||
class _GradeAverageState extends State<GradeAverage> {
|
||||
double average = 0;
|
||||
bool gradeSystem = true;
|
||||
List<int> grades = List.empty(growable: true);
|
||||
|
||||
String getGradeDisplay(int grade) {
|
||||
if(gradeSystem) {
|
||||
return "Note $grade";
|
||||
} else {
|
||||
return "$grade Punkt${grade > 1 ? "e" : ""}";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if(grades.isNotEmpty) {
|
||||
average = grades.reduce((a, b) => a + b) / grades.length;
|
||||
} else {
|
||||
average = 0;
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Notendurschnittsrechner"),
|
||||
actions: [
|
||||
IconButton(onPressed: () {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Zurücksetzen?"),
|
||||
content: const Text("Alle Einträge werden entfernt."),
|
||||
actions: [
|
||||
TextButton(onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Abbrechen")),
|
||||
TextButton(onPressed: () {
|
||||
grades.clear();
|
||||
setState(() {});
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Zurücksetzen"))
|
||||
],
|
||||
);
|
||||
});
|
||||
}, icon: const Icon(Icons.delete_forever)),
|
||||
PopupMenuButton<bool>(
|
||||
enableFeedback: true,
|
||||
initialValue: gradeSystem,
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
itemBuilder: (context) => [true, false].map((e) => PopupMenuItem<bool>(
|
||||
value: e,
|
||||
enabled: e != gradeSystem,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(e ? "Notensystem" : "Punktesystem"),
|
||||
],
|
||||
),
|
||||
)).toList(),
|
||||
|
||||
onSelected: (e) {
|
||||
void switchSystem() => setState(() {
|
||||
grades.clear();
|
||||
gradeSystem = e;
|
||||
});
|
||||
|
||||
if(grades.isNotEmpty) {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Notensystem wechseln"),
|
||||
content: const Text("Beim wechsel des Notensystems werden alle Einträge zurückgesetzt."),
|
||||
actions: [
|
||||
TextButton(onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Abbrechen")),
|
||||
TextButton(onPressed: () {
|
||||
switchSystem();
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Fortfahren")),
|
||||
],
|
||||
);
|
||||
});
|
||||
} else {
|
||||
switchSystem();
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 30),
|
||||
Text(average.toStringAsFixed(2), style: const TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 10),
|
||||
const Divider(),
|
||||
const SizedBox(height: 10),
|
||||
Text(gradeSystem ? "Wähle unten die Anzahl deiner jewiligen Noten aus" : "Wähle unten die Anzahl deiner jeweiligen Punkte aus"),
|
||||
const SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
var grade = gradeSystem ? index + 1 : 14 - index + 1;
|
||||
bool isThis(int e) => e == grade;
|
||||
return Material(
|
||||
child: ListTile(
|
||||
tileColor: grade.isEven ? Colors.transparent : Colors.transparent.withAlpha(50),
|
||||
title: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(getGradeDisplay(grade)),
|
||||
const SizedBox(width: 30),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
if(!grades.any(isThis)) return;
|
||||
grades.removeAt(grades.indexWhere(isThis));
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.remove),
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
Text("${grades.where(isThis).length}", style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold)),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
grades.add(grade);
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
trailing: Visibility(
|
||||
maintainState: true,
|
||||
maintainAnimation: true,
|
||||
maintainSize: true,
|
||||
visible: grades.any(isThis),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
grades.removeWhere(isThis);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: gradeSystem ? 6 : 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
62
lib/view/pages/more/message/message.dart
Normal file
62
lib/view/pages/more/message/message.dart
Normal file
@ -0,0 +1,62 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../../api/mhsl/message/getMessages/getMessagesResponse.dart';
|
||||
import '../../../../model/message/messageProps.dart';
|
||||
import 'messageView.dart';
|
||||
|
||||
|
||||
class Message extends StatefulWidget {
|
||||
const Message({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Message> createState() => _MessageState();
|
||||
}
|
||||
|
||||
class _MessageState extends State<Message> {
|
||||
@override
|
||||
void initState() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<MessageProps>(context, listen: false).run();
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Marianum Message"),
|
||||
),
|
||||
body: Consumer<MessageProps>(builder: (context, value, child) {
|
||||
if(value.primaryLoading()) return const Center(child: CircularProgressIndicator());
|
||||
|
||||
return RefreshIndicator(
|
||||
child: ListView.builder(
|
||||
itemCount: value.getMessagesResponse.messages.length,
|
||||
itemBuilder: (context, index) {
|
||||
GetMessagesResponseObject message = value.getMessagesResponse.messages.toList()[index];
|
||||
return ListTile(
|
||||
leading: const Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [Icon(Icons.newspaper)],
|
||||
),
|
||||
title: Text(message.name, overflow: TextOverflow.ellipsis),
|
||||
subtitle: Text("vom ${message.date}"),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => MessageView(basePath: value.getMessagesResponse.base, message: message)));
|
||||
},
|
||||
);
|
||||
}
|
||||
),
|
||||
onRefresh: () {
|
||||
Provider.of<MessageProps>(context, listen: false).run(renew: true);
|
||||
return Future.delayed(const Duration(seconds: 3));
|
||||
},
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
63
lib/view/pages/more/message/messageView.dart
Normal file
63
lib/view/pages/more/message/messageView.dart
Normal file
@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../../../api/mhsl/message/getMessages/getMessagesResponse.dart';
|
||||
|
||||
class MessageView extends StatefulWidget {
|
||||
final String basePath;
|
||||
final GetMessagesResponseObject message;
|
||||
const MessageView({Key? key, required this.basePath, required this.message}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MessageView> createState() => _MessageViewState();
|
||||
}
|
||||
|
||||
class _MessageViewState extends State<MessageView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.message.name),
|
||||
),
|
||||
body: SfPdfViewer.network(
|
||||
widget.basePath + widget.message.url,
|
||||
enableHyperlinkNavigation: true,
|
||||
onDocumentLoadFailed: (PdfDocumentLoadFailedDetails e) {
|
||||
Navigator.of(context).pop();
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Fehler beim öffnen"),
|
||||
content: Text("Dokument '${widget.message.name}' konnte nicht geladen werden:\n${e.description}"),
|
||||
actions: [
|
||||
TextButton(onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Ok"))
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
onHyperlinkClicked: (PdfHyperlinkClickedDetails e) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Link öffnen"),
|
||||
content: Text("Möchtest du den folgenden Link öffnen?\n${e.uri}"),
|
||||
actions: [
|
||||
TextButton(onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}, child: const Text("Abbrechen")),
|
||||
TextButton(onPressed: () {
|
||||
launchUrl(Uri.parse(e.uri), mode: LaunchMode.externalApplication);
|
||||
}, child: const Text("Öffnen")),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
36
lib/view/pages/more/overhang.dart
Normal file
36
lib/view/pages/more/overhang.dart
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
||||
|
||||
import '../../../widget/ListItem.dart';
|
||||
import '../../settings/settings.dart';
|
||||
import 'countdown/countdown.dart';
|
||||
import 'gradeAverages/gradeAverage.dart';
|
||||
import 'message/message.dart';
|
||||
import 'roomplan/roomplan.dart';
|
||||
|
||||
class Overhang extends StatelessWidget {
|
||||
const Overhang({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Mehr"),
|
||||
actions: [
|
||||
IconButton(onPressed: () => PersistentNavBarNavigator.pushNewScreen(context, screen: const Settings(), withNavBar: false), icon: const Icon(Icons.settings))
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
children: const [
|
||||
ListItemNavigator(icon: Icons.newspaper, text: "Marianum Message", target: Message()),
|
||||
ListItemNavigator(icon: Icons.room, text: "Raumplan", target: Roomplan()),
|
||||
ListItemNavigator(icon: Icons.calculate, text: "Notendurschnitts rechner", target: GradeAverage()),
|
||||
if(!kReleaseMode) ListItemNavigator(icon: Icons.calendar_month, text: "Schulferien", target: Roomplan()),
|
||||
if(!kReleaseMode) ListItemNavigator(icon: Icons.timer, text: "Countdown", target: Countdown()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
23
lib/view/pages/more/roomplan/roomplan.dart
Normal file
23
lib/view/pages/more/roomplan/roomplan.dart
Normal file
@ -0,0 +1,23 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
|
||||
class Roomplan extends StatelessWidget {
|
||||
const Roomplan({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Raumplan"),
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
body: PhotoView(
|
||||
imageProvider: Image.asset("assets/img/raumplan.jpg").image,
|
||||
minScale: 0.5,
|
||||
maxScale: 2.0,
|
||||
backgroundDecoration: const BoxDecoration(color: Colors.white60),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user