parent
bca0dec7bc
commit
7f32ef4bf1
@ -0,0 +1,11 @@ |
|||||||
|
import 'package:flutter/foundation.dart'; |
||||||
|
|
||||||
|
@immutable |
||||||
|
class Product { |
||||||
|
final String title; |
||||||
|
final double price; |
||||||
|
|
||||||
|
String get priceAsString => price.toStringAsFixed(2); |
||||||
|
|
||||||
|
const Product({required this.title, required this.price}); |
||||||
|
} |
@ -1,12 +0,0 @@ |
|||||||
import 'package:flutter/material.dart'; |
|
||||||
|
|
||||||
class ProductListScreen extends StatelessWidget { |
|
||||||
const ProductListScreen({Key? key}) : super(key: key); |
|
||||||
|
|
||||||
@override |
|
||||||
Widget build(BuildContext context) { |
|
||||||
return Scaffold( |
|
||||||
appBar: AppBar(title: const Text('Thesis Shop')), |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,16 @@ |
|||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:thesis_shop/models/product.dart'; |
||||||
|
import 'package:thesis_shop/widgets/number_picker.dart'; |
||||||
|
|
||||||
|
class ProductItem extends StatelessWidget { |
||||||
|
final Product product; |
||||||
|
const ProductItem({Key? key, required this.product}) : super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return ListTile( |
||||||
|
title: Text('${product.title} (${product.priceAsString}€/Stück)'), |
||||||
|
trailing: NumberPicker(value: 5, onUp: () {}, onDown: () {}), |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:thesis_shop/models/product.dart'; |
||||||
|
import 'package:thesis_shop/screens/product_list/product_item.dart'; |
||||||
|
|
||||||
|
const _productPlaceholder = [ |
||||||
|
Product(title: 'Bananen', price: 3), |
||||||
|
Product(title: 'Äpfel', price: 2), |
||||||
|
Product(title: 'Birnen', price: 2.5), |
||||||
|
Product(title: 'Kirschen', price: 1.2), |
||||||
|
]; |
||||||
|
|
||||||
|
class ProductListScreen extends StatelessWidget { |
||||||
|
const ProductListScreen({Key? key}) : super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
const products = _productPlaceholder; |
||||||
|
return Scaffold( |
||||||
|
appBar: AppBar(title: const Text('Thesis Shop')), |
||||||
|
body: ListView.separated( |
||||||
|
itemCount: products.length, |
||||||
|
itemBuilder: (context, index) => ProductItem(product: products[index]), |
||||||
|
separatorBuilder: (context, _) => const Divider(), |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
import 'package:flutter/material.dart'; |
||||||
|
|
||||||
|
class NumberPicker extends StatelessWidget { |
||||||
|
final int value; |
||||||
|
final VoidCallback onUp; |
||||||
|
final VoidCallback onDown; |
||||||
|
final int minValue; |
||||||
|
final int maxValue; |
||||||
|
const NumberPicker({ |
||||||
|
Key? key, |
||||||
|
required this.value, |
||||||
|
required this.onUp, |
||||||
|
required this.onDown, |
||||||
|
this.minValue = 0, |
||||||
|
this.maxValue = 100, |
||||||
|
}) : super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return Row( |
||||||
|
mainAxisSize: MainAxisSize.min, |
||||||
|
crossAxisAlignment: CrossAxisAlignment.center, |
||||||
|
children: [ |
||||||
|
_ConditionalIconButton( |
||||||
|
enabled: value > minValue, onClick: onDown, iconData: Icons.remove), |
||||||
|
Text(value.toString()), |
||||||
|
_ConditionalIconButton( |
||||||
|
enabled: value < maxValue, onClick: onUp, iconData: Icons.add), |
||||||
|
], |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class _ConditionalIconButton extends StatelessWidget { |
||||||
|
final bool enabled; |
||||||
|
final VoidCallback onClick; |
||||||
|
final IconData iconData; |
||||||
|
const _ConditionalIconButton({ |
||||||
|
Key? key, |
||||||
|
required this.enabled, |
||||||
|
required this.onClick, |
||||||
|
required this.iconData, |
||||||
|
}) : super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return IconButton( |
||||||
|
onPressed: enabled ? onClick : null, |
||||||
|
icon: Icon(iconData), |
||||||
|
); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue