mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-17 14:50:12 +08:00
feat: richtextfield
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,506 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/button/icon_button.dart';
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
import 'package:PiliPlus/models/common/image_preview_type.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/models_new/dynamic/dyn_mention/item.dart';
|
||||
import 'package:PiliPlus/models_new/emote/emote.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_emote/emoticon.dart';
|
||||
import 'package:PiliPlus/models_new/upload_bfs/data.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_mention/view.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:chat_bottom_container/chat_bottom_container.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_cropper/image_cropper.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
abstract class CommonPublishPage extends StatefulWidget {
|
||||
const CommonPublishPage({
|
||||
super.key,
|
||||
this.initialValue,
|
||||
this.mentions,
|
||||
this.imageLengthLimit,
|
||||
this.onSave,
|
||||
this.autofocus = true,
|
||||
});
|
||||
|
||||
final String? initialValue;
|
||||
final List<MentionItem>? mentions;
|
||||
final int? imageLengthLimit;
|
||||
final ValueChanged<({String text, List<MentionItem>? mentions})>? onSave;
|
||||
final bool autofocus;
|
||||
}
|
||||
|
||||
abstract class CommonPublishPageState<T extends CommonPublishPage>
|
||||
extends State<T> with WidgetsBindingObserver {
|
||||
late final focusNode = FocusNode();
|
||||
late final controller = ChatBottomPanelContainerController<PanelType>();
|
||||
late final editController = TextEditingController(text: widget.initialValue);
|
||||
|
||||
Rx<PanelType> panelType = PanelType.none.obs;
|
||||
late final RxBool readOnly = false.obs;
|
||||
late final RxBool enablePublish = false.obs;
|
||||
|
||||
late final imagePicker = ImagePicker();
|
||||
late final RxList<String> pathList = <String>[].obs;
|
||||
int get limit => widget.imageLengthLimit ?? 9;
|
||||
|
||||
List<MentionItem>? mentions;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
||||
mentions = widget.mentions;
|
||||
if (widget.initialValue?.trim().isNotEmpty == true) {
|
||||
enablePublish.value = true;
|
||||
}
|
||||
|
||||
if (widget.autofocus) {
|
||||
Future.delayed(const Duration(milliseconds: 300)).whenComplete(() {
|
||||
if (mounted) {
|
||||
focusNode.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
focusNode.dispose();
|
||||
editController.dispose();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _requestFocus() async {
|
||||
await Future.delayed(const Duration(microseconds: 200));
|
||||
focusNode.requestFocus();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
if (mounted &&
|
||||
widget.autofocus &&
|
||||
panelType.value == PanelType.keyboard) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (focusNode.hasFocus) {
|
||||
focusNode.unfocus();
|
||||
_requestFocus();
|
||||
} else {
|
||||
_requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (state == AppLifecycleState.paused) {
|
||||
controller.keepChatPanel();
|
||||
if (focusNode.hasFocus) {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updatePanelType(PanelType type) {
|
||||
final isSwitchToKeyboard = PanelType.keyboard == type;
|
||||
final isSwitchToEmojiPanel = PanelType.emoji == type;
|
||||
bool isUpdated = false;
|
||||
switch (type) {
|
||||
case PanelType.keyboard:
|
||||
updateInputView(isReadOnly: false);
|
||||
break;
|
||||
case PanelType.emoji:
|
||||
isUpdated = updateInputView(isReadOnly: true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
void updatePanelTypeFunc() {
|
||||
controller.updatePanelType(
|
||||
isSwitchToKeyboard
|
||||
? ChatBottomPanelType.keyboard
|
||||
: ChatBottomPanelType.other,
|
||||
data: type,
|
||||
forceHandleFocus: isSwitchToEmojiPanel
|
||||
? ChatBottomHandleFocus.requestFocus
|
||||
: ChatBottomHandleFocus.none,
|
||||
);
|
||||
}
|
||||
|
||||
if (isUpdated) {
|
||||
// Waiting for the input view to update.
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
updatePanelTypeFunc();
|
||||
});
|
||||
} else {
|
||||
updatePanelTypeFunc();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> hidePanel() async {
|
||||
if (focusNode.hasFocus) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
focusNode.unfocus();
|
||||
}
|
||||
updateInputView(isReadOnly: false);
|
||||
if (ChatBottomPanelType.none == controller.currentPanelType) return;
|
||||
controller.updatePanelType(ChatBottomPanelType.none);
|
||||
}
|
||||
|
||||
bool updateInputView({
|
||||
required bool isReadOnly,
|
||||
}) {
|
||||
if (readOnly.value != isReadOnly) {
|
||||
readOnly.value = isReadOnly;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> onPublish() async {
|
||||
feedBack();
|
||||
List<Map<String, dynamic>>? pictures;
|
||||
if (pathList.isNotEmpty) {
|
||||
SmartDialog.showLoading(msg: '正在上传图片...');
|
||||
final cancelToken = CancelToken();
|
||||
try {
|
||||
pictures = await Future.wait<Map<String, dynamic>>(
|
||||
pathList.map((path) async {
|
||||
Map result = await MsgHttp.uploadBfs(
|
||||
path: path,
|
||||
category: 'daily',
|
||||
biz: 'new_dyn',
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
if (!result['status']) throw HttpException(result['msg']);
|
||||
UploadBfsResData data = result['data'];
|
||||
return {
|
||||
'img_width': data.imageWidth,
|
||||
'img_height': data.imageHeight,
|
||||
'img_size': data.imgSize,
|
||||
'img_src': data.imageUrl,
|
||||
};
|
||||
}).toList(),
|
||||
eagerError: true);
|
||||
SmartDialog.dismiss();
|
||||
} on HttpException catch (e) {
|
||||
cancelToken.cancel();
|
||||
SmartDialog.dismiss();
|
||||
SmartDialog.showToast(e.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
onCustomPublish(message: editController.text, pictures: pictures);
|
||||
}
|
||||
|
||||
Future<void> onCustomPublish({required String message, List? pictures});
|
||||
|
||||
void onChooseEmote(dynamic emote) {
|
||||
if (emote is Emote) {
|
||||
onInsertText(emote.text!);
|
||||
} else if (emote is Emoticon) {
|
||||
onInsertText(emote.emoji!);
|
||||
}
|
||||
}
|
||||
|
||||
Widget? get customPanel => null;
|
||||
|
||||
Widget buildEmojiPickerPanel() {
|
||||
double height = context.isTablet ? 300 : 170;
|
||||
final keyboardHeight = controller.keyboardHeight;
|
||||
if (keyboardHeight != 0) {
|
||||
height = max(height, keyboardHeight);
|
||||
}
|
||||
return SizedBox(
|
||||
height: height,
|
||||
child: customPanel,
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildPanelContainer([Color? panelBgColor]) {
|
||||
return ChatBottomPanelContainer<PanelType>(
|
||||
controller: controller,
|
||||
inputFocusNode: focusNode,
|
||||
otherPanelWidget: (type) {
|
||||
if (type == null) return const SizedBox.shrink();
|
||||
switch (type) {
|
||||
case PanelType.emoji:
|
||||
return buildEmojiPickerPanel();
|
||||
default:
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
onPanelTypeChange: (panelType, data) {
|
||||
// if (kDebugMode) debugPrint('panelType: $panelType');
|
||||
switch (panelType) {
|
||||
case ChatBottomPanelType.none:
|
||||
this.panelType.value = PanelType.none;
|
||||
break;
|
||||
case ChatBottomPanelType.keyboard:
|
||||
this.panelType.value = PanelType.keyboard;
|
||||
break;
|
||||
case ChatBottomPanelType.other:
|
||||
if (data == null) return;
|
||||
switch (data) {
|
||||
case PanelType.emoji:
|
||||
this.panelType.value = PanelType.emoji;
|
||||
break;
|
||||
default:
|
||||
this.panelType.value = PanelType.none;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
panelBgColor: panelBgColor ?? Theme.of(context).colorScheme.surface,
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildImage(int index, double height) {
|
||||
final color =
|
||||
Theme.of(context).colorScheme.secondaryContainer.withValues(alpha: 0.5);
|
||||
|
||||
void onClear() {
|
||||
pathList.removeAt(index);
|
||||
if (pathList.isEmpty && editController.text.trim().isEmpty) {
|
||||
enablePublish.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
controller.keepChatPanel();
|
||||
context.imageView(
|
||||
imgList: pathList
|
||||
.map((path) => SourceModel(
|
||||
url: path,
|
||||
sourceType: SourceType.fileImage,
|
||||
))
|
||||
.toList(),
|
||||
initialPage: index,
|
||||
);
|
||||
},
|
||||
onLongPress: onClear,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(4)),
|
||||
child: Image(
|
||||
height: height,
|
||||
fit: BoxFit.fitHeight,
|
||||
filterQuality: FilterQuality.low,
|
||||
image: FileImage(File(pathList[index])),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 34,
|
||||
right: 5,
|
||||
child: iconButton(
|
||||
context: context,
|
||||
icon: Icons.edit,
|
||||
onPressed: () => onCropImage(index),
|
||||
size: 24,
|
||||
iconSize: 14,
|
||||
bgColor: color,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 5,
|
||||
right: 5,
|
||||
child: iconButton(
|
||||
context: context,
|
||||
icon: Icons.clear,
|
||||
onPressed: onClear,
|
||||
size: 24,
|
||||
iconSize: 14,
|
||||
bgColor: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> onCropImage(int index) async {
|
||||
final theme = Theme.of(context);
|
||||
CroppedFile? croppedFile = await ImageCropper().cropImage(
|
||||
sourcePath: pathList[index],
|
||||
uiSettings: [
|
||||
AndroidUiSettings(
|
||||
toolbarTitle: '裁剪',
|
||||
toolbarColor: theme.colorScheme.secondaryContainer,
|
||||
toolbarWidgetColor: theme.colorScheme.onSecondaryContainer,
|
||||
),
|
||||
IOSUiSettings(
|
||||
title: '裁剪',
|
||||
),
|
||||
],
|
||||
);
|
||||
if (croppedFile != null) {
|
||||
pathList[index] = croppedFile.path;
|
||||
}
|
||||
}
|
||||
|
||||
void onPickImage([VoidCallback? callback]) {
|
||||
EasyThrottle.throttle('imagePicker', const Duration(milliseconds: 500),
|
||||
() async {
|
||||
try {
|
||||
List<XFile> pickedFiles = await imagePicker.pickMultiImage(
|
||||
limit: limit,
|
||||
imageQuality: 100,
|
||||
);
|
||||
if (pickedFiles.isNotEmpty) {
|
||||
for (int i = 0; i < pickedFiles.length; i++) {
|
||||
if (pathList.length == limit) {
|
||||
SmartDialog.showToast('最多选择$limit张图片');
|
||||
break;
|
||||
} else {
|
||||
pathList.add(pickedFiles[i].path);
|
||||
}
|
||||
}
|
||||
callback?.call();
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast(e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>>? getRichContent() {
|
||||
if (mentions.isNullOrEmpty) {
|
||||
return null;
|
||||
}
|
||||
List<Map<String, dynamic>> content = [];
|
||||
void addPlainText(String text) {
|
||||
content.add({
|
||||
"raw_text": text,
|
||||
"type": 1,
|
||||
"biz_id": "",
|
||||
});
|
||||
}
|
||||
|
||||
final pattern = RegExp(
|
||||
mentions!.toSet().map((e) => RegExp.escape('@${e.name!}')).join('|'));
|
||||
|
||||
editController.text.splitMapJoin(
|
||||
pattern,
|
||||
onMatch: (Match match) {
|
||||
final name = match.group(0)!;
|
||||
final item =
|
||||
mentions!.firstWhereOrNull((e) => e.name == name.substring(1));
|
||||
if (item != null) {
|
||||
content.add({
|
||||
"raw_text": name,
|
||||
"type": 2,
|
||||
"biz_id": item.uid,
|
||||
});
|
||||
} else {
|
||||
addPlainText(name);
|
||||
}
|
||||
return '';
|
||||
},
|
||||
onNonMatch: (String text) {
|
||||
addPlainText(text);
|
||||
return '';
|
||||
},
|
||||
);
|
||||
return content;
|
||||
}
|
||||
|
||||
double _mentionOffset = 0;
|
||||
void onMention([bool fromClick = false]) {
|
||||
controller.keepChatPanel();
|
||||
DynMentionPanel.onDynMention(
|
||||
context,
|
||||
offset: _mentionOffset,
|
||||
callback: (offset) => _mentionOffset = offset,
|
||||
).then((MentionItem? res) {
|
||||
if (res != null) {
|
||||
(mentions ??= <MentionItem>[]).add(res);
|
||||
|
||||
String atName = '${fromClick ? '@' : ''}${res.name} ';
|
||||
|
||||
onInsertText(atName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onInsertText(String text) {
|
||||
if (text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
enablePublish.value = true;
|
||||
|
||||
final oldValue = editController.value;
|
||||
final selection = oldValue.selection;
|
||||
|
||||
if (selection.isValid) {
|
||||
TextEditingDelta delta;
|
||||
|
||||
if (selection.isCollapsed) {
|
||||
delta = TextEditingDeltaInsertion(
|
||||
oldText: oldValue.text,
|
||||
textInserted: text,
|
||||
insertionOffset: selection.start,
|
||||
selection: TextSelection.collapsed(
|
||||
offset: selection.start + text.length,
|
||||
),
|
||||
composing: TextRange.empty,
|
||||
);
|
||||
} else {
|
||||
delta = TextEditingDeltaReplacement(
|
||||
oldText: oldValue.text,
|
||||
replacementText: text,
|
||||
replacedRange: selection,
|
||||
selection: TextSelection.collapsed(
|
||||
offset: selection.start + text.length,
|
||||
),
|
||||
composing: TextRange.empty,
|
||||
);
|
||||
}
|
||||
|
||||
final newValue = delta.apply(oldValue);
|
||||
|
||||
if (oldValue == newValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
editController.value = newValue;
|
||||
} else {
|
||||
editController.value = TextEditingValue(
|
||||
text: text,
|
||||
selection: TextSelection.collapsed(offset: text.length),
|
||||
);
|
||||
}
|
||||
|
||||
widget.onSave?.call((text: editController.text, mentions: mentions));
|
||||
}
|
||||
|
||||
void onDelAtUser(String name) {
|
||||
mentions!.removeFirstWhere((e) => e.name == name);
|
||||
}
|
||||
|
||||
void onChanged(String value) {
|
||||
bool isEmpty = value.trim().isEmpty;
|
||||
if (isEmpty) {
|
||||
enablePublish.value = false;
|
||||
mentions?.clear();
|
||||
} else {
|
||||
enablePublish.value = true;
|
||||
}
|
||||
widget.onSave?.call((text: value, mentions: mentions));
|
||||
}
|
||||
}
|
||||
256
lib/pages/common/publish/common_publish_page.dart
Normal file
256
lib/pages/common/publish/common_publish_page.dart
Normal file
@@ -0,0 +1,256 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math' show max;
|
||||
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/models_new/upload_bfs/data.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:chat_bottom_container/chat_bottom_container.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
abstract class CommonPublishPage<T> extends StatefulWidget {
|
||||
const CommonPublishPage({
|
||||
super.key,
|
||||
this.initialValue,
|
||||
this.imageLengthLimit,
|
||||
this.onSave,
|
||||
this.autofocus = true,
|
||||
});
|
||||
|
||||
final String? initialValue;
|
||||
final int? imageLengthLimit;
|
||||
final ValueChanged<T>? onSave;
|
||||
final bool autofocus;
|
||||
}
|
||||
|
||||
abstract class CommonPublishPageState<T extends CommonPublishPage>
|
||||
extends State<T> with WidgetsBindingObserver {
|
||||
late final focusNode = FocusNode();
|
||||
late final controller = ChatBottomPanelContainerController<PanelType>();
|
||||
TextEditingController get editController;
|
||||
|
||||
Rx<PanelType> panelType = PanelType.none.obs;
|
||||
late final RxBool readOnly = false.obs;
|
||||
late final RxBool enablePublish = false.obs;
|
||||
|
||||
late final imagePicker = ImagePicker();
|
||||
late final RxList<String> pathList = <String>[].obs;
|
||||
int get limit => widget.imageLengthLimit ?? 9;
|
||||
|
||||
bool? hasPub;
|
||||
void initPubState();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
||||
initPubState();
|
||||
|
||||
if (widget.autofocus) {
|
||||
Future.delayed(const Duration(milliseconds: 300)).whenComplete(() {
|
||||
if (mounted) {
|
||||
focusNode.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (hasPub != true) {
|
||||
onSave();
|
||||
}
|
||||
focusNode.dispose();
|
||||
editController.dispose();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _requestFocus() async {
|
||||
await Future.delayed(const Duration(microseconds: 200));
|
||||
focusNode.requestFocus();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
if (mounted &&
|
||||
widget.autofocus &&
|
||||
panelType.value == PanelType.keyboard) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (focusNode.hasFocus) {
|
||||
focusNode.unfocus();
|
||||
_requestFocus();
|
||||
} else {
|
||||
_requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (state == AppLifecycleState.paused) {
|
||||
controller.keepChatPanel();
|
||||
if (focusNode.hasFocus) {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updatePanelType(PanelType type) {
|
||||
final isSwitchToKeyboard = PanelType.keyboard == type;
|
||||
final isSwitchToEmojiPanel = PanelType.emoji == type;
|
||||
bool isUpdated = false;
|
||||
switch (type) {
|
||||
case PanelType.keyboard:
|
||||
updateInputView(isReadOnly: false);
|
||||
break;
|
||||
case PanelType.emoji:
|
||||
isUpdated = updateInputView(isReadOnly: true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
void updatePanelTypeFunc() {
|
||||
controller.updatePanelType(
|
||||
isSwitchToKeyboard
|
||||
? ChatBottomPanelType.keyboard
|
||||
: ChatBottomPanelType.other,
|
||||
data: type,
|
||||
forceHandleFocus: isSwitchToEmojiPanel
|
||||
? ChatBottomHandleFocus.requestFocus
|
||||
: ChatBottomHandleFocus.none,
|
||||
);
|
||||
}
|
||||
|
||||
if (isUpdated) {
|
||||
// Waiting for the input view to update.
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
updatePanelTypeFunc();
|
||||
});
|
||||
} else {
|
||||
updatePanelTypeFunc();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> hidePanel() async {
|
||||
if (focusNode.hasFocus) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
focusNode.unfocus();
|
||||
}
|
||||
updateInputView(isReadOnly: false);
|
||||
if (ChatBottomPanelType.none == controller.currentPanelType) return;
|
||||
controller.updatePanelType(ChatBottomPanelType.none);
|
||||
}
|
||||
|
||||
bool updateInputView({
|
||||
required bool isReadOnly,
|
||||
}) {
|
||||
if (readOnly.value != isReadOnly) {
|
||||
readOnly.value = isReadOnly;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Widget buildEmojiPickerPanel() {
|
||||
double height = context.isTablet ? 300 : 170;
|
||||
final keyboardHeight = controller.keyboardHeight;
|
||||
if (keyboardHeight != 0) {
|
||||
height = max(height, keyboardHeight);
|
||||
}
|
||||
return SizedBox(
|
||||
height: height,
|
||||
child: customPanel,
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildPanelContainer([Color? panelBgColor]) {
|
||||
return ChatBottomPanelContainer<PanelType>(
|
||||
controller: controller,
|
||||
inputFocusNode: focusNode,
|
||||
otherPanelWidget: (type) {
|
||||
if (type == null) return const SizedBox.shrink();
|
||||
switch (type) {
|
||||
case PanelType.emoji:
|
||||
return buildEmojiPickerPanel();
|
||||
default:
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
onPanelTypeChange: (panelType, data) {
|
||||
// if (kDebugMode) debugPrint('panelType: $panelType');
|
||||
switch (panelType) {
|
||||
case ChatBottomPanelType.none:
|
||||
this.panelType.value = PanelType.none;
|
||||
break;
|
||||
case ChatBottomPanelType.keyboard:
|
||||
this.panelType.value = PanelType.keyboard;
|
||||
break;
|
||||
case ChatBottomPanelType.other:
|
||||
if (data == null) return;
|
||||
switch (data) {
|
||||
case PanelType.emoji:
|
||||
this.panelType.value = PanelType.emoji;
|
||||
break;
|
||||
default:
|
||||
this.panelType.value = PanelType.none;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
panelBgColor: panelBgColor ?? Theme.of(context).colorScheme.surface,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> onPublish() async {
|
||||
feedBack();
|
||||
List<Map<String, dynamic>>? pictures;
|
||||
if (pathList.isNotEmpty) {
|
||||
SmartDialog.showLoading(msg: '正在上传图片...');
|
||||
final cancelToken = CancelToken();
|
||||
try {
|
||||
pictures = await Future.wait<Map<String, dynamic>>(
|
||||
pathList.map((path) async {
|
||||
Map result = await MsgHttp.uploadBfs(
|
||||
path: path,
|
||||
category: 'daily',
|
||||
biz: 'new_dyn',
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
if (!result['status']) throw HttpException(result['msg']);
|
||||
UploadBfsResData data = result['data'];
|
||||
return {
|
||||
'img_width': data.imageWidth,
|
||||
'img_height': data.imageHeight,
|
||||
'img_size': data.imgSize,
|
||||
'img_src': data.imageUrl,
|
||||
};
|
||||
}).toList(),
|
||||
eagerError: true);
|
||||
SmartDialog.dismiss();
|
||||
} on HttpException catch (e) {
|
||||
cancelToken.cancel();
|
||||
SmartDialog.dismiss();
|
||||
SmartDialog.showToast(e.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
onCustomPublish(pictures: pictures);
|
||||
}
|
||||
|
||||
Future<void> onCustomPublish({List? pictures});
|
||||
|
||||
Widget? get customPanel => null;
|
||||
|
||||
void onChanged(String value) {
|
||||
enablePublish.value = value.trim().isNotEmpty;
|
||||
}
|
||||
|
||||
void onSave() {}
|
||||
}
|
||||
342
lib/pages/common/publish/common_rich_text_pub_page.dart
Normal file
342
lib/pages/common/publish/common_rich_text_pub_page.dart
Normal file
@@ -0,0 +1,342 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/button/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/text_field/controller.dart';
|
||||
import 'package:PiliPlus/models/common/image_preview_type.dart';
|
||||
import 'package:PiliPlus/models_new/dynamic/dyn_mention/item.dart';
|
||||
import 'package:PiliPlus/models_new/emote/emote.dart' as e;
|
||||
import 'package:PiliPlus/models_new/live/live_emote/emoticon.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/common_publish_page.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_mention/view.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:image_cropper/image_cropper.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
abstract class CommonRichTextPubPage
|
||||
extends CommonPublishPage<List<RichTextItem>> {
|
||||
const CommonRichTextPubPage({
|
||||
super.key,
|
||||
this.items,
|
||||
super.onSave,
|
||||
super.autofocus,
|
||||
super.imageLengthLimit,
|
||||
});
|
||||
|
||||
final List<RichTextItem>? items;
|
||||
}
|
||||
|
||||
abstract class CommonRichTextPubPageState<T extends CommonRichTextPubPage>
|
||||
extends CommonPublishPageState<T> {
|
||||
bool? hasPub;
|
||||
|
||||
@override
|
||||
late final RichTextEditingController editController =
|
||||
RichTextEditingController(
|
||||
items: widget.items,
|
||||
onMention: onMention,
|
||||
);
|
||||
|
||||
@override
|
||||
void initPubState() {
|
||||
if (editController.rawText.trim().isNotEmpty) {
|
||||
enablePublish.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
editController.richStyle = null;
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
|
||||
Widget buildImage(int index, double height) {
|
||||
final color =
|
||||
Theme.of(context).colorScheme.secondaryContainer.withValues(alpha: 0.5);
|
||||
|
||||
void onClear() {
|
||||
pathList.removeAt(index);
|
||||
if (pathList.isEmpty && editController.rawText.trim().isEmpty) {
|
||||
enablePublish.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
controller.keepChatPanel();
|
||||
context.imageView(
|
||||
imgList: pathList
|
||||
.map((path) => SourceModel(
|
||||
url: path,
|
||||
sourceType: SourceType.fileImage,
|
||||
))
|
||||
.toList(),
|
||||
initialPage: index,
|
||||
);
|
||||
},
|
||||
onLongPress: onClear,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(4)),
|
||||
child: Image(
|
||||
height: height,
|
||||
fit: BoxFit.fitHeight,
|
||||
filterQuality: FilterQuality.low,
|
||||
image: FileImage(File(pathList[index])),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 34,
|
||||
right: 5,
|
||||
child: iconButton(
|
||||
context: context,
|
||||
icon: Icons.edit,
|
||||
onPressed: () => onCropImage(index),
|
||||
size: 24,
|
||||
iconSize: 14,
|
||||
bgColor: color,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 5,
|
||||
right: 5,
|
||||
child: iconButton(
|
||||
context: context,
|
||||
icon: Icons.clear,
|
||||
onPressed: onClear,
|
||||
size: 24,
|
||||
iconSize: 14,
|
||||
bgColor: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> onCropImage(int index) async {
|
||||
final theme = Theme.of(context);
|
||||
CroppedFile? croppedFile = await ImageCropper().cropImage(
|
||||
sourcePath: pathList[index],
|
||||
uiSettings: [
|
||||
AndroidUiSettings(
|
||||
toolbarTitle: '裁剪',
|
||||
toolbarColor: theme.colorScheme.secondaryContainer,
|
||||
toolbarWidgetColor: theme.colorScheme.onSecondaryContainer,
|
||||
),
|
||||
IOSUiSettings(
|
||||
title: '裁剪',
|
||||
),
|
||||
],
|
||||
);
|
||||
if (croppedFile != null) {
|
||||
pathList[index] = croppedFile.path;
|
||||
}
|
||||
}
|
||||
|
||||
void onPickImage([VoidCallback? callback]) {
|
||||
EasyThrottle.throttle('imagePicker', const Duration(milliseconds: 500),
|
||||
() async {
|
||||
try {
|
||||
List<XFile> pickedFiles = await imagePicker.pickMultiImage(
|
||||
limit: limit,
|
||||
imageQuality: 100,
|
||||
);
|
||||
if (pickedFiles.isNotEmpty) {
|
||||
for (int i = 0; i < pickedFiles.length; i++) {
|
||||
if (pathList.length == limit) {
|
||||
SmartDialog.showToast('最多选择$limit张图片');
|
||||
break;
|
||||
} else {
|
||||
pathList.add(pickedFiles[i].path);
|
||||
}
|
||||
}
|
||||
callback?.call();
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast(e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onChooseEmote(dynamic emote, double? width, double? height) {
|
||||
if (emote is e.Emote) {
|
||||
final isTextEmote = width == null;
|
||||
onInsertText(
|
||||
isTextEmote ? emote.text! : '\uFFFC',
|
||||
RichTextType.emoji,
|
||||
rawText: emote.text!,
|
||||
emote: isTextEmote
|
||||
? null
|
||||
: Emote(
|
||||
url: emote.url!,
|
||||
width: width,
|
||||
height: height,
|
||||
),
|
||||
);
|
||||
} else if (emote is Emoticon) {
|
||||
onInsertText(
|
||||
'\uFFFC',
|
||||
RichTextType.emoji,
|
||||
rawText: emote.emoji!,
|
||||
emote: Emote(
|
||||
url: emote.url!,
|
||||
width: width!,
|
||||
height: height,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>>? getRichContent() {
|
||||
if (editController.items.isEmpty) return null;
|
||||
return editController.items.map((e) {
|
||||
return switch (e.type) {
|
||||
RichTextType.text || RichTextType.composing => <String, dynamic>{
|
||||
"raw_text": e.text,
|
||||
"type": 1,
|
||||
"biz_id": "",
|
||||
},
|
||||
RichTextType.at => <String, dynamic>{
|
||||
"raw_text": '@${e.rawText}',
|
||||
"type": 2,
|
||||
"biz_id": e.uid,
|
||||
},
|
||||
RichTextType.emoji => <String, dynamic>{
|
||||
"raw_text": e.rawText,
|
||||
"type": 9,
|
||||
"biz_id": "",
|
||||
},
|
||||
};
|
||||
}).toList();
|
||||
}
|
||||
|
||||
double _mentionOffset = 0;
|
||||
void onMention([bool fromClick = false]) {
|
||||
controller.keepChatPanel();
|
||||
DynMentionPanel.onDynMention(
|
||||
context,
|
||||
offset: _mentionOffset,
|
||||
callback: (offset) => _mentionOffset = offset,
|
||||
).then((MentionItem? res) {
|
||||
if (res != null) {
|
||||
onInsertText(
|
||||
'@${res.name} ',
|
||||
RichTextType.at,
|
||||
rawText: res.name,
|
||||
uid: res.uid,
|
||||
fromClick: fromClick,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onInsertText(
|
||||
String text,
|
||||
RichTextType type, {
|
||||
String? rawText,
|
||||
Emote? emote,
|
||||
String? uid,
|
||||
bool? fromClick,
|
||||
}) {
|
||||
if (text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
enablePublish.value = true;
|
||||
|
||||
var oldValue = editController.value;
|
||||
final selection = oldValue.selection;
|
||||
|
||||
if (selection.isValid) {
|
||||
TextEditingDelta delta;
|
||||
|
||||
if (selection.isCollapsed) {
|
||||
if (type == RichTextType.at && fromClick == false) {
|
||||
delta = RichTextEditingDeltaReplacement(
|
||||
oldText: oldValue.text,
|
||||
replacementText: text,
|
||||
replacedRange:
|
||||
TextRange(start: selection.start - 1, end: selection.end),
|
||||
selection: TextSelection.collapsed(
|
||||
offset: selection.start - 1 + text.length,
|
||||
),
|
||||
composing: TextRange.empty,
|
||||
rawText: rawText,
|
||||
type: type,
|
||||
emote: emote,
|
||||
uid: uid,
|
||||
);
|
||||
} else {
|
||||
delta = RichTextEditingDeltaInsertion(
|
||||
oldText: oldValue.text,
|
||||
textInserted: text,
|
||||
insertionOffset: selection.start,
|
||||
selection: TextSelection.collapsed(
|
||||
offset: selection.start + text.length,
|
||||
),
|
||||
composing: TextRange.empty,
|
||||
rawText: rawText,
|
||||
type: type,
|
||||
emote: emote,
|
||||
uid: uid,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
delta = RichTextEditingDeltaReplacement(
|
||||
oldText: oldValue.text,
|
||||
replacementText: text,
|
||||
replacedRange: selection,
|
||||
selection: TextSelection.collapsed(
|
||||
offset: selection.start + text.length,
|
||||
),
|
||||
composing: TextRange.empty,
|
||||
rawText: rawText,
|
||||
type: type,
|
||||
emote: emote,
|
||||
uid: uid,
|
||||
);
|
||||
}
|
||||
|
||||
final newValue = delta.apply(oldValue);
|
||||
|
||||
if (oldValue == newValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
editController
|
||||
..value = newValue
|
||||
..syncRichText(delta);
|
||||
} else {
|
||||
editController.value = TextEditingValue(
|
||||
text: text,
|
||||
selection: TextSelection.collapsed(offset: text.length),
|
||||
);
|
||||
editController.items
|
||||
..clear()
|
||||
..add(
|
||||
RichTextItem(
|
||||
type: type,
|
||||
text: text,
|
||||
rawText: rawText,
|
||||
range: TextRange(
|
||||
start: 0,
|
||||
end: text.length,
|
||||
),
|
||||
emote: emote,
|
||||
uid: uid,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onSave() {
|
||||
widget.onSave?.call(editController.items);
|
||||
}
|
||||
}
|
||||
29
lib/pages/common/publish/common_text_pub_page.dart
Normal file
29
lib/pages/common/publish/common_text_pub_page.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:PiliPlus/pages/common/publish/common_publish_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract class CommonTextPubPage extends CommonPublishPage<String> {
|
||||
const CommonTextPubPage({
|
||||
super.key,
|
||||
super.initialValue,
|
||||
super.onSave,
|
||||
});
|
||||
}
|
||||
|
||||
abstract class CommonTextPubPageState<T extends CommonTextPubPage>
|
||||
extends CommonPublishPageState<T> {
|
||||
@override
|
||||
late final TextEditingController editController =
|
||||
TextEditingController(text: widget.initialValue);
|
||||
|
||||
@override
|
||||
void initPubState() {
|
||||
if (widget.initialValue?.trim().isNotEmpty == true) {
|
||||
enablePublish.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onSave() {
|
||||
widget.onSave?.call(editController.text);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import 'package:PiliPlus/common/widgets/text_field/controller.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
|
||||
show MainListReply, ReplyInfo, SubjectControl, Mode;
|
||||
import 'package:PiliPlus/grpc/bilibili/pagination.pb.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:PiliPlus/models/common/reply/reply_sort_type.dart';
|
||||
import 'package:PiliPlus/models_new/dynamic/dyn_mention/item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/pages/video/reply_new/view.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
@@ -25,8 +25,7 @@ abstract class ReplyController<R> extends CommonListController<R, ReplyInfo> {
|
||||
late Rx<ReplySortType> sortType;
|
||||
late Rx<Mode> mode;
|
||||
|
||||
late final savedReplies =
|
||||
<Object, ({String text, List<MentionItem>? mentions})?>{};
|
||||
late final savedReplies = <Object, List<RichTextItem>?>{};
|
||||
|
||||
AccountService accountService = Get.find<AccountService>();
|
||||
|
||||
@@ -127,16 +126,20 @@ abstract class ReplyController<R> extends CommonListController<R, ReplyInfo> {
|
||||
.push(
|
||||
GetDialogRoute(
|
||||
pageBuilder: (buildContext, animation, secondaryAnimation) {
|
||||
final saved = savedReplies[key];
|
||||
return ReplyPage(
|
||||
oid: oid ?? replyItem!.oid.toInt(),
|
||||
root: oid != null ? 0 : replyItem!.id.toInt(),
|
||||
parent: oid != null ? 0 : replyItem!.id.toInt(),
|
||||
replyType: replyItem?.type.toInt() ?? replyType!,
|
||||
replyItem: replyItem,
|
||||
initialValue: saved?.text,
|
||||
mentions: saved?.mentions,
|
||||
onSave: (reply) => savedReplies[key] = reply,
|
||||
items: savedReplies[key],
|
||||
onSave: (reply) {
|
||||
if (reply.isEmpty) {
|
||||
savedReplies.remove(key);
|
||||
} else {
|
||||
savedReplies[key] = reply.toList();
|
||||
}
|
||||
},
|
||||
hint: hint,
|
||||
);
|
||||
},
|
||||
@@ -238,4 +241,10 @@ abstract class ReplyController<R> extends CommonListController<R, ReplyInfo> {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
savedReplies.clear();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@ import 'package:PiliPlus/common/widgets/custom_icon.dart';
|
||||
import 'package:PiliPlus/common/widgets/draggable_sheet/draggable_scrollable_sheet_dyn.dart'
|
||||
as dyn_sheet;
|
||||
import 'package:PiliPlus/common/widgets/pair.dart';
|
||||
import 'package:PiliPlus/common/widgets/text_field/text_field.dart'
|
||||
as text_field;
|
||||
import 'package:PiliPlus/common/widgets/text_field/text_field.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/models/common/reply/reply_option_type.dart';
|
||||
import 'package:PiliPlus/models_new/dynamic/dyn_topic_top/topic_item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_publish_page.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/common_rich_text_pub_page.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_mention/controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_select_topic/controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_select_topic/view.dart';
|
||||
@@ -26,7 +25,7 @@ import 'package:flutter/services.dart' show LengthLimitingTextInputFormatter;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class CreateDynPanel extends CommonPublishPage {
|
||||
class CreateDynPanel extends CommonRichTextPubPage {
|
||||
const CreateDynPanel({
|
||||
super.key,
|
||||
super.imageLengthLimit = 18,
|
||||
@@ -60,7 +59,7 @@ class CreateDynPanel extends CommonPublishPage {
|
||||
);
|
||||
}
|
||||
|
||||
class _CreateDynPanelState extends CommonPublishPageState<CreateDynPanel> {
|
||||
class _CreateDynPanelState extends CommonRichTextPubPageState<CreateDynPanel> {
|
||||
final RxBool _isPrivate = false.obs;
|
||||
final Rx<DateTime?> _publishTime = Rx<DateTime?>(null);
|
||||
final Rx<ReplyOptionType> _replyOption = ReplyOptionType.allow.obs;
|
||||
@@ -550,6 +549,12 @@ class _CreateDynPanelState extends CommonPublishPageState<CreateDynPanel> {
|
||||
tooltip: '@',
|
||||
selected: false,
|
||||
),
|
||||
// if (kDebugMode)
|
||||
// ToolbarIconButton(
|
||||
// onPressed: editController.clear,
|
||||
// icon: const Icon(Icons.clear, size: 22),
|
||||
// selected: false,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -563,13 +568,12 @@ class _CreateDynPanelState extends CommonPublishPageState<CreateDynPanel> {
|
||||
}
|
||||
},
|
||||
child: Obx(
|
||||
() => text_field.TextField(
|
||||
() => RichTextField(
|
||||
controller: editController,
|
||||
minLines: 4,
|
||||
maxLines: null,
|
||||
focusNode: focusNode,
|
||||
readOnly: readOnly.value,
|
||||
onDelAtUser: onDelAtUser,
|
||||
onChanged: onChanged,
|
||||
decoration: InputDecoration(
|
||||
hintText: '说点什么吧',
|
||||
@@ -580,8 +584,7 @@ class _CreateDynPanelState extends CommonPublishPageState<CreateDynPanel> {
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
inputFormatters: [LengthLimitingTextInputFormatter(1000)],
|
||||
onMention: onMention,
|
||||
// inputFormatters: [LengthLimitingTextInputFormatter(1000)],
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -591,14 +594,13 @@ class _CreateDynPanelState extends CommonPublishPageState<CreateDynPanel> {
|
||||
Widget? get customPanel => EmotePanel(onChoose: onChooseEmote);
|
||||
|
||||
@override
|
||||
Future<void> onCustomPublish(
|
||||
{required String message, List? pictures}) async {
|
||||
Future<void> onCustomPublish({List? pictures}) async {
|
||||
SmartDialog.showLoading(msg: '正在发布');
|
||||
List<Map<String, dynamic>>? extraContent = getRichContent();
|
||||
final hasMention = extraContent != null;
|
||||
final hasRichText = extraContent != null;
|
||||
var result = await DynamicsHttp.createDynamic(
|
||||
mid: Accounts.main.mid,
|
||||
rawText: hasMention ? null : editController.text,
|
||||
rawText: hasRichText ? null : editController.text,
|
||||
pics: pictures,
|
||||
publishTime: _publishTime.value != null
|
||||
? _publishTime.value!.millisecondsSinceEpoch ~/ 1000
|
||||
@@ -611,13 +613,14 @@ class _CreateDynPanelState extends CommonPublishPageState<CreateDynPanel> {
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (result['status']) {
|
||||
hasPub = true;
|
||||
Get.back();
|
||||
SmartDialog.showToast('发布成功');
|
||||
var id = result['data']?['dyn_id'];
|
||||
RequestUtils.insertCreatedDyn(id);
|
||||
RequestUtils.checkCreatedDyn(
|
||||
id: id,
|
||||
dynText: editController.text,
|
||||
dynText: editController.rawText,
|
||||
);
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
@@ -637,4 +640,7 @@ class _CreateDynPanelState extends CommonPublishPageState<CreateDynPanel> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onSave() {}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,17 @@ import 'package:PiliPlus/common/widgets/text_field/text_field.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/pages/common/common_publish_page.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/common_rich_text_pub_page.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_mention/controller.dart';
|
||||
import 'package:PiliPlus/pages/emote/controller.dart';
|
||||
import 'package:PiliPlus/pages/emote/view.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/request_utils.dart';
|
||||
import 'package:flutter/material.dart' hide DraggableScrollableSheet, TextField;
|
||||
import 'package:flutter/services.dart' show LengthLimitingTextInputFormatter;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class RepostPanel extends CommonPublishPage {
|
||||
class RepostPanel extends CommonRichTextPubPage {
|
||||
const RepostPanel({
|
||||
super.key,
|
||||
this.item,
|
||||
@@ -48,7 +47,7 @@ class RepostPanel extends CommonPublishPage {
|
||||
State<RepostPanel> createState() => _RepostPanelState();
|
||||
}
|
||||
|
||||
class _RepostPanelState extends CommonPublishPageState<RepostPanel> {
|
||||
class _RepostPanelState extends CommonRichTextPubPageState<RepostPanel> {
|
||||
late bool _isMax = widget.isMax ?? false;
|
||||
bool? _isExpanded;
|
||||
|
||||
@@ -225,7 +224,7 @@ class _RepostPanelState extends CommonPublishPageState<RepostPanel> {
|
||||
}
|
||||
},
|
||||
child: Obx(
|
||||
() => TextField(
|
||||
() => RichTextField(
|
||||
controller: editController,
|
||||
minLines: 4,
|
||||
maxLines: null,
|
||||
@@ -240,9 +239,7 @@ class _RepostPanelState extends CommonPublishPageState<RepostPanel> {
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 10),
|
||||
),
|
||||
inputFormatters: [LengthLimitingTextInputFormatter(1000)],
|
||||
onMention: onMention,
|
||||
onDelAtUser: onDelAtUser,
|
||||
// inputFormatters: [LengthLimitingTextInputFormatter(1000)],
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -376,7 +373,7 @@ class _RepostPanelState extends CommonPublishPageState<RepostPanel> {
|
||||
@override
|
||||
Widget? get customPanel => EmotePanel(onChoose: onChooseEmote);
|
||||
|
||||
List<Map<String, dynamic>>? extraContent(DynamicItemModel item) {
|
||||
List<Map<String, dynamic>>? getRepostContent(DynamicItemModel item) {
|
||||
try {
|
||||
return [
|
||||
{"raw_text": "//", "type": 1, "biz_id": ""},
|
||||
@@ -416,26 +413,26 @@ class _RepostPanelState extends CommonPublishPageState<RepostPanel> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onCustomPublish(
|
||||
{required String message, List? pictures}) async {
|
||||
Future<void> onCustomPublish({List? pictures}) async {
|
||||
SmartDialog.showLoading();
|
||||
List<Map<String, dynamic>>? content = getRichContent();
|
||||
final hasMention = content != null;
|
||||
List<Map<String, dynamic>>? richContent = getRichContent();
|
||||
final hasRichText = richContent != null;
|
||||
List<Map<String, dynamic>>? repostContent =
|
||||
widget.item?.orig != null ? extraContent(widget.item!) : null;
|
||||
if (hasMention && repostContent != null) {
|
||||
content.addAll(repostContent);
|
||||
widget.item?.orig != null ? getRepostContent(widget.item!) : null;
|
||||
if (hasRichText && repostContent != null) {
|
||||
richContent.addAll(repostContent);
|
||||
}
|
||||
var result = await DynamicsHttp.createDynamic(
|
||||
mid: Accounts.main.mid,
|
||||
dynIdStr: widget.item?.idStr ?? widget.dynIdStr,
|
||||
rid: widget.rid,
|
||||
dynType: widget.dynType,
|
||||
rawText: hasMention ? null : editController.text,
|
||||
extraContent: content ?? repostContent,
|
||||
rawText: hasRichText ? null : editController.text,
|
||||
extraContent: richContent ?? repostContent,
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (result['status']) {
|
||||
hasPub = true;
|
||||
Get.back();
|
||||
SmartDialog.showToast('转发成功');
|
||||
widget.callback?.call();
|
||||
@@ -443,10 +440,13 @@ class _RepostPanelState extends CommonPublishPageState<RepostPanel> {
|
||||
RequestUtils.insertCreatedDyn(id);
|
||||
RequestUtils.checkCreatedDyn(
|
||||
id: id,
|
||||
dynText: editController.text,
|
||||
dynText: editController.rawText,
|
||||
);
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onSave() {}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class EmotePanel extends StatefulWidget {
|
||||
final ValueChanged<Emote> onChoose;
|
||||
final Function(Emote emote, double? width, double? height) onChoose;
|
||||
|
||||
const EmotePanel({super.key, required this.onChoose});
|
||||
|
||||
@override
|
||||
@@ -46,18 +47,17 @@ class _EmotePanelState extends State<EmotePanel>
|
||||
controller: _emotePanelController.tabController,
|
||||
children: response!.map(
|
||||
(e) {
|
||||
int size = e.emote!.first.meta!.size!;
|
||||
int type = e.type!;
|
||||
double size = e.emote!.first.meta!.size == 1 ? 40 : 60;
|
||||
bool isTextEmote = e.type == 4;
|
||||
return GridView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12, right: 12, bottom: 12),
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent:
|
||||
type == 4 ? 100 : (size == 1 ? 40 : 60),
|
||||
maxCrossAxisExtent: isTextEmote ? 100 : size,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
mainAxisExtent: size == 1 ? 40 : 60,
|
||||
mainAxisExtent: size,
|
||||
),
|
||||
itemCount: e.emote!.length,
|
||||
itemBuilder: (context, index) {
|
||||
@@ -67,10 +67,17 @@ class _EmotePanelState extends State<EmotePanel>
|
||||
child: InkWell(
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(8)),
|
||||
onTap: () => widget.onChoose(item),
|
||||
onTap: () => widget.onChoose(
|
||||
item,
|
||||
isTextEmote
|
||||
? null
|
||||
: e.emote!.first.meta!.size == 1
|
||||
? 24
|
||||
: 42,
|
||||
null),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: type == 4
|
||||
child: isTextEmote
|
||||
? Center(
|
||||
child: Text(
|
||||
item.text!,
|
||||
@@ -80,8 +87,8 @@ class _EmotePanelState extends State<EmotePanel>
|
||||
)
|
||||
: NetworkImgLayer(
|
||||
src: item.url!,
|
||||
width: size * 38,
|
||||
height: size * 38,
|
||||
width: size,
|
||||
height: size,
|
||||
semanticsLabel: item.text!,
|
||||
type: ImageType.emote,
|
||||
boxFit: BoxFit.contain,
|
||||
|
||||
@@ -14,7 +14,7 @@ import 'package:get/get.dart';
|
||||
|
||||
class LiveEmotePanel extends StatefulWidget {
|
||||
final int roomId;
|
||||
final ValueChanged<Emoticon> onChoose;
|
||||
final Function(Emoticon emote, double? width, double? height) onChoose;
|
||||
final ValueChanged<Emoticon> onSendEmoticonUnique;
|
||||
const LiveEmotePanel({
|
||||
super.key,
|
||||
@@ -61,6 +61,8 @@ class _LiveEmotePanelState extends State<LiveEmotePanel>
|
||||
max(1, item.emoticons!.first.width! / 80);
|
||||
double heightFac =
|
||||
max(1, item.emoticons!.first.height! / 80);
|
||||
final width = widthFac * 38;
|
||||
final height = heightFac * 38;
|
||||
return GridView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12, right: 12, bottom: 12),
|
||||
@@ -81,7 +83,7 @@ class _LiveEmotePanelState extends State<LiveEmotePanel>
|
||||
const BorderRadius.all(Radius.circular(8)),
|
||||
onTap: () {
|
||||
if (item.pkgType == 3) {
|
||||
widget.onChoose(e);
|
||||
widget.onChoose(e, width, height);
|
||||
} else {
|
||||
widget.onSendEmoticonUnique(e);
|
||||
}
|
||||
@@ -91,8 +93,8 @@ class _LiveEmotePanelState extends State<LiveEmotePanel>
|
||||
child: NetworkImgLayer(
|
||||
boxFit: BoxFit.contain,
|
||||
src: e.url!,
|
||||
width: widthFac * 38,
|
||||
height: heightFac * 38,
|
||||
width: width,
|
||||
height: height,
|
||||
type: ImageType.emote,
|
||||
quality: item.pkgType == 3 ? null : 80,
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/text_field/controller.dart';
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/live.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
@@ -48,7 +49,7 @@ class LiveRoomController extends GetxController {
|
||||
late List<({int code, String desc})> acceptQnList = [];
|
||||
RxString currentQnDesc = ''.obs;
|
||||
|
||||
String? savedDanmaku;
|
||||
List<RichTextItem>? savedDanmaku;
|
||||
|
||||
AccountService accountService = Get.find<AccountService>();
|
||||
|
||||
@@ -233,6 +234,8 @@ class LiveRoomController extends GetxController {
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
savedDanmaku?.clear();
|
||||
savedDanmaku = null;
|
||||
scrollController
|
||||
..removeListener(listener)
|
||||
..dispose();
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/button/toolbar_icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/text_field/text_field.dart';
|
||||
import 'package:PiliPlus/http/live.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/pages/common/common_publish_page.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/common_rich_text_pub_page.dart';
|
||||
import 'package:PiliPlus/pages/live_emote/controller.dart';
|
||||
import 'package:PiliPlus/pages/live_emote/view.dart';
|
||||
import 'package:PiliPlus/pages/live_room/controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' show LengthLimitingTextInputFormatter;
|
||||
import 'package:flutter/material.dart' hide TextField;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart' hide MultipartFile;
|
||||
|
||||
class LiveSendDmPanel extends CommonPublishPage {
|
||||
class LiveSendDmPanel extends CommonRichTextPubPage {
|
||||
final bool fromEmote;
|
||||
final LiveRoomController liveRoomController;
|
||||
|
||||
const LiveSendDmPanel({
|
||||
super.key,
|
||||
super.initialValue,
|
||||
super.items,
|
||||
super.onSave,
|
||||
this.fromEmote = false,
|
||||
required this.liveRoomController,
|
||||
@@ -28,7 +28,7 @@ class LiveSendDmPanel extends CommonPublishPage {
|
||||
State<LiveSendDmPanel> createState() => _ReplyPageState();
|
||||
}
|
||||
|
||||
class _ReplyPageState extends CommonPublishPageState<LiveSendDmPanel> {
|
||||
class _ReplyPageState extends CommonRichTextPubPageState<LiveSendDmPanel> {
|
||||
LiveRoomController get liveRoomController => widget.liveRoomController;
|
||||
|
||||
@override
|
||||
@@ -101,7 +101,7 @@ class _ReplyPageState extends CommonPublishPageState<LiveSendDmPanel> {
|
||||
}
|
||||
},
|
||||
child: Obx(
|
||||
() => TextField(
|
||||
() => RichTextField(
|
||||
controller: editController,
|
||||
minLines: 1,
|
||||
maxLines: 2,
|
||||
@@ -115,7 +115,7 @@ class _ReplyPageState extends CommonPublishPageState<LiveSendDmPanel> {
|
||||
hintStyle: TextStyle(fontSize: 14),
|
||||
),
|
||||
style: theme.textTheme.bodyLarge,
|
||||
inputFormatters: [LengthLimitingTextInputFormatter(20)],
|
||||
// inputFormatters: [LengthLimitingTextInputFormatter(20)],
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -176,20 +176,23 @@ class _ReplyPageState extends CommonPublishPageState<LiveSendDmPanel> {
|
||||
|
||||
@override
|
||||
Future<void> onCustomPublish({
|
||||
required String message,
|
||||
String? message,
|
||||
List? pictures,
|
||||
int? dmType,
|
||||
emoticonOptions,
|
||||
}) async {
|
||||
final res = await LiveHttp.sendLiveMsg(
|
||||
roomId: liveRoomController.roomId,
|
||||
msg: message,
|
||||
msg: message ?? editController.rawText,
|
||||
dmType: dmType,
|
||||
emoticonOptions: emoticonOptions,
|
||||
);
|
||||
if (res['status']) {
|
||||
hasPub = true;
|
||||
Get.back();
|
||||
liveRoomController.savedDanmaku = null;
|
||||
liveRoomController
|
||||
..savedDanmaku?.clear()
|
||||
..savedDanmaku = null;
|
||||
SmartDialog.showToast('发送成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
|
||||
@@ -606,8 +606,16 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
return LiveSendDmPanel(
|
||||
fromEmote: fromEmote,
|
||||
liveRoomController: _liveRoomController,
|
||||
initialValue: _liveRoomController.savedDanmaku,
|
||||
onSave: (msg) => _liveRoomController.savedDanmaku = msg.text,
|
||||
items: _liveRoomController.savedDanmaku,
|
||||
onSave: (msg) {
|
||||
if (msg.isEmpty) {
|
||||
_liveRoomController
|
||||
..savedDanmaku?.clear()
|
||||
..savedDanmaku = null;
|
||||
} else {
|
||||
_liveRoomController.savedDanmaku = msg.toList();
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
transitionDuration: const Duration(milliseconds: 500),
|
||||
|
||||
@@ -945,7 +945,7 @@ class VideoDetailController extends GetxController
|
||||
bvid: bvid,
|
||||
progress: plPlayerController.position.value.inMilliseconds,
|
||||
initialValue: savedDanmaku,
|
||||
onSave: (danmaku) => savedDanmaku = danmaku.text,
|
||||
onSave: (danmaku) => savedDanmaku = danmaku,
|
||||
callback: (danmakuModel) {
|
||||
savedDanmaku = null;
|
||||
plPlayerController.danmakuController?.addDanmaku(danmakuModel);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/button/toolbar_icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/text_field/controller.dart'
|
||||
show RichTextType;
|
||||
import 'package:PiliPlus/common/widgets/text_field/text_field.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
|
||||
show ReplyInfo;
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/main.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/pages/common/common_publish_page.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/common_rich_text_pub_page.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_mention/controller.dart';
|
||||
import 'package:PiliPlus/pages/emote/view.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
@@ -15,7 +17,7 @@ import 'package:flutter/material.dart' hide TextField;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ReplyPage extends CommonPublishPage {
|
||||
class ReplyPage extends CommonRichTextPubPage {
|
||||
final int oid;
|
||||
final int root;
|
||||
final int parent;
|
||||
@@ -25,8 +27,7 @@ class ReplyPage extends CommonPublishPage {
|
||||
|
||||
const ReplyPage({
|
||||
super.key,
|
||||
super.initialValue,
|
||||
super.mentions,
|
||||
super.items,
|
||||
super.imageLengthLimit,
|
||||
super.onSave,
|
||||
required this.oid,
|
||||
@@ -41,7 +42,7 @@ class ReplyPage extends CommonPublishPage {
|
||||
State<ReplyPage> createState() => _ReplyPageState();
|
||||
}
|
||||
|
||||
class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
|
||||
class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
|
||||
final RxBool _syncToDynamic = false.obs;
|
||||
|
||||
Widget get child => SafeArea(
|
||||
@@ -137,7 +138,7 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
|
||||
}
|
||||
},
|
||||
child: Obx(
|
||||
() => TextField(
|
||||
() => RichTextField(
|
||||
controller: editController,
|
||||
minLines: 4,
|
||||
maxLines: 8,
|
||||
@@ -151,8 +152,6 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
|
||||
hintStyle: const TextStyle(fontSize: 14),
|
||||
),
|
||||
style: themeData.textTheme.bodyLarge,
|
||||
onMention: onMention,
|
||||
onDelAtUser: onDelAtUser,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -265,8 +264,12 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onCustomPublish(
|
||||
{required String message, List? pictures}) async {
|
||||
Future<void> onCustomPublish({List? pictures}) async {
|
||||
Map<String, int> atNameToMid = {
|
||||
for (var e in editController.items)
|
||||
if (e.type == RichTextType.at) e.rawText: int.parse(e.uid!),
|
||||
};
|
||||
String message = editController.rawText;
|
||||
var result = await VideoHttp.replyAdd(
|
||||
type: widget.replyType,
|
||||
oid: widget.oid,
|
||||
@@ -275,13 +278,12 @@ class _ReplyPageState extends CommonPublishPageState<ReplyPage> {
|
||||
message: widget.replyItem != null && widget.replyItem!.root != 0
|
||||
? ' 回复 @${widget.replyItem!.member.name} : $message'
|
||||
: message,
|
||||
atNameToMid: mentions?.isNotEmpty == true
|
||||
? {for (var e in mentions!) e.name: e.uid}
|
||||
: null,
|
||||
atNameToMid: atNameToMid,
|
||||
pictures: pictures,
|
||||
syncToDynamic: _syncToDynamic.value,
|
||||
);
|
||||
if (result['status']) {
|
||||
hasPub = true;
|
||||
SmartDialog.showToast(result['data']['success_toast']);
|
||||
Get.back(result: result['data']['reply']);
|
||||
} else {
|
||||
|
||||
@@ -149,16 +149,20 @@ class VideoReplyReplyController extends ReplyController
|
||||
.push(
|
||||
GetDialogRoute(
|
||||
pageBuilder: (buildContext, animation, secondaryAnimation) {
|
||||
final saved = savedReplies[key];
|
||||
return ReplyPage(
|
||||
oid: oid,
|
||||
root: root,
|
||||
parent: root,
|
||||
replyType: this.replyType,
|
||||
replyItem: replyItem,
|
||||
initialValue: saved?.text,
|
||||
mentions: saved?.mentions,
|
||||
onSave: (reply) => savedReplies[key] = reply,
|
||||
items: savedReplies[key],
|
||||
onSave: (reply) {
|
||||
if (reply.isEmpty) {
|
||||
savedReplies.remove(key);
|
||||
} else {
|
||||
savedReplies[key] = reply.toList();
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
transitionDuration: const Duration(milliseconds: 500),
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:PiliPlus/http/danmaku.dart';
|
||||
import 'package:PiliPlus/main.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/models/user/info.dart';
|
||||
import 'package:PiliPlus/pages/common/common_publish_page.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/common_text_pub_page.dart';
|
||||
import 'package:PiliPlus/pages/setting/slide_color_picker.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:canvas_danmaku/models/danmaku_content_item.dart';
|
||||
@@ -14,7 +14,7 @@ import 'package:flutter/services.dart' show LengthLimitingTextInputFormatter;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class SendDanmakuPanel extends CommonPublishPage {
|
||||
class SendDanmakuPanel extends CommonTextPubPage {
|
||||
// video
|
||||
final dynamic cid;
|
||||
final dynamic bvid;
|
||||
@@ -44,7 +44,7 @@ class SendDanmakuPanel extends CommonPublishPage {
|
||||
State<SendDanmakuPanel> createState() => _SendDanmakuPanelState();
|
||||
}
|
||||
|
||||
class _SendDanmakuPanelState extends CommonPublishPageState<SendDanmakuPanel> {
|
||||
class _SendDanmakuPanelState extends CommonTextPubPageState<SendDanmakuPanel> {
|
||||
late final RxInt _mode;
|
||||
late final RxInt _fontsize;
|
||||
late final Rx<Color> _color;
|
||||
@@ -448,8 +448,7 @@ class _SendDanmakuPanelState extends CommonPublishPageState<SendDanmakuPanel> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onCustomPublish(
|
||||
{required String message, List? pictures}) async {
|
||||
Future<void> onCustomPublish({List? pictures}) async {
|
||||
SmartDialog.showLoading(msg: '发送中...');
|
||||
bool isColorful = _color.value == Colors.transparent;
|
||||
final res = await DanmakuHttp.shootDanmaku(
|
||||
@@ -464,6 +463,7 @@ class _SendDanmakuPanelState extends CommonPublishPageState<SendDanmakuPanel> {
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (res['status']) {
|
||||
hasPub = true;
|
||||
Get.back();
|
||||
SmartDialog.showToast('发送成功');
|
||||
widget.callback(
|
||||
|
||||
@@ -65,12 +65,13 @@ class WhisperDetailController extends CommonListController<RspSessionMsg, Msg> {
|
||||
}
|
||||
|
||||
Future<void> sendMsg({
|
||||
required String message,
|
||||
String? message,
|
||||
Map? picMsg,
|
||||
required VoidCallback onClearText,
|
||||
int? msgType,
|
||||
int? index,
|
||||
}) async {
|
||||
assert((message != null) ^ (picMsg != null));
|
||||
feedBack();
|
||||
SmartDialog.dismiss();
|
||||
if (!accountService.isLogin.value) {
|
||||
@@ -81,7 +82,7 @@ class WhisperDetailController extends CommonListController<RspSessionMsg, Msg> {
|
||||
senderUid: accountService.mid,
|
||||
receiverId: mid!,
|
||||
content:
|
||||
msgType == 5 ? message : jsonEncode(picMsg ?? {"content": message}),
|
||||
msgType == 5 ? message! : jsonEncode(picMsg ?? {"content": message!}),
|
||||
msgType: MsgType.values[msgType ?? (picMsg != null ? 2 : 1)],
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
|
||||
@@ -3,13 +3,14 @@ import 'dart:async';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/text_field/text_field.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/im/type.pb.dart' show Msg;
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
import 'package:PiliPlus/models/common/image_type.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/models_new/upload_bfs/data.dart';
|
||||
import 'package:PiliPlus/pages/common/common_publish_page.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/common_rich_text_pub_page.dart';
|
||||
import 'package:PiliPlus/pages/emote/view.dart';
|
||||
import 'package:PiliPlus/pages/whisper_detail/controller.dart';
|
||||
import 'package:PiliPlus/pages/whisper_detail/widget/chat_item.dart';
|
||||
@@ -17,14 +18,13 @@ import 'package:PiliPlus/pages/whisper_link_setting/view.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' show LengthLimitingTextInputFormatter;
|
||||
import 'package:flutter/material.dart' hide TextField;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
|
||||
class WhisperDetailPage extends CommonPublishPage {
|
||||
class WhisperDetailPage extends CommonRichTextPubPage {
|
||||
const WhisperDetailPage({
|
||||
super.key,
|
||||
super.autofocus = false,
|
||||
@@ -35,7 +35,7 @@ class WhisperDetailPage extends CommonPublishPage {
|
||||
}
|
||||
|
||||
class _WhisperDetailPageState
|
||||
extends CommonPublishPageState<WhisperDetailPage> {
|
||||
extends CommonRichTextPubPageState<WhisperDetailPage> {
|
||||
final _whisperDetailController = Get.put(
|
||||
WhisperDetailController(),
|
||||
tag: Utils.makeHeroTag(Get.parameters['talkerId']),
|
||||
@@ -239,7 +239,7 @@ class _WhisperDetailPageState
|
||||
}
|
||||
},
|
||||
child: Obx(
|
||||
() => TextField(
|
||||
() => RichTextField(
|
||||
readOnly: readOnly.value,
|
||||
focusNode: focusNode,
|
||||
controller: editController,
|
||||
@@ -258,7 +258,7 @@ class _WhisperDetailPageState
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(10),
|
||||
),
|
||||
inputFormatters: [LengthLimitingTextInputFormatter(500)],
|
||||
// inputFormatters: [LengthLimitingTextInputFormatter(500)],
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -269,7 +269,7 @@ class _WhisperDetailPageState
|
||||
onPressed: () async {
|
||||
if (enablePublish.value) {
|
||||
_whisperDetailController.sendMsg(
|
||||
message: editController.text,
|
||||
message: editController.rawText,
|
||||
onClearText: editController.clear,
|
||||
);
|
||||
} else {
|
||||
@@ -301,7 +301,6 @@ class _WhisperDetailPageState
|
||||
SmartDialog.showLoading(msg: '正在发送');
|
||||
await _whisperDetailController.sendMsg(
|
||||
picMsg: picMsg,
|
||||
message: editController.text,
|
||||
onClearText: editController.clear,
|
||||
);
|
||||
} else {
|
||||
@@ -331,7 +330,13 @@ class _WhisperDetailPageState
|
||||
Widget? get customPanel => EmotePanel(onChoose: onChooseEmote);
|
||||
|
||||
@override
|
||||
Future<void> onCustomPublish({required String message, List? pictures}) {
|
||||
Future<void> onCustomPublish({List? pictures}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
void onMention([bool fromClick = false]) {}
|
||||
|
||||
@override
|
||||
void onSave() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user