2025-02-06 15:04:04 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
2024-11-10 21:48:42 +08:00
|
|
|
import 'package:collection/collection.dart';
|
2024-11-10 12:41:56 +08:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2025-02-06 15:04:04 +08:00
|
|
|
import 'package:flutter/foundation.dart';
|
2024-11-10 12:41:56 +08:00
|
|
|
import 'package:flutter/gestures.dart';
|
2024-11-10 01:34:58 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2025-02-06 15:04:04 +08:00
|
|
|
import 'package:flutter/services.dart';
|
2025-02-10 11:51:42 +08:00
|
|
|
import 'package:flutter_context_menu/flutter_context_menu.dart';
|
2024-11-10 12:41:56 +08:00
|
|
|
import 'package:gap/gap.dart';
|
2025-02-15 00:36:55 +08:00
|
|
|
import 'package:go_router/go_router.dart';
|
2025-02-06 15:04:04 +08:00
|
|
|
import 'package:hotkey_manager/hotkey_manager.dart';
|
2024-11-10 12:41:56 +08:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2025-02-06 15:04:04 +08:00
|
|
|
import 'package:pasteboard/pasteboard.dart';
|
2025-02-07 20:19:48 +08:00
|
|
|
import 'package:responsive_framework/responsive_framework.dart';
|
2024-11-10 12:41:56 +08:00
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
2024-11-11 21:30:05 +08:00
|
|
|
import 'package:surface/controllers/post_write_controller.dart';
|
2024-12-22 01:29:16 +08:00
|
|
|
import 'package:surface/providers/config.dart';
|
2025-02-10 11:51:42 +08:00
|
|
|
import 'package:surface/providers/sn_attachment.dart';
|
2024-11-10 12:41:56 +08:00
|
|
|
import 'package:surface/providers/sn_network.dart';
|
2025-02-07 20:19:48 +08:00
|
|
|
import 'package:surface/types/attachment.dart';
|
2024-11-10 12:41:56 +08:00
|
|
|
import 'package:surface/types/post.dart';
|
|
|
|
import 'package:surface/widgets/account/account_image.dart';
|
2025-02-12 23:56:45 +08:00
|
|
|
import 'package:surface/widgets/attachment/attachment_input.dart';
|
2025-02-10 00:44:52 +08:00
|
|
|
import 'package:surface/widgets/attachment/attachment_item.dart';
|
2025-02-10 11:51:42 +08:00
|
|
|
import 'package:surface/widgets/attachment/pending_attachment_alt.dart';
|
|
|
|
import 'package:surface/widgets/attachment/pending_attachment_boost.dart';
|
2024-11-10 18:37:34 +08:00
|
|
|
import 'package:surface/widgets/loading_indicator.dart';
|
2025-02-07 20:19:48 +08:00
|
|
|
import 'package:surface/widgets/markdown_content.dart';
|
2025-01-21 20:35:04 +08:00
|
|
|
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
2024-11-10 16:41:11 +08:00
|
|
|
import 'package:surface/widgets/post/post_media_pending_list.dart';
|
2024-11-10 12:41:56 +08:00
|
|
|
import 'package:surface/widgets/post/post_meta_editor.dart';
|
2024-11-10 16:41:11 +08:00
|
|
|
import 'package:surface/widgets/dialog.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2025-02-13 22:35:53 +08:00
|
|
|
import 'package:surface/widgets/post/post_poll_editor.dart';
|
2025-02-10 00:44:52 +08:00
|
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
|
2025-01-31 22:52:21 +08:00
|
|
|
class PostEditorExtra {
|
2024-12-15 12:59:18 +08:00
|
|
|
final String? text;
|
|
|
|
final String? title;
|
|
|
|
final String? description;
|
|
|
|
final List<PostWriteMedia>? attachments;
|
|
|
|
|
2025-01-31 22:52:21 +08:00
|
|
|
const PostEditorExtra({
|
2024-12-15 12:59:18 +08:00
|
|
|
this.text,
|
|
|
|
this.title,
|
|
|
|
this.description,
|
|
|
|
this.attachments,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-10 12:41:56 +08:00
|
|
|
class PostEditorScreen extends StatefulWidget {
|
|
|
|
final String mode;
|
2024-11-10 18:37:34 +08:00
|
|
|
final int? postEditId;
|
|
|
|
final int? postReplyId;
|
|
|
|
final int? postRepostId;
|
2025-01-31 22:52:21 +08:00
|
|
|
final PostEditorExtra? extraProps;
|
2024-12-07 17:43:44 +08:00
|
|
|
|
2024-11-10 18:37:34 +08:00
|
|
|
const PostEditorScreen({
|
|
|
|
super.key,
|
|
|
|
required this.mode,
|
|
|
|
required this.postEditId,
|
|
|
|
required this.postReplyId,
|
|
|
|
required this.postRepostId,
|
2024-12-15 12:59:18 +08:00
|
|
|
this.extraProps,
|
2024-11-10 18:37:34 +08:00
|
|
|
});
|
2024-11-10 12:41:56 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<PostEditorScreen> createState() => _PostEditorScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostEditorScreenState extends State<PostEditorScreen> {
|
2025-01-06 22:12:10 +08:00
|
|
|
late final PostWriteController _writeController = PostWriteController(
|
|
|
|
doLoadFromTemporary: widget.postEditId == null,
|
|
|
|
);
|
2024-11-10 12:41:56 +08:00
|
|
|
|
2024-11-11 21:30:05 +08:00
|
|
|
bool _isFetching = false;
|
2024-12-07 17:43:44 +08:00
|
|
|
|
2024-11-11 21:30:05 +08:00
|
|
|
bool get _isLoading => _isFetching || _writeController.isLoading;
|
2024-11-10 12:41:56 +08:00
|
|
|
|
|
|
|
List<SnPublisher>? _publishers;
|
|
|
|
|
2024-11-10 18:37:34 +08:00
|
|
|
Future<void> _fetchPublishers() async {
|
2024-11-11 21:30:05 +08:00
|
|
|
setState(() => _isFetching = true);
|
2024-11-10 16:52:24 +08:00
|
|
|
|
2024-11-10 12:41:56 +08:00
|
|
|
try {
|
2024-11-11 21:30:05 +08:00
|
|
|
final sn = context.read<SnNetworkProvider>();
|
2024-12-22 01:29:16 +08:00
|
|
|
final config = context.read<ConfigProvider>();
|
2024-12-12 00:08:48 +08:00
|
|
|
final resp = await sn.client.get('/cgi/co/publishers/me');
|
2024-11-11 21:30:05 +08:00
|
|
|
_publishers = List<SnPublisher>.from(
|
|
|
|
resp.data?.map((e) => SnPublisher.fromJson(e)) ?? [],
|
2024-11-10 18:37:34 +08:00
|
|
|
);
|
2024-12-22 01:29:16 +08:00
|
|
|
final beforeId = config.prefs.getInt('int_last_publisher_id');
|
2025-02-15 00:36:55 +08:00
|
|
|
_writeController.setPublisher(
|
|
|
|
_publishers?.where((ele) => ele.id == beforeId).firstOrNull ??
|
|
|
|
_publishers?.firstOrNull);
|
2024-11-10 12:41:56 +08:00
|
|
|
} catch (err) {
|
2024-11-10 16:52:24 +08:00
|
|
|
if (!mounted) return;
|
2024-11-10 12:41:56 +08:00
|
|
|
context.showErrorDialog(err);
|
|
|
|
} finally {
|
2024-11-11 21:30:05 +08:00
|
|
|
setState(() => _isFetching = false);
|
2024-11-10 12:41:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _updateMeta() {
|
2024-11-11 21:30:05 +08:00
|
|
|
showModalBottomSheet(
|
2024-11-10 12:41:56 +08:00
|
|
|
context: context,
|
2024-11-11 21:30:05 +08:00
|
|
|
builder: (context) => PostMetaEditor(controller: _writeController),
|
2024-11-10 12:41:56 +08:00
|
|
|
useRootNavigator: true,
|
2024-11-11 21:30:05 +08:00
|
|
|
);
|
2024-11-10 12:41:56 +08:00
|
|
|
}
|
|
|
|
|
2025-02-06 15:04:04 +08:00
|
|
|
final HotKey _pasteHotKey = HotKey(
|
|
|
|
key: PhysicalKeyboardKey.keyV,
|
2025-02-15 13:06:25 +08:00
|
|
|
modifiers: [(!kIsWeb && Platform.isMacOS) ? HotKeyModifier.meta : HotKeyModifier.control],
|
2025-02-06 15:04:04 +08:00
|
|
|
scope: HotKeyScope.inapp,
|
|
|
|
);
|
|
|
|
|
|
|
|
void _registerHotKey() {
|
|
|
|
if (kIsWeb || Platform.isAndroid || Platform.isIOS) return;
|
|
|
|
hotKeyManager.register(_pasteHotKey, keyDownHandler: (_) async {
|
|
|
|
final imageBytes = await Pasteboard.image;
|
|
|
|
if (imageBytes == null) return;
|
|
|
|
_writeController.addAttachments([
|
|
|
|
PostWriteMedia.fromBytes(
|
|
|
|
imageBytes,
|
|
|
|
'attachmentPastedImage'.tr(),
|
|
|
|
SnMediaType.image,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-02-07 22:35:04 +08:00
|
|
|
void _showPublisherPopup() {
|
|
|
|
showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => _PostPublisherPopup(
|
|
|
|
controller: _writeController,
|
|
|
|
publishers: _publishers,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-02-12 23:56:45 +08:00
|
|
|
void _showPollEditorDialog() async {
|
|
|
|
final poll = await showDialog<dynamic>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => PollEditorDialog(
|
|
|
|
poll: _writeController.poll,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
if (poll == null) return;
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
if (poll == false) {
|
|
|
|
_writeController.setPoll(null);
|
|
|
|
} else {
|
|
|
|
_writeController.setPoll(poll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-10 12:41:56 +08:00
|
|
|
@override
|
|
|
|
void dispose() {
|
2024-11-11 21:30:05 +08:00
|
|
|
_writeController.dispose();
|
2025-02-15 00:36:55 +08:00
|
|
|
if (!kIsWeb && !(Platform.isAndroid || Platform.isIOS))
|
|
|
|
hotKeyManager.unregister(_pasteHotKey);
|
2024-11-10 12:41:56 +08:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2025-02-06 15:04:04 +08:00
|
|
|
_registerHotKey();
|
2024-11-11 21:30:05 +08:00
|
|
|
if (!PostWriteController.kTitleMap.keys.contains(widget.mode)) {
|
2024-11-10 12:41:56 +08:00
|
|
|
context.showErrorDialog('Unknown post type');
|
|
|
|
Navigator.pop(context);
|
2024-12-07 17:43:44 +08:00
|
|
|
} else {
|
|
|
|
_writeController.setMode(widget.mode);
|
2024-11-10 12:41:56 +08:00
|
|
|
}
|
|
|
|
_fetchPublishers();
|
2024-11-11 21:30:05 +08:00
|
|
|
_writeController.fetchRelatedPost(
|
|
|
|
context,
|
|
|
|
editing: widget.postEditId,
|
|
|
|
replying: widget.postReplyId,
|
|
|
|
reposting: widget.postRepostId,
|
|
|
|
);
|
2024-12-15 12:59:18 +08:00
|
|
|
if (widget.extraProps != null) {
|
|
|
|
_writeController.contentController.text = widget.extraProps!.text ?? '';
|
|
|
|
_writeController.titleController.text = widget.extraProps!.title ?? '';
|
2025-02-15 00:36:55 +08:00
|
|
|
_writeController.descriptionController.text =
|
|
|
|
widget.extraProps!.description ?? '';
|
2024-12-15 12:59:18 +08:00
|
|
|
_writeController.addAttachments(widget.extraProps!.attachments ?? []);
|
|
|
|
}
|
2024-11-10 12:41:56 +08:00
|
|
|
}
|
2024-11-10 01:34:58 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-11 21:30:05 +08:00
|
|
|
return ListenableBuilder(
|
|
|
|
listenable: _writeController,
|
|
|
|
builder: (context, _) {
|
2025-01-21 20:35:04 +08:00
|
|
|
return AppScaffold(
|
2024-11-11 21:30:05 +08:00
|
|
|
appBar: AppBar(
|
|
|
|
leading: BackButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
),
|
2024-11-25 00:05:49 +08:00
|
|
|
title: RichText(
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
text: TextSpan(children: [
|
|
|
|
TextSpan(
|
2025-02-15 00:36:55 +08:00
|
|
|
text: _writeController.title.isNotEmpty
|
|
|
|
? _writeController.title
|
|
|
|
: 'untitled'.tr(),
|
2024-12-12 22:33:10 +08:00
|
|
|
style: Theme.of(context).textTheme.titleLarge!.copyWith(
|
2024-12-15 12:59:18 +08:00
|
|
|
color: Theme.of(context).appBarTheme.foregroundColor!,
|
|
|
|
),
|
2024-11-25 00:05:49 +08:00
|
|
|
),
|
|
|
|
const TextSpan(text: '\n'),
|
|
|
|
TextSpan(
|
2024-11-27 00:06:11 +08:00
|
|
|
text: PostWriteController.kTitleMap[widget.mode]!.tr(),
|
2024-12-12 22:33:10 +08:00
|
|
|
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
2024-12-15 12:59:18 +08:00
|
|
|
color: Theme.of(context).appBarTheme.foregroundColor!,
|
|
|
|
),
|
2024-11-25 00:05:49 +08:00
|
|
|
),
|
|
|
|
]),
|
2025-02-04 22:04:50 +08:00
|
|
|
maxLines: 2,
|
2024-11-25 00:05:49 +08:00
|
|
|
),
|
2024-11-11 21:30:05 +08:00
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Symbols.tune),
|
|
|
|
onPressed: _writeController.isBusy ? null : _updateMeta,
|
|
|
|
),
|
2024-11-24 20:23:06 +08:00
|
|
|
const Gap(8),
|
2024-11-11 21:30:05 +08:00
|
|
|
],
|
2024-11-10 12:41:56 +08:00
|
|
|
),
|
2024-11-11 21:30:05 +08:00
|
|
|
body: Column(
|
|
|
|
children: [
|
2025-02-07 22:35:04 +08:00
|
|
|
if (_writeController.editingPost != null)
|
|
|
|
Container(
|
2025-02-15 00:36:55 +08:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 4, bottom: 4, left: 20, right: 20),
|
2025-02-07 22:35:04 +08:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(
|
|
|
|
color: Theme.of(context).dividerColor,
|
|
|
|
width: 1 / MediaQuery.of(context).devicePixelRatio,
|
2024-11-11 21:30:05 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2025-02-07 22:35:04 +08:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.edit, size: 16),
|
|
|
|
const Gap(10),
|
2025-02-15 00:36:55 +08:00
|
|
|
Text('postEditingNotice').tr(args: [
|
|
|
|
'@${_writeController.editingPost!.publisher.name}'
|
|
|
|
]),
|
2025-02-07 22:35:04 +08:00
|
|
|
],
|
2024-11-11 21:30:05 +08:00
|
|
|
),
|
2024-11-10 12:41:56 +08:00
|
|
|
),
|
2024-11-11 21:30:05 +08:00
|
|
|
Expanded(
|
2025-02-04 22:04:50 +08:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
SingleChildScrollView(
|
|
|
|
padding: EdgeInsets.only(bottom: 160),
|
2025-02-12 23:56:45 +08:00
|
|
|
child: StyledWidget(switch (_writeController.mode) {
|
2025-02-07 22:35:04 +08:00
|
|
|
'stories' => _PostStoryEditor(
|
|
|
|
controller: _writeController,
|
|
|
|
onTapPublisher: _showPublisherPopup,
|
|
|
|
),
|
|
|
|
'articles' => _PostArticleEditor(
|
|
|
|
controller: _writeController,
|
|
|
|
onTapPublisher: _showPublisherPopup,
|
|
|
|
),
|
2025-02-08 01:35:27 +08:00
|
|
|
'questions' => _PostQuestionEditor(
|
|
|
|
controller: _writeController,
|
|
|
|
onTapPublisher: _showPublisherPopup,
|
|
|
|
),
|
2025-02-10 00:44:52 +08:00
|
|
|
'videos' => _PostVideoEditor(
|
|
|
|
controller: _writeController,
|
|
|
|
onTapPublisher: _showPublisherPopup,
|
|
|
|
),
|
2025-02-07 22:35:04 +08:00
|
|
|
_ => const Placeholder(),
|
2025-02-12 23:56:45 +08:00
|
|
|
})
|
|
|
|
.padding(top: 8),
|
2025-02-04 22:04:50 +08:00
|
|
|
),
|
2025-02-15 00:36:55 +08:00
|
|
|
if (_writeController.attachments.isNotEmpty ||
|
|
|
|
_writeController.thumbnail != null)
|
2025-02-04 22:04:50 +08:00
|
|
|
Positioned(
|
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
child: PostMediaPendingList(
|
|
|
|
thumbnail: _writeController.thumbnail,
|
|
|
|
attachments: _writeController.attachments,
|
|
|
|
isBusy: _writeController.isBusy,
|
|
|
|
onUpload: (int idx) async {
|
2025-02-15 00:36:55 +08:00
|
|
|
await _writeController.uploadSingleAttachment(
|
|
|
|
context, idx);
|
2025-02-04 22:04:50 +08:00
|
|
|
},
|
|
|
|
onPostSetThumbnail: (int? idx) {
|
|
|
|
_writeController.setThumbnail(idx);
|
|
|
|
},
|
|
|
|
onInsertLink: (int idx) async {
|
|
|
|
_writeController.contentController.text +=
|
|
|
|
'\n';
|
|
|
|
},
|
2025-02-15 00:36:55 +08:00
|
|
|
onUpdate:
|
|
|
|
(int idx, PostWriteMedia updatedMedia) async {
|
2025-02-04 22:04:50 +08:00
|
|
|
_writeController.setIsBusy(true);
|
|
|
|
try {
|
2025-02-15 00:36:55 +08:00
|
|
|
_writeController.setAttachmentAt(
|
|
|
|
idx, updatedMedia);
|
2025-02-04 22:04:50 +08:00
|
|
|
} finally {
|
|
|
|
_writeController.setIsBusy(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onRemove: (int idx) async {
|
|
|
|
_writeController.setIsBusy(true);
|
|
|
|
try {
|
|
|
|
_writeController.removeAttachmentAt(idx);
|
|
|
|
} finally {
|
|
|
|
_writeController.setIsBusy(false);
|
|
|
|
}
|
|
|
|
},
|
2025-02-15 00:36:55 +08:00
|
|
|
onUpdateBusy: (state) =>
|
|
|
|
_writeController.setIsBusy(state),
|
2025-02-04 22:04:50 +08:00
|
|
|
).padding(bottom: 8),
|
|
|
|
),
|
|
|
|
],
|
2024-11-11 21:30:05 +08:00
|
|
|
),
|
2024-11-10 12:41:56 +08:00
|
|
|
),
|
2024-11-11 21:30:05 +08:00
|
|
|
Material(
|
|
|
|
elevation: 2,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-11-10 12:41:56 +08:00
|
|
|
children: [
|
2025-02-15 00:36:55 +08:00
|
|
|
if (_writeController.isBusy &&
|
|
|
|
_writeController.progress != null)
|
2025-01-15 15:19:46 +08:00
|
|
|
TweenAnimationBuilder<double>(
|
|
|
|
tween: Tween(begin: 0, end: _writeController.progress),
|
|
|
|
duration: Duration(milliseconds: 300),
|
2025-02-15 00:36:55 +08:00
|
|
|
builder: (context, value, _) =>
|
|
|
|
LinearProgressIndicator(value: value, minHeight: 2),
|
2025-01-15 15:19:46 +08:00
|
|
|
)
|
|
|
|
else if (_writeController.isBusy)
|
|
|
|
const LinearProgressIndicator(value: null, minHeight: 2),
|
2025-02-12 23:56:45 +08:00
|
|
|
LoadingIndicator(isActive: _isLoading),
|
|
|
|
const Gap(4),
|
2024-12-29 22:27:07 +08:00
|
|
|
Container(
|
|
|
|
child: _writeController.temporaryRestored
|
2024-12-29 23:11:50 +08:00
|
|
|
? Container(
|
2025-02-15 00:36:55 +08:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 4, bottom: 4, left: 28, right: 22),
|
2024-12-29 23:11:50 +08:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(
|
|
|
|
color: Theme.of(context).dividerColor,
|
2025-02-15 00:36:55 +08:00
|
|
|
width: 1 /
|
|
|
|
MediaQuery.of(context).devicePixelRatio,
|
2024-12-29 23:11:50 +08:00
|
|
|
),
|
2024-12-29 22:27:07 +08:00
|
|
|
),
|
2024-12-29 23:11:50 +08:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.restore, size: 20),
|
|
|
|
const Gap(8),
|
2025-02-15 00:36:55 +08:00
|
|
|
Expanded(
|
|
|
|
child:
|
|
|
|
Text('postLocalDraftRestored').tr()),
|
2024-12-29 23:11:50 +08:00
|
|
|
InkWell(
|
|
|
|
child: Text('dialogDismiss').tr(),
|
|
|
|
onTap: () {
|
|
|
|
_writeController.reset();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
))
|
2024-12-29 22:27:07 +08:00
|
|
|
: const SizedBox.shrink(),
|
|
|
|
)
|
2025-02-15 00:36:55 +08:00
|
|
|
.height(_writeController.temporaryRestored ? 32 : 0,
|
|
|
|
animate: true)
|
|
|
|
.animate(const Duration(milliseconds: 300),
|
|
|
|
Curves.fastLinearToSlowEaseIn),
|
2024-11-11 21:30:05 +08:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: ScrollConfiguration(
|
|
|
|
behavior: _PostEditorActionScrollBehavior(),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2024-12-25 00:48:19 +08:00
|
|
|
AddPostMediaButton(
|
|
|
|
onAdd: (items) {
|
|
|
|
setState(() {
|
|
|
|
_writeController.addAttachments(items);
|
|
|
|
});
|
|
|
|
},
|
2024-11-11 21:30:05 +08:00
|
|
|
),
|
2025-02-12 23:56:45 +08:00
|
|
|
if (_writeController.mode == 'stories')
|
|
|
|
IconButton(
|
2025-02-15 00:36:55 +08:00
|
|
|
icon: Icon(Symbols.poll,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.primary),
|
2025-02-12 23:56:45 +08:00
|
|
|
style: ButtonStyle(
|
2025-02-15 00:36:55 +08:00
|
|
|
backgroundColor:
|
|
|
|
_writeController.poll == null
|
|
|
|
? null
|
|
|
|
: WidgetStatePropertyAll(
|
|
|
|
Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.surfaceContainer),
|
2025-02-12 23:56:45 +08:00
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
_showPollEditorDialog();
|
|
|
|
},
|
|
|
|
),
|
2024-11-11 21:30:05 +08:00
|
|
|
],
|
2024-11-10 12:41:56 +08:00
|
|
|
),
|
2024-11-11 21:30:05 +08:00
|
|
|
),
|
2024-11-10 12:41:56 +08:00
|
|
|
),
|
|
|
|
),
|
2024-11-11 21:30:05 +08:00
|
|
|
TextButton.icon(
|
2025-02-15 00:36:55 +08:00
|
|
|
onPressed: (_writeController.isBusy ||
|
|
|
|
_writeController.publisher == null)
|
2024-11-11 21:30:05 +08:00
|
|
|
? null
|
2024-11-11 22:43:09 +08:00
|
|
|
: () {
|
2024-12-22 00:41:41 +08:00
|
|
|
_writeController.sendPost(context).then((_) {
|
2024-11-11 22:43:09 +08:00
|
|
|
if (!context.mounted) return;
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
});
|
|
|
|
},
|
2024-11-11 21:30:05 +08:00
|
|
|
icon: const Icon(Symbols.send),
|
|
|
|
label: Text('postPublish').tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).padding(horizontal: 16),
|
2024-11-10 12:41:56 +08:00
|
|
|
],
|
2024-11-11 21:30:05 +08:00
|
|
|
).padding(
|
2024-12-08 11:37:03 +08:00
|
|
|
bottom: MediaQuery.of(context).padding.bottom + 8,
|
2024-11-11 21:30:05 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-11-10 12:41:56 +08:00
|
|
|
),
|
2024-11-11 21:30:05 +08:00
|
|
|
);
|
|
|
|
},
|
2024-11-10 12:41:56 +08:00
|
|
|
);
|
2024-11-10 01:34:58 +08:00
|
|
|
}
|
|
|
|
}
|
2024-11-10 12:41:56 +08:00
|
|
|
|
|
|
|
class _PostEditorActionScrollBehavior extends MaterialScrollBehavior {
|
|
|
|
@override
|
|
|
|
Set<PointerDeviceKind> get dragDevices => {
|
|
|
|
PointerDeviceKind.touch,
|
|
|
|
PointerDeviceKind.mouse,
|
|
|
|
};
|
|
|
|
}
|
2025-02-07 20:19:48 +08:00
|
|
|
|
2025-02-07 22:35:04 +08:00
|
|
|
class _PostPublisherPopup extends StatelessWidget {
|
|
|
|
final PostWriteController controller;
|
|
|
|
final List<SnPublisher>? publishers;
|
|
|
|
|
|
|
|
const _PostPublisherPopup({required this.controller, this.publishers});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Symbols.face, size: 24),
|
|
|
|
const Gap(16),
|
2025-02-15 00:36:55 +08:00
|
|
|
Text('accountPublishers',
|
|
|
|
style: Theme.of(context).textTheme.titleLarge)
|
|
|
|
.tr(),
|
2025-02-07 22:35:04 +08:00
|
|
|
],
|
|
|
|
).padding(horizontal: 20, top: 16, bottom: 12),
|
2025-02-15 00:36:55 +08:00
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Symbols.add),
|
|
|
|
title: Text('publishersNew').tr(),
|
|
|
|
subtitle: Text('publisherNewSubtitle').tr(),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
onTap: () {
|
|
|
|
GoRouter.of(context).pushNamed('accountPublisherNew');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const Divider(height: 1),
|
2025-02-07 22:35:04 +08:00
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: publishers?.length ?? 0,
|
|
|
|
itemBuilder: (context, idx) {
|
|
|
|
final publisher = publishers![idx];
|
|
|
|
return ListTile(
|
|
|
|
title: Text(publisher.nick),
|
|
|
|
subtitle: Text('@${publisher.name}'),
|
|
|
|
leading: AccountImage(content: publisher.avatar, radius: 18),
|
|
|
|
onTap: () {
|
|
|
|
controller.setPublisher(publisher);
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-07 20:19:48 +08:00
|
|
|
class _PostStoryEditor extends StatelessWidget {
|
|
|
|
final PostWriteController controller;
|
2025-02-07 22:35:04 +08:00
|
|
|
final Function? onTapPublisher;
|
2025-02-07 20:19:48 +08:00
|
|
|
|
2025-02-07 22:35:04 +08:00
|
|
|
const _PostStoryEditor({required this.controller, this.onTapPublisher});
|
2025-02-07 20:19:48 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
2025-02-08 01:35:27 +08:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
2025-02-07 20:19:48 +08:00
|
|
|
constraints: const BoxConstraints(maxWidth: 640),
|
2025-02-07 22:35:04 +08:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Material(
|
2025-02-08 01:35:27 +08:00
|
|
|
elevation: 2,
|
2025-02-07 22:35:04 +08:00
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(24)),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
onTapPublisher?.call();
|
|
|
|
},
|
|
|
|
child: AccountImage(
|
|
|
|
content: controller.publisher?.avatar,
|
|
|
|
),
|
|
|
|
),
|
2025-02-07 20:19:48 +08:00
|
|
|
),
|
2025-02-07 22:35:04 +08:00
|
|
|
Expanded(
|
2025-02-08 01:35:27 +08:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
const Gap(6),
|
|
|
|
TextField(
|
|
|
|
controller: controller.titleController,
|
|
|
|
decoration: InputDecoration.collapsed(
|
|
|
|
hintText: 'fieldPostTitle'.tr(),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
2025-02-15 00:36:55 +08:00
|
|
|
onTapOutside: (_) =>
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus(),
|
2025-02-08 01:35:27 +08:00
|
|
|
).padding(horizontal: 16),
|
|
|
|
const Gap(8),
|
|
|
|
TextField(
|
|
|
|
controller: controller.contentController,
|
|
|
|
maxLines: null,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: 'fieldPostContent'.tr(),
|
|
|
|
hintStyle: TextStyle(fontSize: 14),
|
|
|
|
isCollapsed: true,
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 16,
|
|
|
|
),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
2025-02-15 00:36:55 +08:00
|
|
|
onTapOutside: (_) =>
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus(),
|
2025-02-07 22:35:04 +08:00
|
|
|
),
|
2025-02-08 01:35:27 +08:00
|
|
|
],
|
|
|
|
),
|
2025-02-07 22:35:04 +08:00
|
|
|
),
|
|
|
|
],
|
2025-02-08 01:35:27 +08:00
|
|
|
).padding(bottom: 8),
|
2025-02-07 20:19:48 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostArticleEditor extends StatelessWidget {
|
|
|
|
final PostWriteController controller;
|
2025-02-07 22:35:04 +08:00
|
|
|
final Function? onTapPublisher;
|
2025-02-07 20:19:48 +08:00
|
|
|
|
2025-02-07 22:35:04 +08:00
|
|
|
const _PostArticleEditor({required this.controller, this.onTapPublisher});
|
2025-02-07 20:19:48 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2025-02-07 22:35:04 +08:00
|
|
|
final editorWidgets = <Widget>[
|
|
|
|
Material(
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
|
|
|
child: InkWell(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
AccountImage(content: controller.publisher?.avatar, radius: 20),
|
|
|
|
const Gap(8),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(controller.publisher?.nick ?? 'loading'.tr()).bold(),
|
|
|
|
Text('@${controller.publisher?.name}'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).padding(horizontal: 12, vertical: 8),
|
|
|
|
onTap: () {
|
|
|
|
onTapPublisher?.call();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2025-02-08 01:35:27 +08:00
|
|
|
const Gap(16),
|
2025-02-07 22:35:04 +08:00
|
|
|
TextField(
|
|
|
|
controller: controller.titleController,
|
2025-02-08 01:35:27 +08:00
|
|
|
decoration: InputDecoration.collapsed(
|
|
|
|
hintText: 'fieldPostTitle'.tr(),
|
2025-02-07 22:35:04 +08:00
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
).padding(horizontal: 16),
|
2025-02-08 01:35:27 +08:00
|
|
|
const Gap(8),
|
2025-02-07 22:35:04 +08:00
|
|
|
TextField(
|
|
|
|
controller: controller.descriptionController,
|
2025-02-08 01:35:27 +08:00
|
|
|
decoration: InputDecoration.collapsed(
|
|
|
|
hintText: 'fieldPostDescription'.tr(),
|
2025-02-07 22:35:04 +08:00
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
maxLines: null,
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
).padding(horizontal: 16),
|
2025-02-08 01:35:27 +08:00
|
|
|
const Gap(4),
|
2025-02-07 22:35:04 +08:00
|
|
|
];
|
|
|
|
|
2025-02-07 20:19:48 +08:00
|
|
|
if (ResponsiveBreakpoints.of(context).largerThan(MOBILE)) {
|
|
|
|
return Container(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 640 * 2 + 8),
|
2025-02-07 22:35:04 +08:00
|
|
|
child: Column(
|
2025-02-07 20:19:48 +08:00
|
|
|
children: [
|
2025-02-07 22:35:04 +08:00
|
|
|
...editorWidgets,
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
controller: controller.contentController,
|
|
|
|
maxLines: null,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: 'fieldPostContent'.tr(),
|
|
|
|
hintStyle: TextStyle(fontSize: 14),
|
|
|
|
isCollapsed: true,
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 16,
|
|
|
|
),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
2025-02-15 00:36:55 +08:00
|
|
|
onTapOutside: (_) =>
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus(),
|
2025-02-07 20:19:48 +08:00
|
|
|
),
|
|
|
|
),
|
2025-02-07 22:35:04 +08:00
|
|
|
const Gap(8),
|
|
|
|
Expanded(
|
|
|
|
child: MarkdownTextContent(
|
|
|
|
content: controller.contentController.text,
|
|
|
|
).padding(horizontal: 24),
|
|
|
|
),
|
|
|
|
],
|
2025-02-07 20:19:48 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-02-07 22:35:04 +08:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
...editorWidgets,
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
constraints: const BoxConstraints(maxWidth: 640),
|
|
|
|
child: TextField(
|
|
|
|
controller: controller.contentController,
|
|
|
|
maxLines: null,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: 'fieldPostContent'.tr(),
|
|
|
|
hintStyle: TextStyle(fontSize: 14),
|
|
|
|
isCollapsed: true,
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 16,
|
|
|
|
),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
2025-02-07 20:19:48 +08:00
|
|
|
),
|
|
|
|
),
|
2025-02-07 22:35:04 +08:00
|
|
|
],
|
2025-02-07 20:19:48 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2025-02-08 01:35:27 +08:00
|
|
|
|
|
|
|
class _PostQuestionEditor extends StatelessWidget {
|
|
|
|
final PostWriteController controller;
|
|
|
|
final Function? onTapPublisher;
|
|
|
|
|
|
|
|
const _PostQuestionEditor({required this.controller, this.onTapPublisher});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
constraints: const BoxConstraints(maxWidth: 640),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Material(
|
|
|
|
elevation: 1,
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(24)),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
onTapPublisher?.call();
|
|
|
|
},
|
|
|
|
child: AccountImage(
|
|
|
|
content: controller.publisher?.avatar,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
const Gap(6),
|
|
|
|
TextField(
|
|
|
|
controller: controller.titleController,
|
|
|
|
decoration: InputDecoration.collapsed(
|
|
|
|
hintText: 'fieldPostTitle'.tr(),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
2025-02-15 00:36:55 +08:00
|
|
|
onTapOutside: (_) =>
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus(),
|
2025-02-08 01:35:27 +08:00
|
|
|
).padding(horizontal: 16),
|
|
|
|
const Gap(8),
|
|
|
|
TextField(
|
|
|
|
controller: controller.rewardController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: 'fieldPostQuestionReward'.tr(),
|
|
|
|
suffixText: 'walletCurrencyShort'.tr(),
|
|
|
|
border: InputBorder.none,
|
|
|
|
isCollapsed: true,
|
|
|
|
),
|
2025-02-15 00:36:55 +08:00
|
|
|
onTapOutside: (_) =>
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus(),
|
2025-02-08 01:35:27 +08:00
|
|
|
).padding(horizontal: 16),
|
|
|
|
const Gap(8),
|
|
|
|
TextField(
|
|
|
|
controller: controller.contentController,
|
|
|
|
maxLines: null,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: 'fieldPostContent'.tr(),
|
|
|
|
hintStyle: TextStyle(fontSize: 14),
|
|
|
|
isCollapsed: true,
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 16,
|
|
|
|
),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
2025-02-15 00:36:55 +08:00
|
|
|
onTapOutside: (_) =>
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus(),
|
2025-02-08 01:35:27 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).padding(top: 8),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2025-02-10 00:44:52 +08:00
|
|
|
|
|
|
|
class _PostVideoEditor extends StatelessWidget {
|
|
|
|
final PostWriteController controller;
|
|
|
|
final Function? onTapPublisher;
|
|
|
|
|
|
|
|
const _PostVideoEditor({required this.controller, this.onTapPublisher});
|
|
|
|
|
|
|
|
void _selectVideo(BuildContext context) async {
|
|
|
|
final video = await showDialog<SnAttachment?>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AttachmentInputDialog(
|
|
|
|
title: 'postVideoUpload'.tr(),
|
|
|
|
pool: 'interactive',
|
|
|
|
mediaType: SnMediaType.video,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
if (!context.mounted) return;
|
|
|
|
if (video == null) return;
|
|
|
|
controller.setVideoAttachment(video);
|
|
|
|
}
|
|
|
|
|
2025-02-10 11:51:42 +08:00
|
|
|
void _setAlt(BuildContext context) async {
|
|
|
|
if (controller.videoAttachment == null) return;
|
|
|
|
|
|
|
|
final result = await showDialog<SnAttachment?>(
|
|
|
|
context: context,
|
2025-02-15 00:36:55 +08:00
|
|
|
builder: (context) => PendingAttachmentAltDialog(
|
|
|
|
media: PostWriteMedia(controller.videoAttachment)),
|
2025-02-10 11:51:42 +08:00
|
|
|
);
|
|
|
|
if (result == null) return;
|
|
|
|
|
|
|
|
controller.setVideoAttachment(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _createBoost(BuildContext context) async {
|
|
|
|
if (controller.videoAttachment == null) return;
|
|
|
|
|
|
|
|
final result = await showDialog<SnAttachmentBoost?>(
|
|
|
|
context: context,
|
2025-02-15 00:36:55 +08:00
|
|
|
builder: (context) => PendingAttachmentBoostDialog(
|
|
|
|
media: PostWriteMedia(controller.videoAttachment)),
|
2025-02-10 11:51:42 +08:00
|
|
|
);
|
|
|
|
if (result == null) return;
|
|
|
|
|
|
|
|
final newAttach = controller.videoAttachment!.copyWith(
|
|
|
|
boosts: [...controller.videoAttachment!.boosts, result],
|
|
|
|
);
|
|
|
|
|
|
|
|
controller.setVideoAttachment(newAttach);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _setThumbnail(BuildContext context) async {
|
|
|
|
if (controller.videoAttachment == null) return;
|
|
|
|
|
|
|
|
final thumbnail = await showDialog<SnAttachment?>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AttachmentInputDialog(
|
|
|
|
title: 'attachmentSetThumbnail'.tr(),
|
|
|
|
pool: 'interactive',
|
|
|
|
analyzeNow: true,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
if (thumbnail == null) return;
|
|
|
|
if (!context.mounted) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final attach = context.read<SnAttachmentProvider>();
|
|
|
|
final newAttach = await attach.updateOne(
|
|
|
|
controller.videoAttachment!,
|
|
|
|
thumbnailId: thumbnail.id,
|
|
|
|
);
|
|
|
|
controller.setVideoAttachment(newAttach);
|
|
|
|
} catch (err) {
|
|
|
|
if (!context.mounted) return;
|
|
|
|
context.showErrorDialog(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _deleteAttachment(BuildContext context) async {
|
|
|
|
if (controller.videoAttachment == null) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final sn = context.read<SnNetworkProvider>();
|
2025-02-15 00:36:55 +08:00
|
|
|
await sn.client
|
|
|
|
.delete('/cgi/uc/attachments/${controller.videoAttachment!.id}');
|
2025-02-10 11:51:42 +08:00
|
|
|
controller.setVideoAttachment(null);
|
|
|
|
} catch (err) {
|
|
|
|
if (!context.mounted) return;
|
|
|
|
context.showErrorDialog(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-10 00:44:52 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Material(
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
|
|
|
child: InkWell(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
AccountImage(content: controller.publisher?.avatar, radius: 20),
|
|
|
|
const Gap(8),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(controller.publisher?.nick ?? 'loading'.tr()).bold(),
|
|
|
|
Text('@${controller.publisher?.name}'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).padding(horizontal: 12, vertical: 8),
|
|
|
|
onTap: () {
|
|
|
|
onTapPublisher?.call();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Gap(16),
|
|
|
|
TextField(
|
|
|
|
controller: controller.titleController,
|
|
|
|
decoration: InputDecoration.collapsed(
|
|
|
|
hintText: 'fieldPostTitle'.tr(),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
).padding(horizontal: 16),
|
|
|
|
const Gap(8),
|
|
|
|
TextField(
|
|
|
|
controller: controller.descriptionController,
|
|
|
|
decoration: InputDecoration.collapsed(
|
|
|
|
hintText: 'fieldPostDescription'.tr(),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
maxLines: null,
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
).padding(horizontal: 16),
|
|
|
|
const Gap(12),
|
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.only(left: 16, right: 16),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
border: Border.all(color: Theme.of(context).dividerColor),
|
|
|
|
),
|
2025-02-10 11:51:42 +08:00
|
|
|
child: ContextMenuRegion(
|
|
|
|
contextMenu: ContextMenu(
|
|
|
|
entries: [
|
|
|
|
MenuItem(
|
|
|
|
label: 'attachmentSetAlt'.tr(),
|
|
|
|
icon: Symbols.description,
|
|
|
|
onSelected: () {
|
|
|
|
_setAlt(context);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
MenuItem(
|
|
|
|
label: 'attachmentBoost'.tr(),
|
|
|
|
icon: Symbols.bolt,
|
|
|
|
onSelected: () {
|
|
|
|
_createBoost(context);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
MenuItem(
|
|
|
|
label: 'attachmentSetThumbnail'.tr(),
|
|
|
|
icon: Symbols.image,
|
|
|
|
onSelected: () {
|
|
|
|
_setThumbnail(context);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
MenuItem(
|
|
|
|
label: 'attachmentCopyRandomId'.tr(),
|
|
|
|
icon: Symbols.content_copy,
|
|
|
|
onSelected: () {
|
2025-02-15 00:36:55 +08:00
|
|
|
Clipboard.setData(
|
|
|
|
ClipboardData(text: controller.videoAttachment!.rid));
|
2025-02-10 11:51:42 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
MenuItem(
|
|
|
|
label: 'delete'.tr(),
|
|
|
|
icon: Symbols.delete,
|
|
|
|
onSelected: () => _deleteAttachment(context),
|
|
|
|
),
|
|
|
|
MenuItem(
|
|
|
|
label: 'unlink'.tr(),
|
|
|
|
icon: Symbols.link_off,
|
|
|
|
onSelected: () {
|
|
|
|
controller.setVideoAttachment(null);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
child: InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
2025-02-15 00:36:55 +08:00
|
|
|
onTap: controller.videoAttachment == null
|
|
|
|
? () => _selectVideo(context)
|
|
|
|
: null,
|
2025-02-10 11:51:42 +08:00
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 16 / 9,
|
|
|
|
child: controller.videoAttachment == null
|
|
|
|
? Center(
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Icons.add),
|
|
|
|
const Gap(4),
|
|
|
|
Text('postVideoUpload'.tr()),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
child: AttachmentItem(
|
|
|
|
data: controller.videoAttachment!,
|
|
|
|
heroTag: const Uuid().v4(),
|
|
|
|
),
|
2025-02-10 00:44:52 +08:00
|
|
|
),
|
2025-02-10 11:51:42 +08:00
|
|
|
),
|
2025-02-10 00:44:52 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|