import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'sample_data.dart'; /* todo: - individuelle Icons je nach Kategorie - Gesamtpreis */ class ShowBasket extends StatelessWidget { final Transaction transaction; final bool editable; const ShowBasket( {super.key, required this.transaction, this.editable = false}); @override Widget build(BuildContext context) { return Column(children: [ Card( child: ListTile( leading: const Icon( Icons.euro, ), title: const Text( 'Kosten:', ), subtitle: Text( '${transaction.amount / 100}', )), ), getBasket(transaction.basket!) ]); } ListView getBasket(List basket) { return ListView.builder( shrinkWrap: true, itemCount: null, itemBuilder: (context, index) { if (index < basket.length) { return Card( child: ListTile( leading: getLeading(basket[index].products.category), title: Text(basket[index].products.name), subtitle: Text( '${basket[index].amount} ${basket[index].products.unit}'), trailing: editable == true ? getTrailing() : null, ), ); } else { return null; } }, ); } Widget getLeading(Category category) { switch (category) { case Category.obstUndGemuese: return const Text("🍅"); case Category.brotCerealienUndAufstriche: return const Text('🍞'); case Category.drogerieUndHaushalt: case Category.getraenke: case Category.kochenUndBacken: case Category.pfand: case Category.suessesUndKnabbereien: case Category.oeleSossenUndGewuerze: default: return const Icon(Icons.error); } } Widget getTrailing() { return TextField( decoration: const InputDecoration(labelText: "Enter your number"), keyboardType: TextInputType.number, inputFormatters: [ FilteringTextInputFormatter.digitsOnly ], ); } }