start quesitonnaire
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/general_error_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/page_header_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/search_bar_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/waiting_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
import 'package:fotodocumentation/utils/global_router.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class FotoCustomerListWidget extends StatefulWidget {
|
||||
const FotoCustomerListWidget({super.key});
|
||||
|
||||
@override
|
||||
State<FotoCustomerListWidget> createState() => _FotoCustomerListWidgetState();
|
||||
}
|
||||
|
||||
class _FotoCustomerListWidgetState extends State<FotoCustomerListWidget> {
|
||||
CustomerController get _customerController => DiContainer.get();
|
||||
GeneralStyle get _generalStyle => DiContainer.get();
|
||||
|
||||
final _searchController = TextEditingController();
|
||||
late Future<List<CustomerListDto>> _dtos;
|
||||
String? _selectedLetter;
|
||||
late DateFormat _dateFormat;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_dateFormat = DateFormat('dd MMMM yyyy');
|
||||
_dtos = _customerController.getAll(_searchController.text, "");
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: _body(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(BuildContext context) {
|
||||
return Container(
|
||||
color: _generalStyle.pageBackgroundColor,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0, left: 50.0, right: 50.0, bottom: 8.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
PageHeaderWidget(text: AppLocalizations.of(context)!.customerListHeadline),
|
||||
//_abcHeaderBar(),
|
||||
const SizedBox(width: 48),
|
||||
SearchBarWidget(
|
||||
searchController: _searchController,
|
||||
onSearch: (text) async => actionSearch(text),
|
||||
),
|
||||
Expanded(
|
||||
child: _customerListWidget(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _customerListWidget() {
|
||||
return FutureBuilder<List<CustomerListDto>>(
|
||||
future: _dtos,
|
||||
builder: (BuildContext context, AsyncSnapshot<List<CustomerListDto>> snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const WaitingWidget();
|
||||
}
|
||||
if (snapshot.hasData) {
|
||||
List<CustomerListDto> dtos = snapshot.data ?? [];
|
||||
|
||||
return _listWidget(dtos);
|
||||
} else if (snapshot.hasError) {
|
||||
var error = snapshot.error;
|
||||
return (error is ServerError) ? GeneralErrorWidget.fromServerError(error) : GeneralErrorWidget(error: snapshot.error.toString());
|
||||
}
|
||||
return const WaitingWidget();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _listWidget(List<CustomerListDto> dtos) {
|
||||
if (dtos.isEmpty) {
|
||||
return Text(AppLocalizations.of(context)!.customerListEmpty,
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
color: _generalStyle.secondaryWidgetBackgroundColor,
|
||||
));
|
||||
}
|
||||
return Card(
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_tableHeaderRow(context),
|
||||
Divider(thickness: 2, height: 1, color: _generalStyle.secondaryWidgetBackgroundColor),
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(0),
|
||||
itemCount: dtos.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return _tableDataRow(context, dtos[index]);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) => Divider(
|
||||
color: _generalStyle.secondaryWidgetBackgroundColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tableHeaderRow(BuildContext context) {
|
||||
final headerStyle = TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
color: _generalStyle.secondaryWidgetBackgroundColor,
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
spacing: 8.0,
|
||||
children: [
|
||||
const SizedBox(width: 48),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.customerListHeaderCustomerNumber,
|
||||
style: headerStyle,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.customerListHeaderName,
|
||||
style: headerStyle,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text(
|
||||
"PLZ/Ort",
|
||||
style: headerStyle,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
"Ort",
|
||||
style: headerStyle,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Wrap(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Icon(Icons.calendar_month, color: _generalStyle.secondaryWidgetBackgroundColor),
|
||||
),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.customerListHeaderLastDate,
|
||||
style: headerStyle,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tableDataRow(BuildContext context, CustomerListDto dto) {
|
||||
final dataStyle = TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontSize: 16.0,
|
||||
color: _generalStyle.secondaryTextLabelColor,
|
||||
);
|
||||
|
||||
final dateStr = dto.lastUpdateDate == null ? "" : _dateFormat.format(dto.lastUpdateDate!);
|
||||
return InkWell(
|
||||
onTap: () => _actionSelect(context, dto),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Row(
|
||||
spacing: 8.0,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 48,
|
||||
child: Icon(Icons.folder_open_outlined, color: _generalStyle.secondaryWidgetBackgroundColor),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text(dto.customerNumber, style: dataStyle),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(dto.name, style: dataStyle),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text(dto.zip ?? "", style: dataStyle),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(dto.city ?? "", style: dataStyle),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(dateStr, style: dataStyle),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> actionSearch(String text) async {
|
||||
_reloadData();
|
||||
}
|
||||
|
||||
Future<void> _actionSelect(BuildContext context, CustomerListDto dto) async {
|
||||
String uri = "${GlobalRouter.pathFotoHome}${GlobalRouter.pathFotoCustomer}/${dto.id}";
|
||||
context.go(uri);
|
||||
}
|
||||
|
||||
void _reloadData() {
|
||||
_dtos = _customerController.getAll(_searchController.text, _selectedLetter ?? "");
|
||||
setState(() {});
|
||||
}
|
||||
/*
|
||||
Widget _abcHeaderBar() {
|
||||
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: letters.split('').map((letter) {
|
||||
final isSelected = _selectedLetter == letter;
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedLetter = isSelected ? null : letter;
|
||||
_reloadData();
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? _generalStyle.secondaryWidgetBackgroundColor : Colors.white,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
letter,
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0,
|
||||
color: isSelected ? Colors.white : _generalStyle.secondaryWidgetBackgroundColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/customer_back_button.dart';
|
||||
import 'package:fotodocumentation/pages/foto/customer/foto_picture_delete_dialog.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/general_error_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/page_header_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/waiting_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
import 'package:fotodocumentation/utils/global_router.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:fotodocumentation/utils/file_download.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class FotoCustomerWidget extends StatefulWidget {
|
||||
final int customerId;
|
||||
const FotoCustomerWidget({super.key, required this.customerId});
|
||||
|
||||
@override
|
||||
State<FotoCustomerWidget> createState() => _FotoCustomerWidgetState();
|
||||
}
|
||||
|
||||
class _FotoCustomerWidgetState extends State<FotoCustomerWidget> {
|
||||
CustomerController get _customerController => DiContainer.get();
|
||||
PictureController get _pictureController => DiContainer.get();
|
||||
GeneralStyle get _generalStyle => DiContainer.get();
|
||||
|
||||
late Future<CustomerDto?> _dto;
|
||||
late DateFormat _dateFormat;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_dateFormat = DateFormat('dd MMMM yyyy');
|
||||
_dto = _customerController.get(id: widget.customerId);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant FotoCustomerWidget oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.customerId != widget.customerId) {
|
||||
_dto = _customerController.get(id: widget.customerId);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
color: _generalStyle.pageBackgroundColor,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0, left: 50.0, right: 50.0, bottom: 8.0),
|
||||
child: _body(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(BuildContext context) {
|
||||
return FutureBuilder<CustomerDto?>(
|
||||
future: _dto,
|
||||
builder: (BuildContext context, AsyncSnapshot<CustomerDto?> snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const WaitingWidget();
|
||||
}
|
||||
if (snapshot.hasData) {
|
||||
CustomerDto? dto = snapshot.data;
|
||||
if (dto == null) {
|
||||
return Text(
|
||||
AppLocalizations.of(context)!.customerWidgetNotFound,
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
color: _generalStyle.secondaryWidgetBackgroundColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _mainWidget(dto);
|
||||
} else if (snapshot.hasError) {
|
||||
var error = snapshot.error;
|
||||
return (error is ServerError) ? GeneralErrorWidget.fromServerError(error) : GeneralErrorWidget(error: snapshot.error.toString());
|
||||
}
|
||||
return const WaitingWidget();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _mainWidget(CustomerDto dto) {
|
||||
var subText = AppLocalizations.of(context)!.customerWidgetCustomerNumberPrefix(dto.customerNumber);
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
PageHeaderWidget(text: dto.name, subText: subText),
|
||||
CustomerBackButton(path: GlobalRouter.pathFotoHome),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
_downloadButton(context, dto),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Expanded(
|
||||
child: _customerWidget(dto),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _customerWidget(CustomerDto customerDto) {
|
||||
var pictureDtos = customerDto.pictures;
|
||||
|
||||
pictureDtos.sort((a, b) => b.pictureDate.compareTo(a.pictureDate));
|
||||
|
||||
return Card(
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_tableHeaderRow(context),
|
||||
Divider(thickness: 2, height: 1, color: _generalStyle.secondaryWidgetBackgroundColor),
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
itemCount: pictureDtos.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return _tableDataRow(context, customerDto, pictureDtos[index]);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) => Divider(color: _generalStyle.secondaryWidgetBackgroundColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tableHeaderRow(BuildContext context) {
|
||||
final headerStyle = TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
color: _generalStyle.secondaryWidgetBackgroundColor,
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 8.0,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.customerWidgetHeaderFoto,
|
||||
style: headerStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.customerWidgetHeaderComment,
|
||||
style: headerStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Bewertung',
|
||||
style: headerStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.customerWidgetHeaderUploadDate,
|
||||
style: headerStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 96),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tableDataRow(BuildContext context, CustomerDto customerDto, PictureDto pictureDto) {
|
||||
final dataStyle = TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontSize: 16.0,
|
||||
color: _generalStyle.secondaryTextLabelColor,
|
||||
);
|
||||
|
||||
final dateStr = _dateFormat.format(pictureDto.pictureDate);
|
||||
final evaluationColor = _generalStyle.evaluationColor(value: pictureDto.evaluation);
|
||||
Header cred = HeaderUtils().getAuthHeader();
|
||||
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),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
spacing: 8.0,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 70, maxHeight: 70),
|
||||
child: Image.network(
|
||||
headers: {cred.name: cred.value},
|
||||
pictureDto.thumbnailSizeUrl,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(pictureDto.comment ?? "", style: dataStyle),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: evaluationColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(dateStr, style: dataStyle),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 48,
|
||||
child: IconButton(
|
||||
key: Key("table_row_download_${pictureDto.id}"),
|
||||
icon: Icon(
|
||||
Icons.file_download_outlined,
|
||||
color: _generalStyle.loginFormTextLabelColor,
|
||||
),
|
||||
onPressed: () => _actionDownload(context, customerDto, pictureDto),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 48,
|
||||
child: IconButton(
|
||||
key: Key("table_row_delete_${customerDto.id}"),
|
||||
icon: Icon(
|
||||
Icons.delete_outline,
|
||||
color: _generalStyle.errorColor,
|
||||
),
|
||||
onPressed: () => _actionDelete(context, customerDto, pictureDto),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _downloadButton(BuildContext context, CustomerDto customerDto) {
|
||||
return ElevatedButton.icon(
|
||||
key: Key("download_all_button"),
|
||||
onPressed: () => _actionDownload(context, customerDto, null),
|
||||
iconAlignment: IconAlignment.end,
|
||||
icon: Icon(
|
||||
Icons.file_download_outlined,
|
||||
color: _generalStyle.primaryButtonTextColor,
|
||||
size: 24,
|
||||
),
|
||||
label: Text(
|
||||
"Alle herunterladen",
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: _generalStyle.primaryButtonTextColor,
|
||||
),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _generalStyle.secondaryWidgetBackgroundColor,
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
shape: const StadiumBorder(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _actionDelete(BuildContext context, CustomerDto customerDto, PictureDto pictureDto) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return FotoPictureDeleteDialog();
|
||||
},
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
_pictureController.delete(pictureDto);
|
||||
setState(() {
|
||||
_dto = _customerController.get(id: widget.customerId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _actionSelect(BuildContext context, CustomerDto customerDto, PictureDto pictureDto) async {
|
||||
String uri = "${GlobalRouter.pathFotoHome}${GlobalRouter.pathFotoCustomer}/${customerDto.id}${GlobalRouter.pathFotoPicture}/${pictureDto.id}";
|
||||
context.go(uri);
|
||||
setState(() {
|
||||
_dto = _customerController.get(id: widget.customerId);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _actionDownload(BuildContext context, CustomerDto customerDto, PictureDto? pictureDto) async {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => Dialog(
|
||||
backgroundColor: Colors.white,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(width: 16),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.customerWidgetDownloadInProgress,
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
final bytes = await _customerController.export(customerId: customerDto.id, pictureId: pictureDto?.id);
|
||||
final fileName = pictureDto != null ? '${customerDto.customerNumber}_${pictureDto.id}.pdf' : '${customerDto.customerNumber}.pdf';
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
await downloadFile(bytes, fileName);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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';
|
||||
|
||||
class FotoPictureDeleteDialog extends StatelessWidget {
|
||||
GeneralStyle get _generalStyle => DiContainer.get();
|
||||
|
||||
const FotoPictureDeleteDialog({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
actionsAlignment: MainAxisAlignment.center,
|
||||
actionsPadding: EdgeInsets.only(bottom: 50),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 50.0),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: _generalStyle.errorColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.delete_outline,
|
||||
size: 32,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left:50, right: 50, bottom: 50),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.deleteDialogText,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
color: _generalStyle.secondaryTextLabelColor,
|
||||
fontSize: 28.71,
|
||||
fontWeight: FontWeight.normal,
|
||||
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
key: Key("picture_delete_no"),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _generalStyle.deleteCancelButtonBackgroundColor,
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.deleteDialogButtonCancel,
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
color: _generalStyle.deleteCancelTextColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18.37,
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
key: Key("picture_delete_yes"),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _generalStyle.primaryButtonBackgroundColor,
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.deleteDialogButtonApprove,
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18.37,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
|
||||
class FotoPictureFullscreenDialog extends StatelessWidget {
|
||||
GeneralStyle get _generalStyle => DiContainer.get();
|
||||
|
||||
final PictureDto dto;
|
||||
|
||||
const FotoPictureFullscreenDialog({super.key, required this.dto});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
final dialogWidth = screenSize.width * 0.9;
|
||||
final dialogHeight = screenSize.height * 0.9 - 50;
|
||||
Header cred = HeaderUtils().getAuthHeader();
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: Colors.black,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0, right: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
IconButton(
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: _generalStyle.primaryButtonBackgroundColor,
|
||||
shape: const CircleBorder(),
|
||||
minimumSize: const Size(36, 36),
|
||||
padding: const EdgeInsets.all(6),
|
||||
),
|
||||
icon: const Icon(Icons.close, color: Colors.white, size: 20),
|
||||
onPressed: () async => await _actionBack(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: dialogWidth,
|
||||
height: dialogHeight,
|
||||
child: InteractiveViewer(
|
||||
constrained: true,
|
||||
panEnabled: true,
|
||||
scaleEnabled: true,
|
||||
minScale: 0.5,
|
||||
maxScale: 5.0,
|
||||
child: Image.network(
|
||||
headers: {cred.name: cred.value},
|
||||
dto.imageUrl,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _actionBack(BuildContext context) async {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,445 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
||||
import 'package:fotodocumentation/controller/picture_controller.dart';
|
||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||
import 'package:fotodocumentation/dto/picture_dto.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/customer_back_button.dart';
|
||||
import 'package:fotodocumentation/pages/foto/customer/foto_picture_fullscreen_dialog.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/general_error_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/page_header_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/component/waiting_widget.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
import 'package:fotodocumentation/utils/global_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class FotoPictureWidget extends StatefulWidget {
|
||||
final int customerId;
|
||||
final int pictureId;
|
||||
const FotoPictureWidget({super.key, required this.customerId, required this.pictureId});
|
||||
|
||||
@override
|
||||
State<FotoPictureWidget> createState() => _FotoPictureWidgetState();
|
||||
}
|
||||
|
||||
class _FotoPictureWidgetState extends State<FotoPictureWidget> {
|
||||
GeneralStyle get _generalStyle => DiContainer.get();
|
||||
CustomerController get _customerController => DiContainer.get();
|
||||
PictureController get _pictureController => DiContainer.get();
|
||||
|
||||
late CustomerDto _customerDto;
|
||||
PictureDto? _selectedPicture;
|
||||
late DateFormat _dateFormat;
|
||||
final ScrollController _commentScrollController = ScrollController();
|
||||
|
||||
late Future<CustomerDto?> _dto;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_dateFormat = DateFormat('dd.MM.yyyy, hh:mm');
|
||||
_dto = _customerController.get(id: widget.customerId);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant FotoPictureWidget oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.customerId != widget.customerId || oldWidget.pictureId != widget.pictureId) {
|
||||
_dto = _customerController.get(id: widget.customerId);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_commentScrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
color: _generalStyle.pageBackgroundColor,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0, left: 50.0, right: 50.0, bottom: 8.0),
|
||||
child: _future(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _future(BuildContext context) {
|
||||
return FutureBuilder<CustomerDto?>(
|
||||
future: _dto,
|
||||
builder: (BuildContext context, AsyncSnapshot<CustomerDto?> snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const WaitingWidget();
|
||||
}
|
||||
if (snapshot.hasData) {
|
||||
CustomerDto? dto = snapshot.data;
|
||||
if (dto == null) {
|
||||
return GeneralErrorWidget(error: AppLocalizations.of(context)!.customerWidgetNotFound);
|
||||
}
|
||||
_customerDto = dto;
|
||||
_selectedPicture ??= dto.pictures.firstWhere((p) => p.id == widget.pictureId);
|
||||
_selectedPicture ??= _customerDto.pictures.firstOrNull;
|
||||
if (_selectedPicture == null) {
|
||||
return GeneralErrorWidget(error: AppLocalizations.of(context)!.pictureWidgetNotFound);
|
||||
}
|
||||
return _body(context, _selectedPicture!);
|
||||
} else if (snapshot.hasError) {
|
||||
var error = snapshot.error;
|
||||
return (error is ServerError) ? GeneralErrorWidget.fromServerError(error) : GeneralErrorWidget(error: snapshot.error.toString());
|
||||
}
|
||||
return const WaitingWidget();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(BuildContext context, PictureDto selectedPicture) {
|
||||
final pictures = _customerDto.pictures;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
PageHeaderWidget(text: _customerDto.name),
|
||||
CustomerBackButton(path: GlobalRouter.pathFotoCustomer),
|
||||
const SizedBox(height: 24),
|
||||
Expanded(
|
||||
child: _mainWidget(context, selectedPicture),
|
||||
),
|
||||
_bottomNavigationWidget(pictures, selectedPicture),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _mainWidget(BuildContext context, PictureDto selectedPicture) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final isNarrow = constraints.maxWidth < 800;
|
||||
final imageWidth = isNarrow ? constraints.maxWidth : constraints.maxWidth * 0.5;
|
||||
return SingleChildScrollView(
|
||||
child: isNarrow
|
||||
? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: imageWidth,
|
||||
child: _imageWidget(selectedPicture),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
_contentWidget(selectedPicture),
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: imageWidth,
|
||||
child: _imageWidget(selectedPicture),
|
||||
),
|
||||
const SizedBox(width: 32),
|
||||
Expanded(child: _contentWidget(selectedPicture)),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _imageWidget(PictureDto dto) {
|
||||
Header cred = HeaderUtils().getAuthHeader();
|
||||
|
||||
return GestureDetector(
|
||||
key: const Key("image"),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => _actionShowFullscreenImage(dto),
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minWidth: 100, minHeight: 100),
|
||||
child: Image.network(
|
||||
headers: {cred.name: cred.value},
|
||||
dto.normalSizeUrl,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _contentWidget(PictureDto dto) {
|
||||
final labelStyle = TextStyle(
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 16,
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
color: _generalStyle.primaryTextLabelColor,
|
||||
);
|
||||
|
||||
final contentStyle = TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
color: _generalStyle.secondaryTextLabelColor,
|
||||
);
|
||||
|
||||
String dateText = _dateFormat.format(dto.pictureDate);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"$dateText UHR",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 32,
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
color: _generalStyle.secondaryWidgetBackgroundColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context)!.pictureWidgetLabelCustomerNumber,
|
||||
style: labelStyle,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
_customerDto.customerNumber,
|
||||
style: contentStyle,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 24.0),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.pictureWidgetLabelZip,
|
||||
style: labelStyle,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
_customerDto.zip ?? "",
|
||||
style: contentStyle,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 24.0),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.pictureWidgetLabelCity,
|
||||
style: labelStyle,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
_customerDto.city ?? "",
|
||||
style: contentStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
_evaluationCard(dto),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 24.0),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.pictureWidgetLabelComment,
|
||||
style: labelStyle,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: 150,
|
||||
child: Scrollbar(
|
||||
controller: _commentScrollController,
|
||||
thumbVisibility: true,
|
||||
child: SingleChildScrollView(
|
||||
controller: _commentScrollController,
|
||||
child: Text(
|
||||
dto.comment ?? "",
|
||||
style: contentStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _evaluationCard(PictureDto dto) {
|
||||
return Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context)!.pictureWidgetLabelEvaluation,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 16,
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
color: _generalStyle.primaryTextLabelColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_evaluationCircle(
|
||||
key: const Key("evaluation_good"),
|
||||
color: _generalStyle.evaluationGoodColor,
|
||||
value: 1,
|
||||
selected: dto.evaluation == 1,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_evaluationCircle(
|
||||
key: const Key("evaluation_middle"),
|
||||
color: _generalStyle.evaluationMiddleColor,
|
||||
value: 2,
|
||||
selected: dto.evaluation == 2,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_evaluationCircle(
|
||||
key: const Key("evaluation_bad"),
|
||||
color: _generalStyle.evaluationBadColor,
|
||||
value: 3,
|
||||
selected: dto.evaluation == 3,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _evaluationCircle({
|
||||
required Key key,
|
||||
required Color color,
|
||||
required int value,
|
||||
required bool selected,
|
||||
}) {
|
||||
return InkWell(
|
||||
key: key,
|
||||
onTap: () async => _actionUpdateEvaluation(value),
|
||||
customBorder: const CircleBorder(),
|
||||
child: Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
border: selected ? Border.all(color: _generalStyle.secondaryWidgetBackgroundColor, width: 3) : null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Bottom navigation buttons
|
||||
Widget _bottomNavigationWidget(List<PictureDto> pictures, PictureDto selectedPicture) {
|
||||
pictures.sort((a, b) => a.pictureDate.compareTo(b.pictureDate));
|
||||
final currentIndex = pictures.indexWhere((p) => p.id == selectedPicture.id);
|
||||
final hasPrevious = currentIndex > 0;
|
||||
final hasNext = currentIndex < pictures.length - 1;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 24.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Previous button
|
||||
IconButton(
|
||||
key: Key("navigate_left"),
|
||||
onPressed: hasPrevious ? () => _actionNavigateToPicture(currentIndex - 1) : null,
|
||||
icon: Icon(Icons.chevron_left, color: _generalStyle.nextTextColor, size: 32),
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
// Picture counter text
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'${currentIndex + 1}',
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _generalStyle.nextTextColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'von ${pictures.length}',
|
||||
style: TextStyle(
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: _generalStyle.nextTextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
// Next button
|
||||
IconButton(
|
||||
key: Key("navigate_right"),
|
||||
onPressed: hasNext ? () => _actionNavigateToPicture(currentIndex + 1) : null,
|
||||
icon: Icon(Icons.chevron_right, color: _generalStyle.nextTextColor, size: 32),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _actionShowFullscreenImage(PictureDto dto) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return FotoPictureFullscreenDialog(dto: dto);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _actionUpdateEvaluation(int value) async {
|
||||
_selectedPicture?.evaluation = value;
|
||||
_pictureController.updateEvaluation(_selectedPicture!);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void _actionNavigateToPicture(int index) {
|
||||
final pictures = _customerDto.pictures;
|
||||
if (index >= 0 && index < pictures.length) {
|
||||
setState(() {
|
||||
_selectedPicture = pictures[index];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:fotodocumentation/controller/login_controller.dart';
|
||||
import 'package:fotodocumentation/dto/jwt_token_pair_dto.dart';
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/general_style.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
import 'package:fotodocumentation/utils/login_credentials.dart';
|
||||
|
||||
class FotoLoginWidget extends StatefulWidget {
|
||||
const FotoLoginWidget({super.key});
|
||||
|
||||
@override
|
||||
State<FotoLoginWidget> createState() => _FotoLoginWidgetState();
|
||||
}
|
||||
|
||||
class _FotoLoginWidgetState extends State<FotoLoginWidget> {
|
||||
LoginController get _loginController => DiContainer.get();
|
||||
LoginCredentials get _loginCredentials => DiContainer.get();
|
||||
GeneralStyle get _generalStyle => DiContainer.get();
|
||||
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
|
||||
final _usernameController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
|
||||
String? _error;
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.dispose();
|
||||
_usernameController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: _body(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(BuildContext context) {
|
||||
return Container(
|
||||
color: _generalStyle.pageBackgroundColor,
|
||||
child: _content(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _content(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: KeyboardListener(
|
||||
focusNode: _focusNode,
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) {
|
||||
_actionSubmit(context);
|
||||
}
|
||||
},
|
||||
child: ListView(
|
||||
children: [
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 40.0),
|
||||
child: Image.asset(
|
||||
'assets/images/logo.png',
|
||||
height: 120,
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 500),
|
||||
child: Card(
|
||||
elevation: 0,
|
||||
margin: EdgeInsets.zero,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(70.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: Text(
|
||||
key: Key("login_title"),
|
||||
AppLocalizations.of(context)!.loginTitle,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _generalStyle.primaryTextLabelColor,
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontSize: 50,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
if (_error != null) ...[
|
||||
_errorWidget(),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
TextFormField(
|
||||
key: Key("username"),
|
||||
controller: _usernameController,
|
||||
decoration: _formFieldInputDecoration(AppLocalizations.of(context)!.loginUsernameTFLabel),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
TextFormField(
|
||||
key: Key("password"),
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
decoration: _formFieldInputDecoration(AppLocalizations.of(context)!.loginPasswordTFLabel),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
key: Key("SubmitWidgetButton"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _generalStyle.primaryButtonBackgroundColor,
|
||||
foregroundColor: _generalStyle.primaryButtonTextColor,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
|
||||
),
|
||||
onPressed: () async => await _actionSubmit(context),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.loginLoginButtonLabel,
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontFamily: _generalStyle.fontFamily),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _errorWidget() {
|
||||
return Center(
|
||||
child: Text(
|
||||
_error!,
|
||||
style: TextStyle(
|
||||
color: _generalStyle.errorColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputDecoration _formFieldInputDecoration(String text) {
|
||||
var formLabelTextStyle = TextStyle(
|
||||
color: _generalStyle.loginFormTextLabelColor,
|
||||
fontFamily: _generalStyle.fontFamily,
|
||||
fontSize: 14,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontWeight: FontWeight.normal,
|
||||
);
|
||||
return InputDecoration(
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: _error != null ? BorderSide(color: _generalStyle.errorColor) : BorderSide(),
|
||||
),
|
||||
enabledBorder: _error != null
|
||||
? OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide(color: _generalStyle.errorColor),
|
||||
)
|
||||
: null,
|
||||
labelText: text.toUpperCase(),
|
||||
labelStyle: formLabelTextStyle,
|
||||
floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _actionSubmit(BuildContext context) async {
|
||||
String username = _usernameController.text;
|
||||
String password = _passwordController.text;
|
||||
|
||||
AuthenticateReply authenticateReply = await _loginController.authenticate(username, password);
|
||||
|
||||
JwtTokenPairDto? jwtTokenPairDto = authenticateReply.jwtTokenPairDto;
|
||||
if (jwtTokenPairDto == null) {
|
||||
setState(() => _error = AppLocalizations.of(context)!.loginErrorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
_loginCredentials.setLoggedIn(true);
|
||||
if (context.mounted) {
|
||||
// Get the redirect URL from query parameters
|
||||
final redirect = GoRouterState.of(context).uri.queryParameters['redirect'];
|
||||
context.go(redirect ?? '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user