Skip to content

Commit

Permalink
refactor structure of code
Browse files Browse the repository at this point in the history
  • Loading branch information
pbarbenheim committed Jan 8, 2025
1 parent 0690f61 commit 26002d4
Show file tree
Hide file tree
Showing 16 changed files with 1,155 additions and 1,109 deletions.
5 changes: 3 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'dart:io';
import 'dart:ui';

import 'package:julog/repository/repository.dart';
import 'package:julog/ui/routes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:path/path.dart' as path;
import 'package:window_size/window_size.dart';

import 'repository/repository.dart';
import 'ui/routes.dart';

void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();

Expand Down
5 changes: 3 additions & 2 deletions lib/pdf/pdf.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:julog/pubspec.g.dart';
import 'package:julog/repository/repository.dart';
import 'package:flutter/services.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';

import '../pubspec.g.dart';
import '../repository/repository.dart';

extension EintragPdfGeneration on Eintrag {
Future<Uint8List> buildPdf(PdfPageFormat format) async {
final doc = pw.Document();
Expand Down
19 changes: 10 additions & 9 deletions lib/ui/routes.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'package:julog/repository/repository.dart';
import 'package:julog/ui/frame.dart';
import 'package:julog/ui/screens/betreuer.dart';
import 'package:julog/ui/screens/dashboard.dart';
import 'package:julog/ui/screens/dienstbuch.dart';
import 'package:julog/ui/screens/identities.dart';
import 'package:julog/ui/screens/jugendliche.dart';
import 'package:julog/ui/screens/kategorien.dart';
import 'package:julog/ui/screens/select_file.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

import '../repository/repository.dart';
import 'frame.dart';
import 'screens/betreuer.dart';
import 'screens/dashboard.dart';
import 'screens/dienstbuch.dart';
import 'screens/identities.dart';
import 'screens/jugendliche.dart';
import 'screens/kategorien.dart';
import 'screens/select_file.dart';

part 'routes.g.dart';

abstract class JulogBaseRoute extends GoRouteData {
Expand Down
101 changes: 5 additions & 96 deletions lib/ui/screens/betreuer.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:julog/repository/repository.dart';
import 'package:julog/ui/frame.dart';
import 'package:julog/ui/routes.dart';
import 'package:julog/ui/util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../repository/repository.dart';
import '../frame.dart';
import '../routes.dart';
import '../widgets/betreuer.dart';

class BetreuerScreen extends ConsumerWidget {
final int? selectedId;
const BetreuerScreen({super.key, this.selectedId});
Expand Down Expand Up @@ -46,23 +47,6 @@ class BetreuerScreen extends ConsumerWidget {
}
}

class BetreuerItem extends Item {
final String name;
final int id;
final Geschlecht geschlecht;
const BetreuerItem({
required this.geschlecht,
super.key,
required this.name,
required this.id,
}) : super(title: name);

@override
Widget build(BuildContext context) {
return Text("$name ($geschlecht, $id)");
}
}

class AddBetreuerScreen extends StatelessWidget {
const AddBetreuerScreen({super.key});

Expand All @@ -77,78 +61,3 @@ class AddBetreuerScreen extends StatelessWidget {
);
}
}

class AddBetreuerForm extends ConsumerStatefulWidget {
const AddBetreuerForm({super.key});

@override
ConsumerState<ConsumerStatefulWidget> createState() =>
_AddBetreuerFormState();
}

class _AddBetreuerFormState extends ConsumerState<AddBetreuerForm> {
late final TextEditingController _nameController;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
Geschlecht? _geschlecht;

@override
void initState() {
_nameController = TextEditingController();
super.initState();
}

@override
void dispose() {
_nameController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
children: [
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
labelText: "Name",
hintText: "Name des Betreuers",
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return "Der Name darf nicht leer sein";
}
if (!Repository.checkString(value)) {
return "Der Name enthält verbotene Zeichen";
}
return null;
},
),
const Padding(padding: EdgeInsets.only(top: 10)),
GeschlechtDropDown(
onChanged: (value) {
setState(() {
_geschlecht = value;
});
},
value: _geschlecht,
),
const Padding(padding: EdgeInsets.only(top: 10)),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
final betreuer = ref
.read(repositoryProvider)!
.addBetreuer(_nameController.text, _geschlecht!);
BetreuerRoute(betreuer.id).go(context);
}
},
child: const Text("Erstellen"),
),
],
),
);
}
}
7 changes: 4 additions & 3 deletions lib/ui/screens/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:julog/repository/repository.dart';
import 'package:julog/ui/frame.dart';
import 'package:julog/ui/util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../repository/repository.dart';
import '../frame.dart';
import '../widgets/util.dart';

class DashboardScreen extends ConsumerWidget {
const DashboardScreen({super.key});

Expand Down
Loading

0 comments on commit 26002d4

Please sign in to comment.