2021-09-11 01:04:15 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:lemmy_api_client/v3.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import '../../pages/full_post/full_post.dart';
|
|
|
|
import '../../util/async_store_listener.dart';
|
2021-09-11 16:26:10 +02:00
|
|
|
import '../../util/extensions/api.dart';
|
2021-09-11 01:04:15 +02:00
|
|
|
import 'post_actions.dart';
|
2021-10-01 23:03:42 +02:00
|
|
|
import 'post_body.dart';
|
2021-09-11 01:04:15 +02:00
|
|
|
import 'post_info_section.dart';
|
|
|
|
import 'post_link_preview.dart';
|
|
|
|
import 'post_media.dart';
|
|
|
|
import 'post_status.dart';
|
|
|
|
import 'post_store.dart';
|
|
|
|
import 'post_title.dart';
|
|
|
|
|
|
|
|
class PostTile extends StatelessWidget {
|
|
|
|
final PostStore postStore;
|
|
|
|
final IsFullPost fullPost;
|
|
|
|
|
|
|
|
const PostTile.fromPostStore(this.postStore, {this.fullPost = true});
|
|
|
|
PostTile.fromPostView(PostView post, {this.fullPost = false})
|
|
|
|
: postStore = PostStore(post);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MultiProvider(
|
|
|
|
providers: [
|
2021-10-18 01:11:04 +02:00
|
|
|
Provider.value(value: postStore),
|
|
|
|
Provider.value(value: fullPost),
|
2021-09-11 01:04:15 +02:00
|
|
|
],
|
|
|
|
builder: (context, child) {
|
|
|
|
return AsyncStoreListener(
|
|
|
|
asyncStore: context.read<PostStore>().savingState,
|
|
|
|
child: AsyncStoreListener(
|
|
|
|
asyncStore: context.read<PostStore>().votingState,
|
2021-09-11 16:26:10 +02:00
|
|
|
child: AsyncStoreListener<BlockedPerson>(
|
2021-09-11 01:04:15 +02:00
|
|
|
asyncStore: context.read<PostStore>().userBlockingState,
|
2021-09-11 16:26:10 +02:00
|
|
|
successMessageBuilder: (context, state) {
|
2021-10-02 18:48:00 +02:00
|
|
|
final name = state.personView.person.preferredName;
|
|
|
|
return state.blocked ? '$name blocked' : '$name unblocked';
|
2021-09-11 16:26:10 +02:00
|
|
|
},
|
|
|
|
child: const _Post(),
|
2021-09-11 01:04:15 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A post overview card
|
2021-10-18 01:11:04 +02:00
|
|
|
class _Post extends StatelessWidget {
|
2021-09-11 01:04:15 +02:00
|
|
|
const _Post();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
final isFullPost = context.read<IsFullPost>();
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
boxShadow: const [BoxShadow(blurRadius: 10, color: Colors.black45)],
|
|
|
|
color: theme.cardColor,
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
|
|
|
),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: isFullPost
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
final postStore = context.read<PostStore>();
|
2021-10-18 01:11:04 +02:00
|
|
|
Navigator.of(context)
|
|
|
|
.push(FullPostPage.fromPostStoreRoute(postStore));
|
2021-09-11 01:04:15 +02:00
|
|
|
},
|
|
|
|
child: Material(
|
|
|
|
type: MaterialType.transparency,
|
|
|
|
child: Column(
|
|
|
|
children: const [
|
|
|
|
PostInfoSection(),
|
|
|
|
PostTitle(),
|
|
|
|
PostMedia(),
|
|
|
|
PostLinkPreview(),
|
2021-10-01 23:03:42 +02:00
|
|
|
PostBody(),
|
2021-09-11 01:04:15 +02:00
|
|
|
PostActions(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|