feet/lib/widgets/homepage_post.dart
2022-12-30 16:43:49 +01:00

63 lines
2.2 KiB
Dart

import 'package:feet/pages/article.dart';
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: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => ArticlePage(article: post)),
);
},
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),
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)),
],
),
),
],
),
)),
);
}
}