add some props an features
This commit is contained in:
@@ -13,115 +13,155 @@ class BauteilFilamentAuswahl extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Obx(() {
|
||||
final ids = {
|
||||
...controller.filamente.map((item) => item.filamentId),
|
||||
...controller.selectedFilamente.keys,
|
||||
};
|
||||
if (ids.isEmpty) {
|
||||
final ids = controller.selectedFilamente.keys.toList();
|
||||
final availableFilamente = controller.filamente
|
||||
.where(
|
||||
(item) => !controller.selectedFilamente.containsKey(item.filamentId),
|
||||
)
|
||||
.toList();
|
||||
if (controller.filamente.isEmpty && ids.isEmpty) {
|
||||
return const Text(
|
||||
'Erfasse zuerst ein Filament in der Einkaufsverwaltung.',
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: ids.map((id) {
|
||||
final selected = controller.selectedFilamente.containsKey(id);
|
||||
final profiles = controller.profilesFor(id);
|
||||
final available = controller.verfuegbarGramm(id);
|
||||
final checkbox = CheckboxListTile(
|
||||
key: ValueKey('filament-$id'),
|
||||
title: Text(controller.filamentLabel(id)),
|
||||
subtitle: Text(
|
||||
available == null
|
||||
? 'Startgewicht unbekannt'
|
||||
: '${DisplayFormats.number(available)} g verfügbar',
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (availableFilamente.isNotEmpty) ...[
|
||||
DropdownButtonFormField<String>(
|
||||
key: ValueKey(
|
||||
availableFilamente
|
||||
.map((item) => item.filamentId)
|
||||
.toList()
|
||||
.toString(),
|
||||
),
|
||||
isExpanded: true,
|
||||
decoration: const InputDecoration(labelText: 'Filament hinzufügen'),
|
||||
hint: const Text('Filament auswählen'),
|
||||
items: availableFilamente
|
||||
.map(
|
||||
(item) => DropdownMenuItem(
|
||||
value: item.filamentId,
|
||||
child: Text(
|
||||
controller.filamentLabel(item.filamentId),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (id) {
|
||||
if (id != null) controller.toggleFilament(id, true);
|
||||
},
|
||||
),
|
||||
value: selected,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
onChanged: (value) => controller.toggleFilament(id, value ?? false),
|
||||
);
|
||||
final consumption = selected
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: EntryNumberField(
|
||||
controller: controller.verbrauchController(id),
|
||||
label: 'Verbrauch',
|
||||
unit: 'g',
|
||||
validator: InputValidators.positive,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Material(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Column(
|
||||
children: [
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
constraints.maxWidth >= 500 && selected
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(child: checkbox),
|
||||
SizedBox(width: 190, child: consumption),
|
||||
],
|
||||
)
|
||||
: Column(children: [checkbox, if (selected) consumption]),
|
||||
),
|
||||
if (selected && profiles.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: DropdownButtonFormField<String>(
|
||||
key: ValueKey(
|
||||
'profile-$id-${controller.selectedFilamente[id]}',
|
||||
),
|
||||
initialValue:
|
||||
profiles.any(
|
||||
(item) =>
|
||||
item.anwendungId ==
|
||||
controller.selectedFilamente[id],
|
||||
const SizedBox(height: 12),
|
||||
] else if (controller.filamente.isNotEmpty) ...[
|
||||
const Text('Alle Filamente wurden hinzugefügt.'),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
if (ids.isEmpty)
|
||||
const Text(
|
||||
'Noch keine Filamente hinzugefügt.',
|
||||
style: TextStyle(color: AppTheme.muted),
|
||||
),
|
||||
...ids.map((id) {
|
||||
final profiles = controller.profilesFor(id);
|
||||
final available = controller.verfuegbarGramm(id);
|
||||
final filament = ListTile(
|
||||
key: ValueKey('filament-$id'),
|
||||
title: Text(controller.filamentLabel(id)),
|
||||
subtitle: Text(
|
||||
available == null
|
||||
? 'Startgewicht unbekannt'
|
||||
: '${DisplayFormats.number(available)} g verfügbar',
|
||||
),
|
||||
trailing: IconButton(
|
||||
tooltip: 'Filament entfernen',
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => controller.toggleFilament(id, false),
|
||||
),
|
||||
);
|
||||
final consumption = Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: EntryNumberField(
|
||||
controller: controller.verbrauchController(id),
|
||||
label: 'Verbrauch',
|
||||
unit: 'g',
|
||||
validator: InputValidators.positive,
|
||||
),
|
||||
);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Material(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Column(
|
||||
children: [
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
constraints.maxWidth >= 500
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(child: filament),
|
||||
SizedBox(width: 190, child: consumption),
|
||||
],
|
||||
)
|
||||
? controller.selectedFilamente[id]
|
||||
: '',
|
||||
isExpanded: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Verarbeitungsprofil',
|
||||
),
|
||||
items: [
|
||||
const DropdownMenuItem(
|
||||
value: '',
|
||||
child: Text('Ohne Profil'),
|
||||
: Column(children: [filament, consumption]),
|
||||
),
|
||||
if (profiles.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: DropdownButtonFormField<String>(
|
||||
key: ValueKey(
|
||||
'profile-$id-${controller.selectedFilamente[id]}',
|
||||
),
|
||||
...profiles.map(
|
||||
(profile) => DropdownMenuItem(
|
||||
value: profile.anwendungId,
|
||||
child: Text(
|
||||
'${DisplayFormats.number(profile.druckTemperatur)} °C · Bett ${DisplayFormats.number(profile.druckbettTemperatur)} °C · ${DisplayFormats.date(profile.erstelltAm)}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
initialValue:
|
||||
profiles.any(
|
||||
(item) =>
|
||||
item.anwendungId ==
|
||||
controller.selectedFilamente[id],
|
||||
)
|
||||
? controller.selectedFilamente[id]
|
||||
: '',
|
||||
isExpanded: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Verarbeitungsprofil',
|
||||
),
|
||||
items: [
|
||||
const DropdownMenuItem(
|
||||
value: '',
|
||||
child: Text('Ohne Profil'),
|
||||
),
|
||||
...profiles.map(
|
||||
(profile) => DropdownMenuItem(
|
||||
value: profile.anwendungId,
|
||||
child: Text(
|
||||
'${DisplayFormats.number(profile.druckTemperatur)} °C · Bett ${DisplayFormats.number(profile.druckbettTemperatur)} °C · ${DisplayFormats.date(profile.erstelltAm)}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (value) => controller.selectProfile(
|
||||
id,
|
||||
value == '' ? null : value,
|
||||
),
|
||||
],
|
||||
onChanged: (value) => controller.selectProfile(
|
||||
id,
|
||||
value == '' ? null : value,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (selected && profiles.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: Text(
|
||||
'Noch kein Profil. Einstellungen kannst du über das Filament in der Einkaufsübersicht erfassen.',
|
||||
style: TextStyle(color: AppTheme.muted),
|
||||
if (profiles.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: Text(
|
||||
'Noch kein Profil. Einstellungen kannst du über das Filament in der Einkaufsübersicht erfassen.',
|
||||
style: TextStyle(color: AppTheme.muted),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user