Merge branch 'feature-replyWithPic'

This commit is contained in:
guozhigq
2024-10-21 23:29:13 +08:00
12 changed files with 318 additions and 9 deletions

View File

@ -29,6 +29,8 @@ PODS:
- Flutter
- GT3Captcha-iOS
- GT3Captcha-iOS (0.15.8.3)
- image_picker_ios (0.0.1):
- Flutter
- media_kit_libs_ios_video (1.0.4):
- Flutter
- media_kit_native_event_loop (1.0.0):
@ -80,6 +82,7 @@ DEPENDENCIES:
- flutter_volume_controller (from `.symlinks/plugins/flutter_volume_controller/ios`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- gt3_flutter_plugin (from `.symlinks/plugins/gt3_flutter_plugin/ios`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- media_kit_libs_ios_video (from `.symlinks/plugins/media_kit_libs_ios_video/ios`)
- media_kit_native_event_loop (from `.symlinks/plugins/media_kit_native_event_loop/ios`)
- media_kit_video (from `.symlinks/plugins/media_kit_video/ios`)
@ -129,6 +132,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/fluttertoast/ios"
gt3_flutter_plugin:
:path: ".symlinks/plugins/gt3_flutter_plugin/ios"
image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios"
media_kit_libs_ios_video:
:path: ".symlinks/plugins/media_kit_libs_ios_video/ios"
media_kit_native_event_loop:
@ -179,6 +184,7 @@ SPEC CHECKSUMS:
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
gt3_flutter_plugin: 5bd2c08d3c19cbb6ee3b08f4358439e54c8ab2ee
GT3Captcha-iOS: 5e3b1077834d8a9d6f4d64a447a30af3e14affe6
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
media_kit_libs_ios_video: a5fe24bc7875ccd6378a0978c13185e1344651c1
media_kit_native_event_loop: e6b2ab20cf0746eb1c33be961fcf79667304fa2a
media_kit_video: 5da63f157170e5bf303bf85453b7ef6971218a2e

View File

@ -601,4 +601,7 @@ class Api {
/// 删除评论
static const String replyDel = '/x/v2/reply/del';
/// 图片上传
static const String uploadImage = '/x/dynamic/feed/draw/upload_bfs';
}

View File

@ -1,5 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:image_picker/image_picker.dart';
import '../models/video/reply/data.dart';
import '../models/video/reply/emote.dart';
import 'api.dart';
@ -131,4 +134,44 @@ class ReplyHttp {
return {'status': false, 'msg': res.data['message']};
}
}
// 图片上传
static Future uploadImage({required XFile xFile, String type = 'im'}) async {
var formData = FormData.fromMap({
'file_up': await xFileToMultipartFile(xFile),
'biz': type,
'csrf': await Request.getCsrf(),
'build': 0,
'mobi_app': 'web',
});
var res = await Request().post(
Api.uploadImage,
data: formData,
);
if (res.data['code'] == 0) {
var data = res.data['data'];
data['img_src'] = data['image_url'];
data['img_width'] = data['image_width'];
data['img_height'] = data['image_height'];
data.remove('image_url');
data.remove('image_width');
data.remove('image_height');
return {
'status': true,
'data': data,
};
} else {
return {
'status': false,
'date': [],
'msg': res.data['message'],
};
}
}
static Future<MultipartFile> xFileToMultipartFile(XFile xFile) async {
var file = File(xFile.path);
var bytes = await file.readAsBytes();
return MultipartFile.fromBytes(bytes, filename: xFile.name);
}
}

View File

@ -1,4 +1,6 @@
import 'dart:convert';
import 'dart:developer';
import 'package:dio/dio.dart';
import 'package:hive/hive.dart';
import '../common/constants.dart';
import '../models/common/reply_type.dart';
@ -346,20 +348,34 @@ class VideoHttp {
required String message,
int? root,
int? parent,
List<Map<dynamic, dynamic>>? pictures,
}) async {
if (message == '') {
return {'status': false, 'data': [], 'msg': '请输入评论内容'};
}
var params = <String, dynamic>{
'plat': 1,
'oid': oid,
'type': type.index,
// 'root': root == null || root == 0 ? '' : root,
// 'parent': parent == null || parent == 0 ? '' : parent,
'message': message,
'at_name_to_mid': {},
if (pictures != null) 'pictures': jsonEncode(pictures),
'gaia_source': 'main_web',
'csrf': await Request.getCsrf(),
};
Map sign = await WbiSign().makSign(params);
params.remove('wts');
params.remove('w_rid');
FormData formData = FormData.fromMap({...params});
var res = await Request().post(
Api.replyAdd,
data: {
'type': type.index,
'oid': oid,
'root': root == null || root == 0 ? '' : root,
'parent': parent == null || parent == 0 ? '' : parent,
'message': message,
'csrf': await Request.getCsrf(),
queryParameters: {
'w_rid': sign['w_rid'],
'wts': sign['wts'],
},
data: formData,
);
log(res.toString());
if (res.data['code'] == 0) {

View File

@ -1,13 +1,18 @@
import 'dart:async';
import 'package:cached_network_image/cached_network_image.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';
import 'package:pilipala/http/dynamics.dart';
import 'package:pilipala/http/reply.dart';
import 'package:pilipala/http/video.dart';
import 'package:pilipala/models/common/reply_type.dart';
import 'package:pilipala/models/video/reply/emote.dart';
import 'package:pilipala/models/video/reply/item.dart';
import 'package:pilipala/pages/emote/index.dart';
import 'package:pilipala/plugin/pl_gallery/hero_dialog_route.dart';
import 'package:pilipala/plugin/pl_gallery/interactiveviewer_gallery.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'toolbar_icon_button.dart';
@ -44,6 +49,9 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
RxBool isForward = false.obs;
RxBool showForward = false.obs;
RxString message = ''.obs;
final ImagePicker _picker = ImagePicker();
RxList<String> imageList = [''].obs;
List<Map<dynamic, dynamic>> pictures = [];
@override
void initState() {
@ -60,6 +68,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
if (routePath.startsWith('/video')) {
showForward.value = true;
}
imageList.clear();
}
_autoFocus() async {
@ -90,6 +99,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
message: widget.replyItem != null && widget.replyItem!.root != 0
? ' 回复 @${widget.replyItem!.member!.uname!} : ${message.value}'
: message.value,
pictures: pictures,
);
if (result['status']) {
SmartDialog.showToast(result['data']['success_toast']);
@ -125,6 +135,59 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
);
}
void onChooseImage() async {
if (mounted) {
try {
final XFile? pickedFile =
await _picker.pickImage(source: ImageSource.gallery);
var res = await ReplyHttp.uploadImage(xFile: pickedFile!);
if (res['status']) {
imageList.add(res['data']['img_src']);
pictures.add(res['data']);
}
} catch (e) {
debugPrint('选择图片失败: $e');
}
}
}
void onPreviewImg(picList, initIndex, context) {
Navigator.of(context).push(
HeroDialogRoute<void>(
builder: (BuildContext context) => InteractiveviewerGallery(
sources: picList,
initIndex: initIndex,
itemBuilder: (
BuildContext context,
int index,
bool isFocus,
bool enablePageView,
) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (enablePageView) {
Navigator.of(context).pop();
}
},
child: Center(
child: Hero(
tag: picList[index],
child: CachedNetworkImage(
fadeInDuration: const Duration(milliseconds: 0),
imageUrl: picList[index],
fit: BoxFit.contain,
),
),
),
);
},
onPageChanged: (int pageIndex) {},
),
),
);
}
@override
void didChangeMetrics() {
super.didChangeMetrics();
@ -175,10 +238,11 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ConstrainedBox(
constraints: const BoxConstraints(
maxHeight: 200,
maxHeight: 250,
minHeight: 120,
),
child: Container(
@ -209,6 +273,65 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
),
),
),
Obx(
() => Padding(
padding: const EdgeInsets.fromLTRB(12, 10, 12, 10),
child: SizedBox(
height: 65, // 固定高度以避免无限扩展
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: imageList.length,
itemBuilder: (context, index) {
final url = imageList[index];
return url != ''
? Container(
width: 65,
height: 65,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.secondaryContainer,
borderRadius:
const BorderRadius.all(Radius.circular(6))),
child: InkWell(
onTap: () =>
onPreviewImg(imageList, index, context),
onLongPress: () {
feedBack();
imageList.removeAt(index);
},
child: CachedNetworkImage(
imageUrl: url,
width: 65,
height: 65,
fit: BoxFit.cover,
),
),
)
: const SizedBox();
},
separatorBuilder: (context, index) =>
const SizedBox(width: 8.0),
),
),
),
),
Obx(
() => Visibility(
visible: imageList.isNotEmpty,
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 10),
child: Text(
'点击预览,长按删除',
style: TextStyle(
color: Theme.of(context).colorScheme.outline,
fontSize: 12,
),
),
),
),
),
Divider(
height: 1,
color: Theme.of(context).dividerColor.withOpacity(0.1),
@ -240,7 +363,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
toolbarType: toolbarType,
selected: toolbarType == 'input',
),
const SizedBox(width: 20),
const SizedBox(width: 10),
ToolbarIconButton(
onPressed: () {
if (toolbarType == 'input') {
@ -254,6 +377,15 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
toolbarType: toolbarType,
selected: toolbarType == 'emote',
),
if (widget.root != null && widget.root == 0) ...[
const SizedBox(width: 10),
ToolbarIconButton(
onPressed: onChooseImage,
icon: const Icon(Icons.photo, size: 22),
toolbarType: toolbarType,
selected: toolbarType == 'picture',
),
],
const SizedBox(width: 6),
Obx(
() => showForward.value

View File

@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_volume_controller/flutter_volume_controller_plugin.h>
#include <gtk/gtk_plugin.h>
#include <media_kit_libs_linux/media_kit_libs_linux_plugin.h>
@ -17,6 +18,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) flutter_volume_controller_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterVolumeControllerPlugin");
flutter_volume_controller_plugin_register_with_registrar(flutter_volume_controller_registrar);

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
file_selector_linux
flutter_volume_controller
gtk
media_kit_libs_linux

View File

@ -11,6 +11,7 @@ import audio_session
import connectivity_plus
import device_info_plus
import dynamic_color
import file_selector_macos
import flutter_volume_controller
import media_kit_libs_macos_video
import media_kit_video
@ -29,6 +30,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterVolumeControllerPlugin.register(with: registry.registrar(forPlugin: "FlutterVolumeControllerPlugin"))
MediaKitLibsMacosVideoPlugin.register(with: registry.registrar(forPlugin: "MediaKitLibsMacosVideoPlugin"))
MediaKitVideoPlugin.register(with: registry.registrar(forPlugin: "MediaKitVideoPlugin"))

View File

@ -529,6 +529,38 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "7.0.0"
file_selector_linux:
dependency: transitive
description:
name: file_selector_linux
sha256: "045d372bf19b02aeb69cacf8b4009555fb5f6f0b7ad8016e5f46dd1387ddd492"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.2+1"
file_selector_macos:
dependency: transitive
description:
name: file_selector_macos
sha256: cb284e267f8e2a45a904b5c094d2ba51d0aabfc20b1538ab786d9ef7dc2bf75c
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.4+1"
file_selector_platform_interface:
dependency: transitive
description:
name: file_selector_platform_interface
sha256: a3994c26f10378a039faa11de174d7b78eb8f79e4dd0af2a451410c1a5c3f66b
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.6.2"
file_selector_windows:
dependency: transitive
description:
name: file_selector_windows
sha256: "2ad726953f6e8affbc4df8dc78b77c3b4a060967a291e528ef72ae846c60fb69"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.3+2"
fixnum:
dependency: transitive
description:
@ -782,6 +814,70 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.1.3"
image_picker:
dependency: "direct main"
description:
name: image_picker
sha256: "021834d9c0c3de46bf0fe40341fa07168407f694d9b2bb18d532dc1261867f7a"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.2"
image_picker_android:
dependency: transitive
description:
name: image_picker_android
sha256: "0f57fee1e8bfadf8cc41818bbcd7f72e53bb768a54d9496355d5e8a5681a19f1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.8.12+1"
image_picker_for_web:
dependency: transitive
description:
name: image_picker_for_web
sha256: "65d94623e15372c5c51bebbcb820848d7bcb323836e12dfdba60b5d3a8b39e50"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.5"
image_picker_ios:
dependency: transitive
description:
name: image_picker_ios
sha256: "6703696ad49f5c3c8356d576d7ace84d1faf459afb07accbb0fae780753ff447"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.8.12"
image_picker_linux:
dependency: transitive
description:
name: image_picker_linux
sha256: "4ed1d9bb36f7cd60aa6e6cd479779cc56a4cb4e4de8f49d487b1aaad831300fa"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.1+1"
image_picker_macos:
dependency: transitive
description:
name: image_picker_macos
sha256: "3f5ad1e8112a9a6111c46d0b57a7be2286a9a07fc6e1976fdf5be2bd31d4ff62"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.1+1"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
sha256: "9ec26d410ff46f483c5519c29c02ef0e02e13a543f882b152d4bfd2f06802f80"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.10.0"
image_picker_windows:
dependency: transitive
description:
name: image_picker_windows
sha256: "6ad07afc4eb1bc25f3a01084d28520496c4a3bb0cb13685435838167c9dcedeb"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.1+1"
intl:
dependency: transitive
description:

View File

@ -151,6 +151,8 @@ dependencies:
brotli: ^0.6.0
# 文本语法高亮
re_highlight: ^0.0.3
# 图片选择器
image_picker: ^1.1.2
dev_dependencies:
flutter_test:

View File

@ -9,6 +9,7 @@
#include <app_links/app_links_plugin_c_api.h>
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <dynamic_color/dynamic_color_plugin_c_api.h>
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_volume_controller/flutter_volume_controller_plugin_c_api.h>
#include <media_kit_libs_windows_video/media_kit_libs_windows_video_plugin_c_api.h>
#include <media_kit_video/media_kit_video_plugin_c_api.h>
@ -24,6 +25,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
DynamicColorPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FlutterVolumeControllerPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterVolumeControllerPluginCApi"));
MediaKitLibsWindowsVideoPluginCApiRegisterWithRegistrar(

View File

@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
app_links
connectivity_plus
dynamic_color
file_selector_windows
flutter_volume_controller
media_kit_libs_windows_video
media_kit_video