cleanup and added unit tests
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import 'dart:convert' show jsonDecode, jsonEncode;
|
||||
import 'dart:convert' show jsonDecode;
|
||||
|
||||
import 'package:fotodocumentation/dto/base_dto.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
import 'package:fotodocumentation/utils/http_client_utils.dart';
|
||||
import 'package:fotodocumentation/utils/jwt_token_storage.dart';
|
||||
import 'package:fotodocumentation/utils/url_utils.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart' show Response;
|
||||
|
||||
import 'package:fotodocumentation/main.dart' show logger;
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
import 'package:fotodocumentation/utils/http_client_utils.dart';
|
||||
import 'package:fotodocumentation/utils/jwt_token_storage.dart';
|
||||
import 'package:fotodocumentation/utils/url_utils.dart';
|
||||
|
||||
abstract class BaseController {
|
||||
UrlUtils get uriUtils => DiContainer.get();
|
||||
@@ -75,68 +74,6 @@ abstract class BaseController {
|
||||
var response = await client.delete(uri, headers: {cred.name: cred.value});
|
||||
return response.statusCode == 200;
|
||||
}
|
||||
|
||||
Future<bool> runPutWithAuth(String uriStr) async {
|
||||
http.Client client = httpClientUtils.client;
|
||||
Header cred = await getAuthHeader();
|
||||
Uri uri = Uri.parse(uriStr);
|
||||
var response = await client.put(uri, headers: {cred.name: cred.value});
|
||||
return response.statusCode == 200;
|
||||
}
|
||||
|
||||
Future<ServerReply<T>> runSaveNew<T extends DtoMapAble>(String uriStr, T dtoObj, Function(http.Response response, T dto) processReply) async {
|
||||
http.Client client = httpClientUtils.client;
|
||||
try {
|
||||
Header cred = await getAuthHeader();
|
||||
String body = jsonEncode(dtoObj.toMap());
|
||||
|
||||
Uri uri = Uri.parse(uriStr);
|
||||
var response = await client.post(uri, headers: {cred.name: cred.value, "Accept": "application/json", "Content-Type": "application/json"}, body: body);
|
||||
return processReply(response, dtoObj);
|
||||
} catch (e) {
|
||||
logger.e("exception $e");
|
||||
}
|
||||
return ServerReply(ServerState.error, dtoObj);
|
||||
}
|
||||
|
||||
Future<ServerReply<T>> runSaveUpdate<T extends DtoMapAble>(String uriStr, T dtoObj, Function(http.Response response, T dto) processReply) async {
|
||||
http.Client client = httpClientUtils.client;
|
||||
try {
|
||||
Header cred = await getAuthHeader();
|
||||
String body = jsonEncode(dtoObj.toMap());
|
||||
|
||||
Uri uri = Uri.parse(uriStr);
|
||||
var response = await client.put(uri, headers: {cred.name: cred.value, "Accept": "application/json", "Content-Type": "application/json"}, body: body);
|
||||
|
||||
return processReply(response, dtoObj);
|
||||
} catch (e) {
|
||||
logger.e("exception $e");
|
||||
}
|
||||
return ServerReply(ServerState.error, dtoObj);
|
||||
}
|
||||
|
||||
ServerReply<T> processServerResponse<T>(Response response, T dto, T Function(Map<String, dynamic> json) fromJson) {
|
||||
if (response.statusCode == 200) {
|
||||
String text = response.body;
|
||||
var json = jsonDecode(text);
|
||||
var dto = fromJson(json);
|
||||
return ServerReply(ServerState.ok, dto);
|
||||
} else if (response.statusCode == 400 || response.statusCode == 409) {
|
||||
String text = response.body;
|
||||
try {
|
||||
var json = jsonDecode(text);
|
||||
var error = ErrorDto.fromJson(json);
|
||||
|
||||
return ServerReply(ServerState.duplicate, dto, error: error);
|
||||
} catch (e) {
|
||||
return ServerReply(ServerState.error, dto, error: ErrorDto(response.statusCode, text));
|
||||
}
|
||||
} else if (response.statusCode == 403) {
|
||||
var error = ErrorDto(403, "Not allowed.");
|
||||
return ServerReply(ServerState.error, dto, error: error);
|
||||
}
|
||||
return ServerReply(ServerState.error, dto, error: ErrorDto(response.statusCode, "Internal server error"));
|
||||
}
|
||||
}
|
||||
|
||||
class Header {
|
||||
@@ -149,26 +86,8 @@ class Header {
|
||||
String toString() => '$runtimeType: $name, $value';
|
||||
}
|
||||
|
||||
class ServerReply<T> {
|
||||
ServerState state;
|
||||
T entity;
|
||||
ErrorDto? error;
|
||||
|
||||
ServerReply(this.state, this.entity, {this.error});
|
||||
|
||||
@override
|
||||
String toString() => '$runtimeType: $state, $entity, $error';
|
||||
}
|
||||
|
||||
class ServerError {
|
||||
int statusCode;
|
||||
|
||||
ServerError(this.statusCode);
|
||||
}
|
||||
|
||||
enum ServerState {
|
||||
ok,
|
||||
duplicate,
|
||||
error,
|
||||
;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||
|
||||
abstract interface class PictureController {
|
||||
Future<bool> delete(PictureDto dto);
|
||||
|
||||
@@ -8,8 +8,3 @@ final class ErrorDto {
|
||||
: error = json['error'] as int,
|
||||
message = json['message'];
|
||||
}
|
||||
|
||||
abstract interface class DtoMapAble {
|
||||
Map<String, dynamic> toMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||
import 'package:fotodocumentation/utils/date_time_utils.dart';
|
||||
|
||||
class CustomerListDto {
|
||||
@@ -38,28 +39,4 @@ class CustomerDto {
|
||||
}
|
||||
}
|
||||
|
||||
class PictureDto {
|
||||
final int id;
|
||||
final String? comment;
|
||||
final String? category;
|
||||
final String image;
|
||||
final DateTime pictureDate;
|
||||
final String? username;
|
||||
final CustomerListDto customerListDto;
|
||||
|
||||
PictureDto(
|
||||
{required this.id, required this.comment, required this.category, required this.image, required this.pictureDate, required this.username, required this.customerListDto});
|
||||
|
||||
/// Create from JSON response
|
||||
factory PictureDto.fromJson(Map<String, dynamic> json) {
|
||||
return PictureDto(
|
||||
id: json['id'] as int,
|
||||
comment: json['comment'] as String?,
|
||||
category: json['category'] as String?,
|
||||
image: json['image'] as String,
|
||||
pictureDate: DateTimeUtils.toDateTime(json['pictureDate']) ?? DateTime.now(),
|
||||
username: json['username'] as String?,
|
||||
customerListDto: CustomerListDto.fromJson(json['customer']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,3 @@
|
||||
/// DTO representing a failes login attempt request for 2fa token.
|
||||
class TokenRequiredDto {
|
||||
final bool? tokenRequired;
|
||||
final bool? tokenInValid;
|
||||
|
||||
TokenRequiredDto({
|
||||
required this.tokenRequired,
|
||||
required this.tokenInValid,
|
||||
});
|
||||
|
||||
/// Create from JSON response
|
||||
factory TokenRequiredDto.fromJson(Map<String, dynamic> json) {
|
||||
return TokenRequiredDto(
|
||||
tokenRequired: json['tokenRequired'] as bool,
|
||||
tokenInValid: json['tokenInValid'] as bool,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// DTO representing a pair of JWT tokens from the backend.
|
||||
class JwtTokenPairDto {
|
||||
@@ -35,14 +17,6 @@ class JwtTokenPairDto {
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert to JSON (for serialization if needed)
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'accessToken': accessToken,
|
||||
'refreshToken': refreshToken,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'JwtTokenPairDto{accessToken: [REDACTED], refreshToken: [REDACTED]}';
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:fotodocumentation/utils/date_time_utils.dart';
|
||||
|
||||
class PictureDto {
|
||||
final int id;
|
||||
final String? comment;
|
||||
final String? category;
|
||||
final String image;
|
||||
final DateTime pictureDate;
|
||||
final String? username;
|
||||
|
||||
PictureDto(
|
||||
{required this.id, required this.comment, required this.category, required this.image, required this.pictureDate, required this.username});
|
||||
|
||||
/// Create from JSON response
|
||||
factory PictureDto.fromJson(Map<String, dynamic> json) {
|
||||
return PictureDto(
|
||||
id: json['id'] as int,
|
||||
comment: json['comment'] as String?,
|
||||
category: json['category'] as String?,
|
||||
image: json['image'] as String,
|
||||
pictureDate: DateTimeUtils.toDateTime(json['pictureDate']) ?? DateTime.now(),
|
||||
username: json['username'] as String?
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ void main() async {
|
||||
|
||||
await initializeDateFormatting('de_DE', null);
|
||||
LoginController loginController = DiContainer.get();
|
||||
//await loginController.isLoggedIn();
|
||||
await loginController.isUsingJwtAuth();
|
||||
runApp(FotoDocumentationApp(theme: theme));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/dialog/delete_dialog.dart';
|
||||
|
||||
class CustomerRowItem extends StatelessWidget {
|
||||
final CustomerListDto dto;
|
||||
final Future<DeleteDialogResult> Function(CustomerListDto) doDelete;
|
||||
final Future<void> Function(CustomerListDto)? doSelect;
|
||||
|
||||
const CustomerRowItem({super.key, required this.dto, required this.doDelete, this.doSelect});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Colors.grey[300],
|
||||
child: Text(
|
||||
dto.name.isNotEmpty ? dto.name[0].toUpperCase() : '?',
|
||||
style: TextStyle(
|
||||
color: Colors.grey[700],
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(dto.name),
|
||||
subtitle: Text('CustomerNumber: ${dto.customerNumber}'),
|
||||
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
onTap: () async => await _doSelect(context),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _doSelect(BuildContext context) async {
|
||||
if (doSelect != null) {
|
||||
await doSelect!(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'dart:convert' show base64Decode;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||
import 'package:fotodocumentation/pages/customer/picture_delete_dialog.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -194,6 +195,7 @@ class _CustomerWidgetState extends State<CustomerWidget> {
|
||||
|
||||
final dateStr = _dateFormat.format(pictureDto.pictureDate);
|
||||
return InkWell(
|
||||
key: Key("table_row_${customerDto.id}"),
|
||||
onTap: () => _actionSelect(context, customerDto, pictureDto),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
@@ -231,6 +233,7 @@ class _CustomerWidgetState extends State<CustomerWidget> {
|
||||
SizedBox(
|
||||
width: 48,
|
||||
child: IconButton(
|
||||
key: Key("table_row_delete_${customerDto.id}"),
|
||||
icon: Icon(
|
||||
Icons.delete_outline,
|
||||
color: _generalStyle.errorColor,
|
||||
|
||||
@@ -28,6 +28,7 @@ class PictureDeleteDialog extends StatelessWidget {
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: Key("picture_delete_no"),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.deleteDialogButtonCancel,
|
||||
@@ -38,6 +39,7 @@ class PictureDeleteDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
key: Key("picture_delete_yes"),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.deleteDialogButtonApprove,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:convert' show base64Decode;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:convert' show base64Decode;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||
import 'package:fotodocumentation/pages/customer/picture_fullscreen_dialog.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
@@ -179,12 +180,17 @@ class _PictureWidgetState extends State<PictureWidget> {
|
||||
|
||||
Widget _imageWidget(PictureDto dto) {
|
||||
return GestureDetector(
|
||||
key: const Key("image"),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => _showFullscreenImage(dto),
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: Image.memory(
|
||||
base64Decode(dto.image),
|
||||
fit: BoxFit.contain,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minWidth: 100, minHeight: 100),
|
||||
child: Image.memory(
|
||||
base64Decode(dto.image),
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -234,7 +240,7 @@ class _PictureWidgetState extends State<PictureWidget> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
dto.customerListDto.name,
|
||||
widget.customerDto.name,
|
||||
style: contentStyle,
|
||||
),
|
||||
),
|
||||
@@ -248,7 +254,7 @@ class _PictureWidgetState extends State<PictureWidget> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
dto.customerListDto.customerNumber,
|
||||
widget.customerDto.customerNumber,
|
||||
style: contentStyle,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LandingPageWidget extends StatefulWidget {
|
||||
final Widget child;
|
||||
const LandingPageWidget({super.key, required this.child});
|
||||
|
||||
@override
|
||||
State<LandingPageWidget> createState() => _LandingPageWidgetState();
|
||||
}
|
||||
|
||||
class _LandingPageWidgetState extends State<LandingPageWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
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),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
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});
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract interface class GeneralStyle {
|
||||
ButtonStyle get elevatedButtonStyle;
|
||||
ButtonStyle get roundedButtonStyle;
|
||||
|
||||
|
||||
Color get primaryTextLabelColor;
|
||||
Color get secondaryTextLabelColor;
|
||||
|
||||
@@ -14,23 +12,12 @@ abstract interface class GeneralStyle {
|
||||
|
||||
Color get pageBackgroundColor;
|
||||
|
||||
Color get primaryCardColor;
|
||||
|
||||
Color get errorColor;
|
||||
|
||||
String get fontFamily;
|
||||
}
|
||||
|
||||
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
|
||||
ButtonStyle get elevatedButtonStyle => _elevatedButtonStyle;
|
||||
|
||||
@override
|
||||
ButtonStyle get roundedButtonStyle => _roundedButtonStyle;
|
||||
|
||||
@override
|
||||
Color get primaryTextLabelColor => const Color(0xFF0045FF);
|
||||
|
||||
@@ -45,10 +32,7 @@ class GeneralStyleImpl implements GeneralStyle {
|
||||
|
||||
@override
|
||||
Color get primaryButtonTextColor => Colors.white;
|
||||
|
||||
@override
|
||||
Color get primaryCardColor => Colors.white;
|
||||
|
||||
|
||||
@override
|
||||
Color get pageBackgroundColor => const Color(0xFFF5F5F5);
|
||||
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
||||
import 'package:fotodocumentation/controller/login_controller.dart';
|
||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/dialog/snackbar_utils.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/header_utils.dart';
|
||||
import 'package:fotodocumentation/utils/http_client_utils.dart';
|
||||
import 'package:fotodocumentation/utils/jwt_token_storage.dart';
|
||||
import 'package:fotodocumentation/utils/login_credentials.dart';
|
||||
@@ -24,9 +22,7 @@ class DiContainer {
|
||||
DiContainer.instance.put(GeneralStyle, GeneralStyleImpl());
|
||||
DiContainer.instance.put(JwtTokenStorage, JwtTokenStorageImpl());
|
||||
DiContainer.instance.put(HttpClientUtils, HttpCLientUtilsImpl());
|
||||
DiContainer.instance.put(HeaderUtils, HeaderUtilsImpl());
|
||||
DiContainer.instance.put(UrlUtils, UrlUtilsImpl());
|
||||
DiContainer.instance.put(SnackbarUtils, SnackbarUtilsImpl());
|
||||
DiContainer.instance.put(LoginController, LoginControllerImpl());
|
||||
DiContainer.instance.put(CustomerController, CustomerControllerImpl());
|
||||
DiContainer.instance.put(PictureController, PictureControllerImpl());
|
||||
|
||||
Reference in New Issue
Block a user