Initial and done prolly
This commit is contained in:
commit
6f88b9966f
175 changed files with 15445 additions and 0 deletions
105
lib/pages/main/widgets/product_widget.dart
Normal file
105
lib/pages/main/widgets/product_widget.dart
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:groceries_manager/common/icons.dart';
|
||||
import 'package:groceries_manager/db/database.dart';
|
||||
import 'package:groceries_manager/utils/format_datetime_extension.dart';
|
||||
import 'package:groceries_manager/utils/pluralize_int_extension.dart';
|
||||
|
||||
class ProductWidget extends GetWidget {
|
||||
final ProductData prod;
|
||||
final ProductCategoryData cat;
|
||||
final StorageLocationData store;
|
||||
|
||||
final void Function(ProductData) onEditClicked;
|
||||
final void Function(ProductData) onDeleteClicked;
|
||||
final void Function(ProductData) onAddToCartClicked;
|
||||
|
||||
const ProductWidget({
|
||||
super.key,
|
||||
required this.prod,
|
||||
required this.cat,
|
||||
required this.store,
|
||||
required this.onEditClicked,
|
||||
required this.onDeleteClicked,
|
||||
required this.onAddToCartClicked,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print(prod);
|
||||
return Card.outlined(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
bottom: 16,
|
||||
top: 4,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ListTile(
|
||||
key: ValueKey("se-item-${prod.id}"),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(prod.name),
|
||||
subtitle: Text(
|
||||
"Куплено: ${prod.purchaseDate?.simpleDateFormat}\n"
|
||||
"Испортится через ${() {
|
||||
final diff =
|
||||
prod.expiryDate!.difference(DateTime.now());
|
||||
if (diff.inDays == 0) {
|
||||
return diff.inHours.pluralize(
|
||||
name: "час",
|
||||
absent: "часа",
|
||||
absentMul: "часов",
|
||||
);
|
||||
}
|
||||
return (diff.inDays + (diff.inHours > 24 ? 1 : 0))
|
||||
.pluralize(
|
||||
name: "день",
|
||||
absent: "дня",
|
||||
absentMul: "дней",
|
||||
);
|
||||
}()}",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Chip(
|
||||
avatar: Icon(
|
||||
ProductCategoryIcons.fromName(cat.icon).icon,
|
||||
),
|
||||
visualDensity: const VisualDensity(
|
||||
horizontal: -4,
|
||||
vertical: -4,
|
||||
),
|
||||
label: Text(cat.name),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () => onAddToCartClicked(prod),
|
||||
icon: const Icon(Icons.add_shopping_cart),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => onEditClicked(prod),
|
||||
icon: const Icon(Icons.edit),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => onDeleteClicked(prod),
|
||||
icon: const Icon(Icons.delete_forever),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue