price per item is printed
This commit is contained in:
@@ -77,6 +77,9 @@ class AnwendungController extends GetxController {
|
||||
entry.toJson(),
|
||||
]);
|
||||
anwendungen.assignAll([entry]);
|
||||
if (Get.isRegistered<HomeController>()) {
|
||||
Get.find<HomeController>().loadProfile();
|
||||
}
|
||||
hasError.value = false;
|
||||
message.value = 'Verarbeitungsprofil gespeichert.';
|
||||
} catch (_) {
|
||||
|
||||
@@ -31,6 +31,7 @@ class BauteilController extends GetxController {
|
||||
final minutenController = TextEditingController(text: '0');
|
||||
final gewichtController = TextEditingController();
|
||||
final abfallController = TextEditingController(text: '0');
|
||||
final gesamtpreisController = TextEditingController();
|
||||
final _verbrauchControllers = <String, TextEditingController>{};
|
||||
final filamente = <KaufFilamentModel>[].obs;
|
||||
final profile = <AnwendungModel>[].obs;
|
||||
@@ -224,6 +225,7 @@ class BauteilController extends GetxController {
|
||||
druckdauerMinuten: duration,
|
||||
gewichtGramm: InputValidators.number(gewichtController.text)!,
|
||||
abfallGramm: InputValidators.number(abfallController.text)!,
|
||||
gesamtpreis: InputValidators.number(gesamtpreisController.text),
|
||||
fotoBase64: foto.value == null ? null : base64Encode(foto.value!),
|
||||
filamente: selectedFilamente.entries
|
||||
.map(
|
||||
@@ -268,6 +270,8 @@ class BauteilController extends GetxController {
|
||||
minutenController.text = '${entry.druckdauerMinuten % 60}';
|
||||
gewichtController.text = DisplayFormats.number(entry.gewichtGramm);
|
||||
abfallController.text = DisplayFormats.number(entry.abfallGramm);
|
||||
gesamtpreisController.text =
|
||||
entry.gesamtpreis?.toString().replaceAll('.', ',') ?? '';
|
||||
foto.value = entry.fotoBytes;
|
||||
for (final item in entry.filamente) {
|
||||
verbrauchController(item.filamentId).text = item.verbrauchGramm > 0
|
||||
@@ -342,6 +346,7 @@ class BauteilController extends GetxController {
|
||||
minutenController.text = '0';
|
||||
gewichtController.clear();
|
||||
abfallController.text = '0';
|
||||
gesamtpreisController.clear();
|
||||
selectedFilamente.clear();
|
||||
for (final controller in _verbrauchControllers.values) {
|
||||
controller.clear();
|
||||
@@ -359,6 +364,7 @@ class BauteilController extends GetxController {
|
||||
minutenController.dispose();
|
||||
gewichtController.dispose();
|
||||
abfallController.dispose();
|
||||
gesamtpreisController.dispose();
|
||||
for (final controller in _verbrauchControllers.values) {
|
||||
controller.dispose();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../models/kauf_filament_model.dart';
|
||||
import '../models/bauteil_model.dart';
|
||||
import '../models/anwendung_model.dart';
|
||||
import '../helper/storage_keys.dart';
|
||||
import '../helper/filament_bestand.dart';
|
||||
import '../helper/display_formats.dart';
|
||||
@@ -18,6 +19,16 @@ class HomeController extends GetxController {
|
||||
|
||||
final filamente = <KaufFilamentModel>[].obs;
|
||||
final verbrauch = <String, double>{}.obs;
|
||||
final filamentIdsMitProfil = <String>{}.obs;
|
||||
|
||||
void loadProfile() {
|
||||
filamentIdsMitProfil.assignAll(
|
||||
storage
|
||||
.getModelList(StorageKeys.anwendungen)
|
||||
.map(AnwendungModel.fromJson)
|
||||
.map((profile) => profile.filamentId),
|
||||
);
|
||||
}
|
||||
|
||||
void loadVerbrauch() {
|
||||
verbrauch.assignAll(
|
||||
@@ -133,6 +144,7 @@ class HomeController extends GetxController {
|
||||
|
||||
void loadFilamente() {
|
||||
loadVerbrauch();
|
||||
loadProfile();
|
||||
final data = storage.getModelList(storageKey);
|
||||
|
||||
filamente.assignAll(data.map(KaufFilamentModel.fromJson));
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class DisplayFormats {
|
||||
static String currency(num value) =>
|
||||
NumberFormat.currency(locale: 'de_AT', symbol: '€').format(value);
|
||||
static String number(num value) =>
|
||||
NumberFormat('0.##', 'de_AT').format(value);
|
||||
static String date(DateTime value) =>
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:get_storage/get_storage.dart';
|
||||
|
||||
import 'services/get_storage_services.dart';
|
||||
import 'theme/app_theme.dart';
|
||||
import 'widgets/responsive_viewport.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -26,6 +27,8 @@ class MyApp extends StatelessWidget {
|
||||
title: 'Flutter Filament Verwaltung',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.light,
|
||||
builder: (context, child) =>
|
||||
ResponsiveViewport(child: child ?? const SizedBox.shrink()),
|
||||
initialBinding: SampleBindings(),
|
||||
initialRoute: HomeView.routeName,
|
||||
getPages: SampleRouts.samplePages,
|
||||
|
||||
@@ -71,6 +71,7 @@ class BackupModel {
|
||||
item.druckdauerMinuten <= 0 ||
|
||||
!_positive(item.gewichtGramm) ||
|
||||
!_nonNegative(item.abfallGramm) ||
|
||||
(item.gesamtpreis != null && !_nonNegative(item.gesamtpreis!)) ||
|
||||
item.filamente.isEmpty ||
|
||||
item.filamente.any(
|
||||
(entry) =>
|
||||
|
||||
@@ -34,6 +34,7 @@ class BauteilModel {
|
||||
final int druckdauerMinuten;
|
||||
final double gewichtGramm;
|
||||
final double abfallGramm;
|
||||
final double? gesamtpreis;
|
||||
final List<BauteilFilamentModel> filamente;
|
||||
final String? fotoBase64;
|
||||
|
||||
@@ -46,6 +47,7 @@ class BauteilModel {
|
||||
required this.gewichtGramm,
|
||||
required this.abfallGramm,
|
||||
required this.filamente,
|
||||
this.gesamtpreis,
|
||||
this.fotoBase64,
|
||||
});
|
||||
|
||||
@@ -71,6 +73,7 @@ class BauteilModel {
|
||||
druckdauerMinuten: druckdauerMinuten,
|
||||
gewichtGramm: gewichtGramm,
|
||||
abfallGramm: abfallGramm,
|
||||
gesamtpreis: gesamtpreis,
|
||||
filamente: filamente,
|
||||
fotoBase64: fotoBase64,
|
||||
);
|
||||
@@ -83,6 +86,7 @@ class BauteilModel {
|
||||
'druckdauerMinuten': druckdauerMinuten,
|
||||
'gewichtGramm': gewichtGramm,
|
||||
'abfallGramm': abfallGramm,
|
||||
'gesamtpreis': gesamtpreis,
|
||||
'filamente': filamente.map((item) => item.toJson()).toList(),
|
||||
'fotoBase64': fotoBase64,
|
||||
};
|
||||
@@ -95,6 +99,7 @@ class BauteilModel {
|
||||
druckdauerMinuten: json['druckdauerMinuten'] as int,
|
||||
gewichtGramm: (json['gewichtGramm'] as num).toDouble(),
|
||||
abfallGramm: (json['abfallGramm'] as num).toDouble(),
|
||||
gesamtpreis: (json['gesamtpreis'] as num?)?.toDouble(),
|
||||
fotoBase64: json['fotoBase64'] as String?,
|
||||
filamente: (json['filamente'] as List)
|
||||
.map(
|
||||
|
||||
+23
-10
@@ -6,6 +6,7 @@ import '../models/kauf_filament_model.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../widgets/filament_form.dart';
|
||||
import '../widgets/filament_inventory.dart';
|
||||
import '../widgets/app_version.dart';
|
||||
import 'anwendung_view.dart';
|
||||
import 'bauteil_view.dart';
|
||||
import 'export_view.dart';
|
||||
@@ -27,17 +28,27 @@ class HomeView extends GetView<HomeController> {
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
title: const Row(
|
||||
children: [
|
||||
Icon(Icons.all_inbox_rounded, color: AppTheme.teal, size: 28),
|
||||
SizedBox(width: 12),
|
||||
Flexible(
|
||||
child: Text(
|
||||
'Filamentverwaltung',
|
||||
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w700),
|
||||
title: LayoutBuilder(
|
||||
builder: (context, constraints) => Row(
|
||||
children: [
|
||||
if (constraints.maxWidth >= 260) ...[
|
||||
const Icon(
|
||||
Icons.all_inbox_rounded,
|
||||
color: AppTheme.teal,
|
||||
size: 28,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
],
|
||||
const Flexible(
|
||||
child: Text(
|
||||
'Filamentverwaltung',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
drawer: Drawer(
|
||||
@@ -46,6 +57,8 @@ class HomeView extends GetView<HomeController> {
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
const ListTile(title: Text('Filamentverwaltung')),
|
||||
const AppVersion(),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.import_export),
|
||||
title: const Text('Daten exportieren / importieren'),
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
class AppVersion extends StatefulWidget {
|
||||
const AppVersion({super.key});
|
||||
|
||||
@override
|
||||
State<AppVersion> createState() => _AppVersionState();
|
||||
}
|
||||
|
||||
class _AppVersionState extends State<AppVersion> {
|
||||
late final Future<PackageInfo> _info = PackageInfo.fromPlatform();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => FutureBuilder<PackageInfo>(
|
||||
future: _info,
|
||||
builder: (context, snapshot) {
|
||||
final info = snapshot.data;
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.info_outline),
|
||||
title: Text(info == null ? 'Version' : 'Version ${info.version}'),
|
||||
subtitle: Text(
|
||||
info == null
|
||||
? (snapshot.hasError ? 'Nicht verfügbar' : 'Wird geladen …')
|
||||
: 'Build ${info.buildNumber}',
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -102,6 +102,10 @@ class BauteilCard extends StatelessWidget {
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_detail(DisplayFormats.duration(bauteil.druckdauerMinuten)),
|
||||
if (bauteil.gesamtpreis != null)
|
||||
_detail(
|
||||
'Gesamtpreis ${DisplayFormats.currency(bauteil.gesamtpreis!)}',
|
||||
),
|
||||
_detail(
|
||||
'Bauteil ${DisplayFormats.number(bauteil.gewichtGramm)} g',
|
||||
),
|
||||
|
||||
@@ -64,6 +64,13 @@ class BauteilForm extends StatelessWidget {
|
||||
unit: 'g',
|
||||
validator: InputValidators.nonNegative,
|
||||
),
|
||||
EntryNumberField(
|
||||
controller: controller.gesamtpreisController,
|
||||
label: 'Gesamtpreis (optional)',
|
||||
unit: '€',
|
||||
validator: (value) =>
|
||||
InputValidators.nonNegative(value, optional: true),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
@@ -9,51 +9,58 @@ class BauteilPhotoPicker extends StatelessWidget {
|
||||
final BauteilController controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Obx(
|
||||
() => Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BauteilPhoto(bytes: controller.foto.value),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) => Obx(() {
|
||||
final photo = BauteilPhoto(bytes: controller.foto.value);
|
||||
final controls = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Bauteilfoto (optional)',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
const Text(
|
||||
'Bauteilfoto (optional)',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
OutlinedButton.icon(
|
||||
onPressed:
|
||||
controller.isPickingPhoto.value ||
|
||||
controller.isSaving.value
|
||||
? null
|
||||
: controller.pickPhoto,
|
||||
icon: const Icon(Icons.add_photo_alternate_outlined),
|
||||
label: Text(
|
||||
controller.isPickingPhoto.value
|
||||
? 'Wird geladen …'
|
||||
: 'Foto auswählen',
|
||||
),
|
||||
),
|
||||
if (controller.foto.value != null)
|
||||
TextButton(
|
||||
onPressed: controller.isSaving.value
|
||||
? null
|
||||
: controller.removePhoto,
|
||||
child: const Text('Foto entfernen'),
|
||||
),
|
||||
],
|
||||
OutlinedButton.icon(
|
||||
onPressed:
|
||||
controller.isPickingPhoto.value || controller.isSaving.value
|
||||
? null
|
||||
: controller.pickPhoto,
|
||||
icon: const Icon(Icons.add_photo_alternate_outlined),
|
||||
label: Text(
|
||||
controller.isPickingPhoto.value
|
||||
? 'Wird geladen …'
|
||||
: 'Foto auswählen',
|
||||
),
|
||||
),
|
||||
if (controller.foto.value != null)
|
||||
TextButton(
|
||||
onPressed: controller.isSaving.value
|
||||
? null
|
||||
: controller.removePhoto,
|
||||
child: const Text('Foto entfernen'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
if (constraints.maxWidth < 400) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [photo, const SizedBox(height: 12), controls],
|
||||
);
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
photo,
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: controls),
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ class FilamentCard extends StatelessWidget {
|
||||
required this.onTap,
|
||||
required this.onAction,
|
||||
this.verbrauchGramm = 0,
|
||||
this.hatProfil = false,
|
||||
});
|
||||
|
||||
final KaufFilamentModel filament;
|
||||
final VoidCallback onTap;
|
||||
final ValueChanged<String> onAction;
|
||||
final double verbrauchGramm;
|
||||
final bool hatProfil;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -155,6 +157,11 @@ class FilamentCard extends StatelessWidget {
|
||||
icon: Icons.layers_outlined,
|
||||
),
|
||||
_DetailPill(label: weight, icon: Icons.scale_outlined),
|
||||
if (hatProfil)
|
||||
const _DetailPill(
|
||||
label: 'Profil erstellt',
|
||||
icon: Icons.check_circle_outline,
|
||||
),
|
||||
],
|
||||
),
|
||||
const Padding(
|
||||
|
||||
@@ -32,6 +32,7 @@ class FilamentInventory extends StatelessWidget {
|
||||
sliver: Obx(() {
|
||||
final filamente = controller.filamente.toList();
|
||||
final verbrauch = Map<String, double>.from(controller.verbrauch);
|
||||
final filamentIdsMitProfil = controller.filamentIdsMitProfil.toSet();
|
||||
final total = filamente.fold<double>(
|
||||
0,
|
||||
(sum, item) => sum + item.preis,
|
||||
@@ -144,6 +145,9 @@ class FilamentInventory extends StatelessWidget {
|
||||
key: ValueKey(filament.filamentId),
|
||||
filament: filament,
|
||||
verbrauchGramm: verbrauch[filament.filamentId] ?? 0,
|
||||
hatProfil: filamentIdsMitProfil.contains(
|
||||
filament.filamentId,
|
||||
),
|
||||
onTap: () => onOpen(filament),
|
||||
onAction: (action) => onAction(action, filament),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Keeps the navigator (including dialogs) usable in very narrow browser tabs.
|
||||
/// The native Windows/Linux runners use the same minimum client width.
|
||||
class ResponsiveViewport extends StatelessWidget {
|
||||
const ResponsiveViewport({super.key, required this.child});
|
||||
|
||||
static const minimumWidth = 320.0;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (constraints.maxWidth >= minimumWidth) return child;
|
||||
final media = MediaQuery.of(context);
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
primary: false,
|
||||
child: SizedBox(
|
||||
width: minimumWidth,
|
||||
height: constraints.maxHeight,
|
||||
child: MediaQuery(
|
||||
data: media.copyWith(size: Size(minimumWidth, media.size.height)),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user