Fix: Passt das Verhalten der InputFelder an, dass sich diese wirklich verändern
This commit is contained in:
@@ -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