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,14 +56,25 @@ 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(
future: auth.isAuthorized(),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data!) {
return FloatingActionButton(
child: const Icon(Icons.edit), child: const Icon(Icons.edit),
onPressed: () async { onPressed: () async {
final did = await router.pushNamed("posts.moments.editor"); final did = await router.pushNamed("posts.moments.editor");
if (did == true) _pagingController.refresh(); if (did == true) _pagingController.refresh();
}, },
);
} else {
return Container();
}
},
), ),
title: AppLocalizations.of(context)!.explore, title: AppLocalizations.of(context)!.explore,
child: RefreshIndicator( child: RefreshIndicator(
@ -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,13 +94,16 @@ 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(
children: [
renderReply(),
Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
CircleAvatar( CircleAvatar(
@ -71,6 +120,8 @@ class ChatMessage extends StatelessWidget {
), ),
), ),
], ],
),
],
); );
} }
} }

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';