256 lines
9.2 KiB
Dart
256 lines
9.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
import '../controller/home_controller.dart';
|
|
import '../theme/app_theme.dart';
|
|
import '../helper/input_validators.dart';
|
|
|
|
class FilamentForm extends StatelessWidget {
|
|
const FilamentForm({super.key, required this.controller});
|
|
|
|
final HomeController controller;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(24),
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.inputSurface,
|
|
borderRadius: BorderRadius.circular(24),
|
|
border: Border.all(color: const Color(0xFFCEE6DF)),
|
|
),
|
|
child: Form(
|
|
key: controller.formKey,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const Row(
|
|
children: [
|
|
Icon(Icons.add_circle_outline, color: AppTheme.teal),
|
|
SizedBox(width: 10),
|
|
Flexible(
|
|
child: Text(
|
|
'EINKAUF ERFASSEN',
|
|
style: TextStyle(
|
|
color: AppTheme.teal,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w700,
|
|
letterSpacing: 1.4,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 14),
|
|
Obx(
|
|
() => Text(
|
|
controller.editingId.value == null
|
|
? 'Neues Filament'
|
|
: 'Filament bearbeiten',
|
|
style: const TextStyle(
|
|
fontSize: 25,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 6),
|
|
const Text(
|
|
'Alle Details zu deinem Einkauf an einem Ort.',
|
|
style: TextStyle(color: AppTheme.muted, height: 1.5),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Obx(
|
|
() => Material(
|
|
color: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
side: const BorderSide(color: Color(0xFFCCDEDA)),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: ListTile(
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 3,
|
|
),
|
|
leading: const Icon(
|
|
Icons.calendar_today_outlined,
|
|
color: AppTheme.teal,
|
|
),
|
|
title: const Text(
|
|
'Kaufdatum',
|
|
style: TextStyle(fontSize: 12, color: AppTheme.muted),
|
|
),
|
|
subtitle: Text(
|
|
DateFormat('dd.MM.yyyy').format(controller.kaufdatum.value),
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: AppTheme.ink,
|
|
),
|
|
),
|
|
trailing: const Icon(
|
|
Icons.expand_more,
|
|
color: AppTheme.muted,
|
|
),
|
|
onTap: () async {
|
|
final date = await showDatePicker(
|
|
context: context,
|
|
initialDate: controller.kaufdatum.value,
|
|
firstDate: DateTime(2000),
|
|
lastDate: DateTime(2100),
|
|
);
|
|
if (date != null) controller.kaufdatum.value = date;
|
|
},
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: controller.haendlerController,
|
|
textCapitalization: TextCapitalization.words,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Händler',
|
|
prefixIcon: Icon(Icons.storefront_outlined),
|
|
),
|
|
validator: (value) => value == null || value.trim().isEmpty
|
|
? 'Händler eingeben'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: controller.markeController,
|
|
textCapitalization: TextCapitalization.words,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Marke',
|
|
prefixIcon: Icon(Icons.sell_outlined),
|
|
),
|
|
validator: (value) => value == null || value.trim().isEmpty
|
|
? 'Marke eingeben'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Obx(
|
|
() => DropdownButtonFormField<String>(
|
|
key: ValueKey(
|
|
'${controller.editingId.value ?? "new"}_${controller.material.value}',
|
|
),
|
|
initialValue: controller.material.value,
|
|
isExpanded: true,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Material',
|
|
prefixIcon: Icon(Icons.layers_outlined),
|
|
),
|
|
items: controller.materialien
|
|
.toSet()
|
|
.map(
|
|
(item) =>
|
|
DropdownMenuItem(value: item, child: Text(item)),
|
|
)
|
|
.toList(),
|
|
onChanged: (value) {
|
|
if (value != null) controller.material.value = value;
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: controller.farbeController,
|
|
textCapitalization: TextCapitalization.words,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Farbe',
|
|
prefixIcon: Icon(Icons.palette_outlined),
|
|
),
|
|
validator: (value) => value == null || value.trim().isEmpty
|
|
? 'Farbe eingeben'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 16),
|
|
LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final fields = [
|
|
TextFormField(
|
|
controller: controller.preisController,
|
|
keyboardType: const TextInputType.numberWithOptions(
|
|
decimal: true,
|
|
),
|
|
decoration: const InputDecoration(
|
|
labelText: 'Preis',
|
|
suffixText: '€',
|
|
),
|
|
validator: (value) {
|
|
final price = double.tryParse(
|
|
(value ?? '').replaceAll(',', '.'),
|
|
);
|
|
return price == null || !price.isFinite || price < 0
|
|
? 'Preis ungültig'
|
|
: null;
|
|
},
|
|
),
|
|
TextFormField(
|
|
controller: controller.gewichtController,
|
|
keyboardType: const TextInputType.numberWithOptions(
|
|
decimal: true,
|
|
),
|
|
decoration: const InputDecoration(
|
|
labelText: 'Startgewicht',
|
|
suffixText: 'g',
|
|
),
|
|
validator: InputValidators.positive,
|
|
),
|
|
];
|
|
if (constraints.maxWidth < 280) {
|
|
return Column(
|
|
children: [
|
|
fields[0],
|
|
const SizedBox(height: 16),
|
|
fields[1],
|
|
],
|
|
);
|
|
}
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(child: fields[0]),
|
|
const SizedBox(width: 12),
|
|
Expanded(child: fields[1]),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 24),
|
|
Obx(
|
|
() => Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
FilledButton.icon(
|
|
onPressed: controller.saveFilament,
|
|
icon: Icon(
|
|
controller.editingId.value == null
|
|
? Icons.add
|
|
: Icons.check,
|
|
),
|
|
label: Text(
|
|
controller.editingId.value == null
|
|
? 'Filament speichern'
|
|
: 'Änderungen speichern',
|
|
),
|
|
),
|
|
if (controller.editingId.value != null) ...[
|
|
const SizedBox(height: 8),
|
|
TextButton.icon(
|
|
onPressed: controller.resetForm,
|
|
icon: const Icon(Icons.close),
|
|
label: const Text('Bearbeitung abbrechen'),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|