Fix: Passt das Verhalten der InputFelder an, dass sich diese wirklich verändern
This commit is contained in:
@@ -36,6 +36,7 @@ class _RecentTransactionsListState extends State<RecentTransactionsList> {
|
||||
final Future<List<Transaction>> recentTransactions = _transactionRepository
|
||||
.findBy(
|
||||
account: _accountController.selected.value,
|
||||
dateTo: DateTime.now(),
|
||||
limit: 5,
|
||||
orderBy: 'dateDesc',
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../Services/date_service.dart';
|
||||
import '../../Dialog/dialog_action.dart';
|
||||
import '../../Dialog/dialog_input_field.dart';
|
||||
import '../../Dialog/dialog_input_field_type_enum.dart';
|
||||
@@ -9,16 +10,13 @@ import '../../Dialog/dynamic_dialog.dart';
|
||||
class DateRangePicker extends StatefulWidget {
|
||||
/// Initialisiert eine neue Instanz dieser Klasse
|
||||
const DateRangePicker({
|
||||
this.controller,
|
||||
this.autofocus = false,
|
||||
super.key,
|
||||
this.decoration,
|
||||
this.initialValue,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
/// Der Initiale Wert des Input-Feldes
|
||||
final DateTimeRange? initialValue;
|
||||
|
||||
/// Ob das Feld automatisch ausgewählt werden soll
|
||||
final bool autofocus;
|
||||
|
||||
@@ -28,42 +26,39 @@ class DateRangePicker extends StatefulWidget {
|
||||
/// Die Dekoration, wie das Feld aussehen soll
|
||||
final InputDecoration? decoration;
|
||||
|
||||
/// Der Controller über den der Wert des Inputfeldes gesetzt
|
||||
/// und ausgelesen werden kann
|
||||
final TextEditingController? controller;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _DateRangePicker();
|
||||
}
|
||||
|
||||
class _DateRangePicker extends State<DateRangePicker> {
|
||||
final ValueNotifier<DateTimeRange?> _value = ValueNotifier(null);
|
||||
final TextEditingController _valueController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
void dispose() {
|
||||
_valueController.dispose();
|
||||
|
||||
_value.value = widget.initialValue;
|
||||
_value.addListener(() {
|
||||
widget.onChanged?.call(_value.value);
|
||||
});
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) => TextField(
|
||||
readOnly: true,
|
||||
controller: TextEditingController(
|
||||
text: widget.initialValue != null
|
||||
? '${widget.initialValue!.start.day}'
|
||||
'.${widget.initialValue!.start.month}'
|
||||
'.${widget.initialValue!.start.year}'
|
||||
' - '
|
||||
'${widget.initialValue!.end.day}'
|
||||
'.${widget.initialValue!.end.month}'
|
||||
'.${widget.initialValue!.end.year}'
|
||||
: null,
|
||||
),
|
||||
controller: widget.controller ?? _valueController,
|
||||
decoration: widget.decoration,
|
||||
onTap: _pickDateRange,
|
||||
);
|
||||
|
||||
Future<void> _pickDateRange() async {
|
||||
final TextEditingController controller =
|
||||
widget.controller ?? _valueController;
|
||||
|
||||
final DateTimeRange<DateTime>? dateTimeRange =
|
||||
DateService.stringToDateTimeRange(controller.text);
|
||||
|
||||
await DynamicDialog(
|
||||
title: 'Zeitraum auswählen',
|
||||
inputFields: [
|
||||
@@ -72,14 +67,14 @@ class _DateRangePicker extends State<DateRangePicker> {
|
||||
label: 'Startdatum',
|
||||
keyboardType: TextInputType.datetime,
|
||||
inputType: DialogInputFieldTypeEnum.date,
|
||||
initialValue: _value.value?.start,
|
||||
initialValue: dateTimeRange?.start,
|
||||
),
|
||||
DialogInputField(
|
||||
id: 'dateTo',
|
||||
label: 'Enddatum',
|
||||
keyboardType: TextInputType.datetime,
|
||||
inputType: DialogInputFieldTypeEnum.date,
|
||||
initialValue: _value.value?.end,
|
||||
initialValue: dateTimeRange?.end,
|
||||
),
|
||||
],
|
||||
actions: [
|
||||
@@ -87,7 +82,8 @@ class _DateRangePicker extends State<DateRangePicker> {
|
||||
DialogAction(
|
||||
label: 'Leeren',
|
||||
onPressed: (_) {
|
||||
_value.value = null;
|
||||
controller.text = '';
|
||||
widget.onChanged?.call(null);
|
||||
},
|
||||
),
|
||||
DialogAction(
|
||||
@@ -98,10 +94,13 @@ class _DateRangePicker extends State<DateRangePicker> {
|
||||
values['dateFrom'] is DateTime &&
|
||||
values['dateTo'] != null &&
|
||||
values['dateTo'] is DateTime) {
|
||||
_value.value = DateTimeRange(
|
||||
final DateTimeRange<DateTime> timeRange = DateTimeRange(
|
||||
start: values['dateFrom'],
|
||||
end: values['dateTo'],
|
||||
);
|
||||
|
||||
controller.text = DateService.dateTimeRangeToString(timeRange)!;
|
||||
widget.onChanged?.call(timeRange);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:date_field/date_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../Services/date_service.dart';
|
||||
|
||||
/// Ein Feld mit Popup über welches man Datumsfelder auswählen kann
|
||||
class DynamicDateTimeField extends StatefulWidget {
|
||||
@@ -45,7 +46,7 @@ class _DynamicDateTimeFieldState extends State<DynamicDateTimeField> {
|
||||
@override
|
||||
Widget build(final BuildContext context) => DateTimeField(
|
||||
initialPickerDateTime: widget.initialValue,
|
||||
dateFormat: DateFormat('d.M.y'),
|
||||
dateFormat: DateService.dateFormat,
|
||||
value: _value,
|
||||
mode: widget.mode,
|
||||
autofocus: widget.autofocus,
|
||||
|
||||
@@ -62,7 +62,7 @@ class _MonthlyBalanceChart extends State<MonthlyBalanceChart> {
|
||||
amountMin: widget.amountMin,
|
||||
amountMax: widget.amountMax,
|
||||
dateFrom: widget.dateFrom,
|
||||
dateTo: widget.dateTo,
|
||||
dateTo: (widget.dateTo != null) ? widget.dateTo : DateTime.now(),
|
||||
),
|
||||
builder:
|
||||
(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:routemaster/routemaster.dart';
|
||||
|
||||
import '../../Services/date_service.dart';
|
||||
import '../Misc/InputFields/date_range_picker.dart';
|
||||
|
||||
/// Stellt die Inputfelder für die Verlaufsübersicht dar
|
||||
@@ -13,7 +14,6 @@ class InputFields extends StatefulWidget {
|
||||
this.dateFrom,
|
||||
this.dateTo,
|
||||
this.name,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
/// Der Name der Transaktion, nach der gesucht werden soll
|
||||
@@ -31,35 +31,54 @@ class InputFields extends StatefulWidget {
|
||||
///Das Datum der Transaktionen, bis zu welchen beendet wurde
|
||||
final DateTime? dateTo;
|
||||
|
||||
/// Die Funktion, die bei Veränderung eines Wertes aufgerufen wird
|
||||
final Function()? onChanged;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _InputFields();
|
||||
}
|
||||
|
||||
class _InputFields extends State<InputFields> {
|
||||
String? _name;
|
||||
double? _amountMin;
|
||||
double? _amountMax;
|
||||
DateTimeRange? _dateTimeRange;
|
||||
final TextEditingController _nameController = TextEditingController();
|
||||
final TextEditingController _amountMinController = TextEditingController();
|
||||
final TextEditingController _amountMaxController = TextEditingController();
|
||||
final TextEditingController _dateTimeController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_name = widget.name;
|
||||
_amountMin = widget.amountMin;
|
||||
_amountMax = widget.amountMax;
|
||||
if (widget.name != null) {
|
||||
_nameController.text = widget.name!;
|
||||
}
|
||||
|
||||
if (widget.amountMin != null) {
|
||||
_amountMinController.text = widget.amountMin!.toString();
|
||||
}
|
||||
|
||||
if (widget.amountMax != null) {
|
||||
_amountMaxController.text = widget.amountMax!.toString();
|
||||
}
|
||||
|
||||
if (widget.dateFrom != null && widget.dateTo != null) {
|
||||
_dateTimeRange = DateTimeRange(
|
||||
final DateTimeRange dateTimeRange = DateTimeRange(
|
||||
start: widget.dateFrom!,
|
||||
end: widget.dateTo!,
|
||||
);
|
||||
|
||||
_dateTimeController.text = DateService.dateTimeRangeToString(
|
||||
dateTimeRange,
|
||||
)!;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_amountMinController.dispose();
|
||||
_amountMaxController.dispose();
|
||||
_dateTimeController.dispose();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
@@ -68,12 +87,12 @@ class _InputFields extends State<InputFields> {
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _nameController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Name',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onChanged: (final String value) {
|
||||
_name = value;
|
||||
_updateUrl();
|
||||
},
|
||||
),
|
||||
@@ -81,13 +100,13 @@ class _InputFields extends State<InputFields> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _amountMinController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Min Betrag €',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
onChanged: (final String value) {
|
||||
_amountMin = double.tryParse(value);
|
||||
_updateUrl();
|
||||
},
|
||||
),
|
||||
@@ -95,13 +114,13 @@ class _InputFields extends State<InputFields> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _amountMaxController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Max Betrag €',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
onChanged: (final String value) {
|
||||
_amountMax = double.tryParse(value);
|
||||
_updateUrl();
|
||||
},
|
||||
),
|
||||
@@ -109,9 +128,8 @@ class _InputFields extends State<InputFields> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: DateRangePicker(
|
||||
initialValue: _dateTimeRange,
|
||||
controller: _dateTimeController,
|
||||
onChanged: (final DateTimeRange? value) {
|
||||
_dateTimeRange = value;
|
||||
_updateUrl();
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
@@ -127,10 +145,10 @@ class _InputFields extends State<InputFields> {
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_name = null;
|
||||
_amountMin = null;
|
||||
_amountMax = null;
|
||||
_dateTimeRange = null;
|
||||
_nameController.text = '';
|
||||
_amountMinController.text = '';
|
||||
_amountMaxController.text = '';
|
||||
_dateTimeController.text = '';
|
||||
|
||||
_updateUrl();
|
||||
},
|
||||
@@ -142,18 +160,24 @@ class _InputFields extends State<InputFields> {
|
||||
|
||||
void _updateUrl() {
|
||||
final params = <String, String>{
|
||||
if (_name != null && _name != '') 'name': _name!,
|
||||
if (_amountMin != null) 'amountMin': _amountMin!.toString(),
|
||||
if (_amountMax != null) 'amountMax': _amountMax!.toString(),
|
||||
if (_nameController.text != '') 'name': _nameController.text,
|
||||
if (_amountMinController.text != '')
|
||||
'amountMin': _amountMinController.text,
|
||||
if (_amountMaxController.text != '')
|
||||
'amountMax': _amountMaxController.text,
|
||||
};
|
||||
|
||||
if (_dateTimeRange != null) {
|
||||
params['dateFrom'] = _dateTimeRange!.start.toIso8601String();
|
||||
params['dateTo'] = _dateTimeRange!.end.toIso8601String();
|
||||
if (_dateTimeController.text != '') {
|
||||
final DateTimeRange<DateTime>? range = DateService.stringToDateTimeRange(
|
||||
_dateTimeController.text,
|
||||
);
|
||||
|
||||
if (range != null) {
|
||||
params['dateFrom'] = range.start.toIso8601String();
|
||||
params['dateTo'] = range.end.toIso8601String();
|
||||
}
|
||||
}
|
||||
|
||||
Routemaster.of(context).replace('/trend', queryParameters: params);
|
||||
|
||||
widget.onChanged?.call();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +62,9 @@ class _TransactionListState extends State<TransactionList> {
|
||||
amountMin: widget.amountMin,
|
||||
amountMax: widget.amountMax,
|
||||
dateFrom: widget.dateFrom,
|
||||
dateTo: widget.dateTo,
|
||||
dateTo: (widget.dateTo != null) ? widget.dateTo : DateTime.now(),
|
||||
account: _accountController.selected.value,
|
||||
orderBy: 'dateDesc',
|
||||
),
|
||||
builder:
|
||||
(
|
||||
|
||||
@@ -44,9 +44,6 @@ class _TrendState extends State<Trend> {
|
||||
amountMax: amountMax,
|
||||
dateFrom: dateFrom,
|
||||
dateTo: dateTo,
|
||||
onChanged: () {
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user