Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show user who added item and when #190

Merged
merged 1 commit into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"@addCategory": {},
"addDescriptionFromSource": "Add description from source",
"@addDescriptionFromSource": {},
"addedBy": "Added by {name}",
"@addedBy": {
"placeholders": {
"name": {}
}
},
"addItemTitle": "Add Items",
"@addItemTitle": {},
"addLanguage": "Add Language",
Expand Down
20 changes: 20 additions & 0 deletions lib/models/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,18 @@ class ItemWithDescription extends Item {
}

class ShoppinglistItem extends ItemWithDescription {
final int? createdById;
final DateTime? createdAt;

const ShoppinglistItem({
super.id,
required super.name,
super.description = '',
super.category,
super.icon,
super.ordering = 0,
this.createdById,
this.createdAt,
});

factory ShoppinglistItem.fromJson(Map<String, dynamic> map) {
Expand All @@ -140,6 +145,11 @@ class ShoppinglistItem extends ItemWithDescription {
icon: map['icon'],
category:
map['category'] != null ? Category.fromJson(map['category']) : null,
createdAt: map['created_at'] != null
? DateTime.fromMillisecondsSinceEpoch(map['created_at'], isUtc: true)
.toLocal()
: null,
createdById: map['created_by'],
);
}

Expand Down Expand Up @@ -169,6 +179,16 @@ class ShoppinglistItem extends ItemWithDescription {
description: description ?? this.description,
ordering: ordering,
);

@override
List<Object?> get props => super.props + [createdAt, createdById];

@override
Map<String, dynamic> toJsonWithId() => super.toJsonWithId()
..addAll({
"created_at": createdAt?.toUtc().millisecondsSinceEpoch,
"created_by": createdById,
});
}

class RecipeItem extends ItemWithDescription {
Expand Down
29 changes: 29 additions & 0 deletions lib/pages/item_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import 'package:kitchenowl/app.dart';
import 'package:kitchenowl/cubits/household_cubit.dart';
import 'package:kitchenowl/cubits/item_edit_cubit.dart';
Expand Down Expand Up @@ -218,6 +220,33 @@ class _ItemPageState<T extends Item> extends State<ItemPage<T>> {
),
],
),
if (widget.item is ShoppinglistItem)
ListTile(
contentPadding: EdgeInsets.zero,
title: Text(
AppLocalizations.of(context)!
.addedBy(widget.household?.member
?.firstWhereOrNull(
(e) =>
e.id ==
(widget.item
as ShoppinglistItem)
.createdById,
)
?.name ??
AppLocalizations.of(context)!.other),
),
trailing: (widget.item as ShoppinglistItem)
.createdAt !=
null
? Text(
DateFormat.yMMMEd().add_jm().format(
(widget.item as ShoppinglistItem)
.createdAt!,
),
)
: null,
),
],
),
),
Expand Down