feet/lib/widgets/homepage_post.dart

57 lines
2 KiB
Dart
Raw Normal View History

2022-12-29 23:27:35 +00:00
import 'package:flutter/material.dart';
import '../api/api.dart';
// TODO use some localization library
String formatDate(DateTime date) {
return '${date.day}.${date.month}.${date.year}, ${date.hour}:${date.minute < 10 ? '0${date.minute}' : date.minute}';
}
class HomepagePost extends StatelessWidget {
final Item post;
const HomepagePost({ super.key, required this.post });
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 6.0, horizontal: 8.0),
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.secondaryContainer,
),
borderRadius: const BorderRadius.all(Radius.circular(15)),
color: post.isRead
? null
: Theme.of(context).colorScheme.secondaryContainer.withAlpha(150),
),
child: InkWell(
onTap: () {
showDialog(context: context, builder: (context) => SimpleDialog(title: Text(post.title)));
},
borderRadius: const BorderRadius.all(Radius.circular(15)),
child: Container(
margin: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(post.title, style: Theme.of(context).textTheme.titleMedium, overflow: TextOverflow.ellipsis),
2022-12-29 23:44:54 +00:00
ClipRRect(
clipBehavior: Clip.antiAlias,
child: Row(
children: [
Text('${post.api.cache.feeds.get(post.feedId)?.title}'),
const Text(' \u2022 '),
post.author.isNotEmpty
? Text(post.author)
: const Text('Unknown author', style: TextStyle(fontStyle: FontStyle.italic)),
const Text(' \u2022 '),
Text(formatDate(post.createdOnTime)),
],
),
2022-12-29 23:27:35 +00:00
),
],
),
)
),
);
}
}