added frontend

This commit is contained in:
verboomp
2026-01-21 16:08:09 +01:00
parent d2e6f5164a
commit b3de3eec8c
74 changed files with 4938 additions and 26 deletions

View File

@@ -0,0 +1,55 @@
import 'package:flutter/material.dart';
import 'package:fotodocumentation/l10n/app_localizations.dart';
import 'package:fotodocumentation/controller/base_controller.dart';
class GeneralErrorWidget extends StatelessWidget {
final String error;
final Function()? reload;
final int? statusCode;
const GeneralErrorWidget({super.key, required this.error, this.reload, this.statusCode});
factory GeneralErrorWidget.fromServerError(ServerError serverError, {Function()? reload}) {
return GeneralErrorWidget(error: "", reload: reload, statusCode: serverError.statusCode);
}
factory GeneralErrorWidget.fromSnapshot(AsyncSnapshot snapshot, {Function()? reload}) {
var error = snapshot.error;
if (error is ServerError) {
return GeneralErrorWidget.fromServerError(error, reload: () => reload);
}
return GeneralErrorWidget(error: snapshot.error.toString(), reload: () => reload);
}
@override
Widget build(BuildContext context) {
final localizations = AppLocalizations.of(context)!;
final String errorMessage = statusCode != null
? localizations.errorWidgetStatusCode(statusCode!)
: localizations.errorWidget(error);
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error_outline, size: 60, color: Colors.red[300]),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text(
errorMessage,
style: TextStyle(color: Colors.red[700]),
textAlign: TextAlign.center,
),
),
const SizedBox(height: 16),
if (reload != null) ...[
ElevatedButton(
onPressed: reload,
child: Text(localizations.errorWidgetRetryButton),
),
],
],
),
);
}
}

View File

@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:fotodocumentation/l10n/app_localizations.dart';
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
import 'package:fotodocumentation/utils/di_container.dart';
typedef SubmitCallback = void Function();
class GeneralSubmitWidget extends StatelessWidget {
GeneralStyle get _generalStyle => DiContainer.get();
final SubmitCallback onSelect;
final String? title;
const GeneralSubmitWidget({super.key, required this.onSelect, this.title});
@override
Widget build(BuildContext context) {
String text = title ?? AppLocalizations.of(context)!.submitWidget;
return Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
ElevatedButton(
key: Key("SubmitWidgetButton"),
style: _generalStyle.elevatedButtonStyle,
onPressed: onSelect,
child: Text(text),
),
],
);
}
}

View File

@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
class PageHeaderWidget extends StatelessWidget {
final IconData iconData;
final String text;
final String subText;
final Color? iconColor;
const PageHeaderWidget({super.key, this.iconData = Icons.business, required this.text, this.subText = "", this.iconColor});
@override
Widget build(BuildContext context) {
final color = iconColor ?? Theme.of(context).colorScheme.primary;
return Card(
elevation: 2,
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(
color: Colors.grey[300]!,
width: 1,
),
),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: color.withAlpha(51),
shape: BoxShape.circle,
),
child: Icon(
iconData,
size: 32,
color: color,
),
),
const SizedBox(width: 16),
Text(
text,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
if (subText.isNotEmpty) ...[
const SizedBox(height: 16),
Text(
subText,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.grey[600],
),
),
],
],
),
),
);
}
}

View File

@@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:fotodocumentation/l10n/app_localizations.dart';
class SearchBarCardWidget extends StatefulWidget {
final TextEditingController searchController;
final Function(String) onSearch;
const SearchBarCardWidget({super.key, required this.searchController, required this.onSearch});
@override
State<SearchBarCardWidget> createState() => _SearchBarCardWidgetState();
}
class _SearchBarCardWidgetState extends State<SearchBarCardWidget> {
@override
Widget build(BuildContext context) {
return Card(
elevation: 2,
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(
color: Colors.grey[300]!,
width: 1,
),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: TextField(
key: Key("Search_text_field"),
controller: widget.searchController,
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.searchTFHint,
border: InputBorder.none,
prefixIcon: const Icon(Icons.search, size: 28),
contentPadding: EdgeInsets.zero,
isDense: true,
suffixIcon: InkWell(
key: Key("Search_text_clear_button"),
onTap: () => _actionClear(),
child: const Icon(
Icons.close,
color: Colors.black,
),
)
),
onSubmitted: (_) => _actionSubmit(),
),
),
const SizedBox(width: 8),
ElevatedButton.icon(
key: Key("Search_text_button"),
onPressed: _actionSubmit,
icon: const Icon(Icons.search, size: 18),
label: Text(AppLocalizations.of(context)!.searchButtonLabel),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
],
),
),
);
}
void _actionSubmit() {
widget.onSearch(widget.searchController.text);
}
void _actionClear() {
widget.searchController.text = "";
widget.onSearch(widget.searchController.text);
}
}

View File

@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
import 'package:fotodocumentation/l10n/app_localizations.dart';
import 'package:provider/provider.dart';
class TextInputWidget extends StatelessWidget {
final String labelText;
final bool required;
final bool obscureText;
final bool readOnly;
final Function? onTap;
const TextInputWidget({super.key, required this.labelText, this.required = false, this.obscureText = false, this.readOnly = false, this.onTap});
@override
Widget build(BuildContext context) {
return Consumer<TextEditingController>(builder: (context, controller, child) {
return TextFormField(
readOnly: readOnly,
obscureText: obscureText,
controller: controller,
decoration: InputDecoration(
border: const UnderlineInputBorder(),
labelText: labelText,
),
validator: (String? value) => required && (value == null || value.isEmpty) ? AppLocalizations.of(context)!.textInputWidgetValidatorText : null,
onTap: () => onTap?.call(),
);
});
}
}
class TextMultiInputWidget extends StatelessWidget {
final String labelText;
final bool required;
final bool obscureText;
final bool readOnly;
final Function? onTap;
final int maxLines;
const TextMultiInputWidget({super.key, required this.labelText, this.required = false, this.obscureText = false, this.readOnly = false, this.maxLines = 6, this.onTap});
@override
Widget build(BuildContext context) {
return Consumer<TextEditingController>(builder: (context, controller, child) {
return TextFormField(
readOnly: readOnly,
minLines: 3, // Set this
maxLines: maxLines, // and this
keyboardType: TextInputType.multiline,
obscureText: obscureText,
controller: controller,
decoration: InputDecoration(
border: const UnderlineInputBorder(),
labelText: labelText,
),
validator: (String? value) => required && (value == null || value.isEmpty) ? AppLocalizations.of(context)!.textInputWidgetValidatorText : null,
onTap: () => onTap?.call(),
);
});
}
}

View File

@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:fotodocumentation/l10n/app_localizations.dart';
class WaitingWidget extends StatelessWidget {
const WaitingWidget({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
width: 60,
height: 60,
child: CircularProgressIndicator(),
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text(AppLocalizations.of(context)!.waitingWidget),
),
],
),
);
}
}

View File

@@ -0,0 +1,173 @@
import 'package:flutter/material.dart';
import 'package:fotodocumentation/main.dart' show logger;
import 'package:fotodocumentation/l10n/app_localizations.dart';
import 'package:fotodocumentation/pages/ui_utils/dialog/snackbar_utils.dart';
import 'package:fotodocumentation/utils/di_container.dart';
class DeleteDialog extends StatelessWidget {
static SnackbarUtils get _snackbarUtils => DiContainer.get();
const DeleteDialog({super.key});
static Future<void> show(BuildContext context, Future<DeleteDialogResult> Function() doDelete) async {
await _openDialog(context).then((value) async {
if (value != null && value && context.mounted) {
logger.d("Delete popup result $value");
var result = await doDelete();
if (context.mounted && result.msg.isNotEmpty) {
_snackbarUtils.showSnackbar(context, result.msg, result.warning);
}
}
});
}
static Future<bool?> _openDialog(BuildContext context) async {
return showDialog<bool>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return const DeleteDialog(
key: Key("delete_dialog"),
);
},
);
}
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context)!;
return AlertDialog(
backgroundColor: Colors.white,
scrollable: false,
titlePadding: const EdgeInsets.all(16.0),
contentPadding: const EdgeInsets.fromLTRB(16.0, 0, 16.0, 16.0),
title: _titleWidget(context, loc),
content: _content(context, loc),
);
}
Widget _titleWidget(BuildContext context, AppLocalizations loc) {
return Card(
elevation: 4,
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(
color: Colors.grey[300]!,
width: 1,
),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.warning_amber_rounded,
size: 32,
color: Colors.orange[700],
),
const SizedBox(width: 16),
Text(
loc.deleteDialogTitle,
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
IconButton(
key: const Key("close_button"),
icon: const Icon(Icons.close),
onPressed: () => Navigator.pop(context, false),
),
],
),
),
);
}
Widget _content(BuildContext context, AppLocalizations loc) {
return SizedBox(
width: 400,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
elevation: 2,
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(
color: Colors.grey[300]!,
width: 1,
),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
Icon(
Icons.warning_amber_rounded,
size: 48,
color: Colors.orange[700],
),
const SizedBox(width: 16),
Expanded(
child: Text(
loc.deleteDialogText,
style: Theme.of(context).textTheme.bodyLarge,
),
),
],
),
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
key: const Key("delete_dialog:cancel"),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
onPressed: () => Navigator.pop(context, false),
child: Text(loc.deleteDialogButtonCancel),
),
const SizedBox(width: 8),
ElevatedButton.icon(
key: const Key("delete_dialog:approve"),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
backgroundColor: Colors.red[600],
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
onPressed: () => Navigator.pop(context, true),
icon: const Icon(Icons.delete, size: 20),
label: Text(loc.deleteDialogButtonApprove),
),
],
),
],
),
);
}
}
class DeleteDialogResult {
final String msg;
final bool warning;
DeleteDialogResult({required this.msg, required this.warning});
}

View File

@@ -0,0 +1,11 @@
class DialogResult<T> {
final DialogResultType type;
final T? dto;
const DialogResult({required this.type, this.dto});
}
enum DialogResultType {
create,
add;
}

View File

@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
abstract interface class SnackbarUtils {
void showSnackbar(BuildContext context, String msg, bool warning);
void showSnackbarPopup(BuildContext context, String msg, bool warning);
}
class SnackbarUtilsImpl implements SnackbarUtils {
@override
void showSnackbar(BuildContext context, String msg, bool warning) {
var snackBar = SnackBar(
content: _contentFor(context, msg, warning),
backgroundColor: Colors.white,
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
closeIconColor: Theme.of(context).colorScheme.inversePrimary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(width: 2.0, style: BorderStyle.solid, color: Theme.of(context).colorScheme.inversePrimary),
),
margin: EdgeInsets.only(bottom: MediaQuery.of(context).size.height - 130, left: MediaQuery.of(context).size.width - 400, right: 10),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
@override
void showSnackbarPopup(BuildContext context, String msg, bool warning) {
var snackBar = SnackBar(
content: _contentFor(context, msg, warning),
backgroundColor: Colors.white,
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
closeIconColor: Theme.of(context).colorScheme.inversePrimary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(width: 2.0, style: BorderStyle.solid, color: Theme.of(context).colorScheme.inversePrimary),
),
width: 350,
//margin: EdgeInsets.only(bottom: MediaQuery.of(context).size.height - 100, left: MediaQuery.of(context).size.width - 350, right: 10),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
Widget _contentFor(BuildContext context, String msg, bool warning) {
var icon = _iconFor(context, warning);
var style = _textStyleFor(context, warning);
return Wrap(
alignment: WrapAlignment.start,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
icon,
Text(
msg,
style: style,
),
],
);
}
Icon _iconFor(BuildContext context, bool warning) {
var color = _contentColor(context, warning);
return warning ? Icon(Icons.error, color: color) : Icon(Icons.check_circle_outline, color: color);
}
TextStyle _textStyleFor(BuildContext context, bool warning) {
var color = _contentColor(context, warning);
var bodyLarge = Theme.of(context).primaryTextTheme.bodyLarge!;
var style = TextStyle(
color: color,
decoration: bodyLarge.decoration,
fontFamily: bodyLarge.fontFamily,
fontSize: bodyLarge.fontSize,
fontWeight: bodyLarge.fontWeight,
letterSpacing: bodyLarge.letterSpacing,
textBaseline: bodyLarge.textBaseline);
return style;
}
Color _contentColor(BuildContext context, bool warning) {
return warning ? Theme.of(context).colorScheme.error : Theme.of(context).colorScheme.inversePrimary;
}
}

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:pinput/pinput.dart';
abstract interface class GeneralStyle {
PinTheme get pinTheme;
ButtonStyle get elevatedButtonStyle;
ButtonStyle get roundedButtonStyle;
}
class GeneralStyleImpl implements GeneralStyle {
static final ButtonStyle _elevatedButtonStyle = ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));
static final ButtonStyle _roundedButtonStyle = ElevatedButton.styleFrom(shape: const CircleBorder(), padding: const EdgeInsets.all(8));
@override
PinTheme get pinTheme => _getPinTheme();
@override
ButtonStyle get elevatedButtonStyle => _elevatedButtonStyle;
@override
ButtonStyle get roundedButtonStyle => _roundedButtonStyle;
PinTheme _getPinTheme() {
return PinTheme(
width: 56,
height: 56,
textStyle: TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8),
),
);
}
}

View File

@@ -0,0 +1,89 @@
import 'package:flutter/material.dart';
class HeaderButtonWrapper extends StatefulWidget {
final IconData icon;
final String tooltip;
final VoidCallback onPressed;
final Color? iconColor;
final int? badgeCount;
const HeaderButtonWrapper({
super.key,
required this.icon,
required this.tooltip,
required this.onPressed,
this.iconColor,
this.badgeCount,
});
@override
State<HeaderButtonWrapper> createState() => _HeaderButtonWrapperState();
}
class _HeaderButtonWrapperState extends State<HeaderButtonWrapper> {
bool _isHovered = false;
@override
Widget build(BuildContext context) {
return MouseRegion(
onEnter: (_) => setState(() => _isHovered = true),
onExit: (_) => setState(() => _isHovered = false),
child: Tooltip(
message: widget.tooltip,
child: Stack(
clipBehavior: Clip.none,
children: [
Container(
decoration: BoxDecoration(
color: _isHovered ? Colors.blue[50] : Colors.transparent,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: _isHovered ? Colors.blue[200]! : Colors.transparent,
width: 1,
),
),
child: IconButton(
icon: Icon(
widget.icon,
size: 24,
color: widget.iconColor ?? Colors.grey[700],
),
onPressed: widget.onPressed,
splashRadius: 24,
),
),
if (widget.badgeCount != null && widget.badgeCount! > 0)
Positioned(
right: 4,
top: 4,
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.red[600],
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 2,
),
),
constraints: const BoxConstraints(
minWidth: 20,
minHeight: 20,
),
child: Text(
widget.badgeCount! > 99 ? '99+' : widget.badgeCount.toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:fotodocumentation/utils/di_container.dart';
import 'package:fotodocumentation/utils/login_credentials.dart';
abstract interface class HeaderUtils {
Widget titleWidget(String text);
}
class HeaderUtilsImpl extends HeaderUtils {
LoginCredentials get _loginCredentials => DiContainer.get();
@override
Widget titleWidget(String text) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.school,
size: 28,
color: Colors.blue[700],
),
const SizedBox(width: 12),
Text(
text,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
],
),
const SizedBox(height: 4),
if (_loginCredentials.fullname.isNotEmpty) ...[
Padding(
padding: const EdgeInsets.only(left: 40.0),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Colors.blue[200]!,
width: 1,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.person_outline,
size: 14,
color: Colors.blue[700],
),
const SizedBox(width: 6),
Text(
_loginCredentials.fullname,
style: TextStyle(
fontSize: 12,
color: Colors.blue[900],
fontWeight: FontWeight.w500,
),
),
],
),
),
),
],
],
);
}
}

View File

@@ -0,0 +1,99 @@
import 'package:flutter/material.dart';
import 'package:fotodocumentation/pages/ui_utils/header_button_wrapper.dart';
class ModernAppBar extends StatelessWidget implements PreferredSizeWidget {
final Widget title;
final List<Widget> actions;
final Widget? leading;
final bool automaticallyImplyLeading;
const ModernAppBar({
super.key,
required this.title,
this.actions = const [],
this.leading,
this.automaticallyImplyLeading = true,
});
@override
Widget build(BuildContext context) {
Widget? effectiveLeading = _effectiveLeading(context);
return Container(
decoration: BoxDecoration(
color: Colors.grey[50],
border: Border(
bottom: BorderSide(
color: Colors.grey[300]!,
width: 1,
),
),
),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Row(
children: [
if (effectiveLeading != null) ...[
effectiveLeading,
const SizedBox(width: 16),
],
Expanded(child: title),
const SizedBox(width: 16),
...actions.map((action) => Padding(
padding: const EdgeInsets.only(left: 8.0),
child: action,
)),
],
),
),
),
);
}
Widget? _effectiveLeading(BuildContext context) {
// Determine if we should show a back button
final ScaffoldState? scaffold = Scaffold.maybeOf(context);
final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context);
final bool hasDrawer = scaffold?.hasDrawer ?? false;
final bool canPop = parentRoute?.canPop ?? false;
final bool useCloseButton = parentRoute is PageRoute<dynamic> && parentRoute.fullscreenDialog;
Widget? effectiveLeading = leading;
if (effectiveLeading == null && automaticallyImplyLeading) {
if (hasDrawer) {
effectiveLeading = HeaderButtonWrapper(
icon: Icons.menu,
onPressed: () {
Scaffold.of(context).openDrawer();
},
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
iconColor: Colors.grey[700],
);
} else if (canPop) {
if (useCloseButton) {
effectiveLeading = HeaderButtonWrapper(
icon: Icons.close,
onPressed: () {
Navigator.of(context).pop();
},
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
iconColor: Colors.grey[700],
);
} else {
effectiveLeading = HeaderButtonWrapper(
icon: Icons.arrow_back,
onPressed: () {
Navigator.of(context).pop();
},
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
iconColor: Colors.grey[700],
);
}
}
}
return effectiveLeading;
}
@override
Size get preferredSize => const Size.fromHeight(80);
}