button to save/unsave

This commit is contained in:
Lea 2023-01-01 00:56:12 +01:00
parent 0d3ca86df9
commit 72f61ea804
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

View file

@ -1,5 +1,6 @@
import 'package:feet/pages/article.dart'; import 'package:feet/pages/article.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../api/api.dart'; import '../api/api.dart';
// TODO use some localization library // TODO use some localization library
@ -42,9 +43,8 @@ class _HomepagePostState extends State<HomepagePost> {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text( content: Text(
'Marking post as ${post.isRead ? 'Unread' : 'Read'}', 'Marking post as ${post.isRead ? 'Unread' : 'Read'}',
style: TextStyle(color: theme.colorScheme.onBackground) style: TextStyle(color: theme.colorScheme.onBackground)),
),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
backgroundColor: theme.colorScheme.secondaryContainer, backgroundColor: theme.colorScheme.secondaryContainer,
), ),
@ -69,6 +69,26 @@ class _HomepagePostState extends State<HomepagePost> {
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: Row( child: Row(
children: [ children: [
GestureDetector(
onTap: () async {
HapticFeedback.lightImpact();
await post.api
.request()
.markItem(
post,
post.isSaved
? ItemMarkType.unsaved
: ItemMarkType.saved)
.execute();
setState(() {});
},
child: Icon(
post.isSaved
? Icons.bookmark
: Icons.bookmark_add_outlined,
color:
post.isSaved ? const Color(0xFFF3A13E) : null),
),
Text('${post.api.cache.feeds.get(post.feedId)?.title}'), Text('${post.api.cache.feeds.get(post.feedId)?.title}'),
const Text(' \u2022 '), const Text(' \u2022 '),
post.author.isNotEmpty post.author.isNotEmpty