1
0
Fork 0

Merge branch 'main' into inheritedwidget

inheritedwidget
Jonas Franz 2 years ago
commit c56cdd1314
  1. 14
      lib/models/cart_item.dart
  2. 29
      lib/screens/cart/cart_item_list.dart
  3. 10
      lib/screens/cart/cart_screen.dart

@ -0,0 +1,14 @@
import 'package:flutter/foundation.dart';
import 'package:thesis_shop/models/product.dart';
@immutable
class CartItem {
final Product product;
final int amount;
double get totalPrice => product.price * amount;
String get totalPriceAsString => totalPrice.toStringAsFixed(2);
const CartItem({required this.product, required this.amount})
: assert(amount >= 0);
}

@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:thesis_shop/models/cart_item.dart';
class CartItemList extends StatelessWidget {
const CartItemList({Key? key}) : super(key: key);
final List<CartItem> items;
const CartItemList({Key? key, required this.items}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -10,17 +12,20 @@ class CartItemList extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Table(
columnWidths: const {
0: FlexColumnWidth(),
1: FixedColumnWidth(128),
2: IntrinsicColumnWidth(),
},
children: const [
TableRow(children: [Text('Äpfel'), Text('3x3€'), Text('9€')]),
TableRow(children: [Text('Äpfel'), Text('3x3€'), Text('9€')]),
TableRow(children: [Text('Äpfel'), Text('3x3€'), Text('9€')])
],
),
columnWidths: const {
0: FlexColumnWidth(),
1: FixedColumnWidth(128),
2: IntrinsicColumnWidth(),
},
children: items
.map(
(item) => TableRow(children: [
Text(item.product.title),
Text("${item.amount}*${item.product.priceAsString}"),
Text('${item.totalPriceAsString}'),
]),
)
.toList()),
),
);
}

@ -1,9 +1,17 @@
import 'package:flutter/material.dart';
import 'package:thesis_shop/models/cart_item.dart';
import 'package:thesis_shop/models/product.dart';
import 'package:thesis_shop/screens/cart/total_price_text.dart';
import 'package:thesis_shop/widgets/user_switch.dart';
import 'cart_item_list.dart';
const _placeHolderItems = [
CartItem(product: Product(title: 'Äpfel', price: 3), amount: 3),
CartItem(product: Product(title: 'Äpfel', price: 3), amount: 3),
CartItem(product: Product(title: 'Äpfel', price: 3), amount: 3),
];
class CartScreen extends StatelessWidget {
const CartScreen({Key? key}) : super(key: key);
@ -17,7 +25,7 @@ class CartScreen extends StatelessWidget {
body: Column(
mainAxisSize: MainAxisSize.max,
children: const [
Expanded(child: CartItemList()),
Expanded(child: CartItemList(items: _placeHolderItems)),
TotalPriceText(),
],
),

Loading…
Cancel
Save