show posts on main page
This commit is contained in:
parent
a2a2928ebc
commit
e610286d69
|
@ -27,7 +27,7 @@ class Feed {
|
|||
title = json['title'];
|
||||
url = json['url'];
|
||||
siteUrl = json['site_url'];
|
||||
isSpark = json['isSpark'] == '1';
|
||||
isSpark = json['isSpark'] == 1;
|
||||
lastUpdatedOnTime = DateTime.fromMillisecondsSinceEpoch(toInt(json['last_updated_on_time']) * 1000);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ class Item {
|
|||
author = json['author'];
|
||||
html = json['html'];
|
||||
url = json['url'];
|
||||
isSaved = json['is_saved'] == '1';
|
||||
isRead = json['is_read'] == '1';
|
||||
isSaved = json['is_saved'] == 1;
|
||||
isRead = json['is_read'] == 1;
|
||||
createdOnTime = DateTime.fromMillisecondsSinceEpoch(toInt(json['created_on_time']) * 1000);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:feet/widgets/homepage_post.dart';
|
||||
import 'package:feet/widgets/login_prompt.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dynamic_color/dynamic_color.dart';
|
||||
|
@ -88,9 +89,28 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.title),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
widget.api.request()
|
||||
.withFeeds()
|
||||
.withGroups()
|
||||
.withItems()
|
||||
.execute()
|
||||
.then((_) { setState(() {}); });
|
||||
},
|
||||
icon: const Icon(Icons.replay_outlined),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: loggedIn
|
||||
? const Center(child: Text('Meep'))
|
||||
? ListView(
|
||||
children: widget.api.cache.items.getAll()
|
||||
.values
|
||||
.map((value) => HomepagePost(post: value))
|
||||
.toList()
|
||||
..sort((a, b) => b.post.createdOnTime.millisecondsSinceEpoch.compareTo(a.post.createdOnTime.millisecondsSinceEpoch)),
|
||||
)
|
||||
: Center(child: LoginPrompt(api: widget.api)),
|
||||
);
|
||||
}
|
||||
|
|
52
lib/widgets/homepage_post.dart
Normal file
52
lib/widgets/homepage_post.dart
Normal file
|
@ -0,0 +1,52 @@
|
|||
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),
|
||||
Row(
|
||||
children: [
|
||||
post.author.isNotEmpty
|
||||
? Text(post.author)
|
||||
: const Text('Unknown author', style: TextStyle(fontStyle: FontStyle.italic)),
|
||||
const Text(' \u2022 '),
|
||||
Text(formatDate(post.createdOnTime)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue