Render replied message!

This commit is contained in:
LittleSheep 2024-04-19 17:51:00 +08:00
parent b257378a82
commit fa7b18fa98
5 changed files with 85 additions and 28 deletions

View File

@ -1,8 +1,10 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:solian/models/pagination.dart'; import 'package:solian/models/pagination.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/utils/service_url.dart'; import 'package:solian/utils/service_url.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
@ -54,13 +56,24 @@ class _ExploreScreenState extends State<ExploreScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final auth = context.read<AuthProvider>();
return IndentWrapper( return IndentWrapper(
noSafeArea: true, noSafeArea: true,
floatingActionButton: FloatingActionButton( floatingActionButton: FutureBuilder(
child: const Icon(Icons.edit), future: auth.isAuthorized(),
onPressed: () async { builder: (context, snapshot) {
final did = await router.pushNamed("posts.moments.editor"); if (snapshot.hasData && snapshot.data!) {
if (did == true) _pagingController.refresh(); return FloatingActionButton(
child: const Icon(Icons.edit),
onPressed: () async {
final did = await router.pushNamed("posts.moments.editor");
if (did == true) _pagingController.refresh();
},
);
} else {
return Container();
}
}, },
), ),
title: AppLocalizations.of(context)!.explore, title: AppLocalizations.of(context)!.explore,
@ -71,9 +84,8 @@ class _ExploreScreenState extends State<ExploreScreen> {
child: Center( child: Center(
child: Container( child: Container(
constraints: const BoxConstraints(maxWidth: 640), constraints: const BoxConstraints(maxWidth: 640),
child: PagedListView<int, Post>.separated( child: PagedListView<int, Post>(
pagingController: _pagingController, pagingController: _pagingController,
separatorBuilder: (context, index) => const Divider(thickness: 0.3),
builderDelegate: PagedChildBuilderDelegate<Post>( builderDelegate: PagedChildBuilderDelegate<Post>(
itemBuilder: (context, item, index) => PostItem( itemBuilder: (context, item, index) => PostItem(
item: item, item: item,

View File

@ -11,7 +11,6 @@ class ChatMessageContent extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Markdown( return Markdown(
selectable: true,
data: item.content, data: item.content,
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),

View File

@ -1,8 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:solian/models/message.dart'; import 'package:solian/models/message.dart';
import 'package:solian/widgets/chat/content.dart'; import 'package:solian/widgets/chat/content.dart';
import 'package:solian/widgets/posts/content/attachment.dart'; import 'package:solian/widgets/posts/content/attachment.dart';
import 'package:timeago/timeago.dart' as timeago; import 'package:timeago/timeago.dart' as timeago;
import 'dart:math' as math;
class ChatMessage extends StatelessWidget { class ChatMessage extends StatelessWidget {
final Message item; final Message item;
@ -21,6 +24,49 @@ class ChatMessage extends StatelessWidget {
} }
} }
Widget renderReply() {
final padding =
underMerged ? const EdgeInsets.only(left: 14, right: 8, top: 4) : const EdgeInsets.only(left: 8, right: 8);
if (item.replyTo != null) {
return Row(
children: [
Container(
padding: padding,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Transform(
alignment: Alignment.center,
transform: Matrix4.rotationY(math.pi),
child: const Icon(Icons.reply, size: 16),
),
const SizedBox(width: 8),
CircleAvatar(
radius: 10,
backgroundImage: NetworkImage(item.replyTo!.sender.account.avatar),
),
]),
),
Expanded(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(right: 12, top: 2),
child: ChatMessageContent(item: item.replyTo!),
),
renderAttachment()
],
),
),
],
);
} else {
return Container();
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final contentPart = Padding( final contentPart = Padding(
@ -48,27 +94,32 @@ class ChatMessage extends StatelessWidget {
const SizedBox(width: 40), const SizedBox(width: 40),
Expanded( Expanded(
child: Column( child: Column(
children: [contentPart, renderAttachment()], children: [renderReply(), contentPart, renderAttachment()],
), ),
), ),
], ],
); );
} else { } else {
return Row( return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
CircleAvatar( renderReply(),
backgroundImage: NetworkImage(item.sender.account.avatar), Row(
), crossAxisAlignment: CrossAxisAlignment.start,
Expanded( children: [
child: Column( CircleAvatar(
crossAxisAlignment: CrossAxisAlignment.start, backgroundImage: NetworkImage(item.sender.account.avatar),
children: [ ),
userinfoPart, Expanded(
contentPart, child: Column(
renderAttachment(), crossAxisAlignment: CrossAxisAlignment.start,
], children: [
), userinfoPart,
contentPart,
renderAttachment(),
],
),
),
],
), ),
], ],
); );

View File

@ -1,13 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:solian/models/message.dart'; import 'package:solian/models/message.dart';
import 'package:solian/models/post.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:solian/screens/posts/comment_editor.dart';
import 'package:solian/widgets/chat/message_deletion.dart'; import 'package:solian/widgets/chat/message_deletion.dart';
import 'package:solian/widgets/posts/item_deletion.dart';
class ChatMessageAction extends StatelessWidget { class ChatMessageAction extends StatelessWidget {
final String channel; final String channel;

View File

@ -3,7 +3,6 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:solian/models/message.dart'; import 'package:solian/models/message.dart';
import 'package:solian/models/post.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/utils/service_url.dart'; import 'package:solian/utils/service_url.dart';