Commit 8db55406 by tanghuan

dev

1 parent 3ce6d8ec
import 'dart:io';
import 'package:appframe/l10n/gen/app_localizations.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
......@@ -16,6 +17,8 @@ class App extends StatelessWidget {
theme: const CupertinoThemeData(primaryColor: CupertinoColors.systemBlue),
)
: MaterialApp.router(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
routerConfig: router,
title: '班小二',
theme: ThemeData(primarySwatch: Colors.blue),
......
......@@ -62,6 +62,7 @@ class WechatAuthCubit extends Cubit<WechatAuthState> {
// _textEditingController = TextEditingController()..text = '127.0.0.1';
_textEditingController = TextEditingController()..text = 'appdev-th.banxiaoer.net';
// _textEditingController = TextEditingController()..text = 'appdev-xj.banxiaoer.net';
// _textEditingController = TextEditingController()..text = '192.168.1.136';
_wechatAuthRepository = getIt<WechatAuthRepository>();
......
......@@ -17,6 +17,7 @@ import 'package:appframe/data/repositories/message/orientation_handler.dart';
import 'package:appframe/data/repositories/message/save_file_to_disk_handler.dart';
import 'package:appframe/data/repositories/message/save_to_album_handler.dart';
import 'package:appframe/data/repositories/message/scan_code_handler.dart';
import 'package:appframe/data/repositories/message/set_title_handler.dart';
import 'package:appframe/data/repositories/message/storage_handler.dart';
import 'package:appframe/data/repositories/message/upload_file.dart';
import 'package:appframe/data/repositories/message/vibrate_short_handler.dart';
......@@ -107,7 +108,7 @@ Future<void> setupLocator() async {
/// 获取视频信息
getIt.registerLazySingleton<MessageHandler>(() => VideoInfoHandler(), instanceName: 'getVideoInfo');
/// 保存文件
/// 保存文件到客户端文件系统
getIt.registerLazySingleton<MessageHandler>(() => SaveFileToDisKHandler(), instanceName: 'saveFileToDisk');
/// 保存文件/视频到相册
......@@ -120,7 +121,7 @@ Future<void> setupLocator() async {
/// 视频压缩
getIt.registerLazySingleton<MessageHandler>(() => CompressVideoHandler(), instanceName: 'compressVideo');
/// 保存文件到客户端文件系统
/// 打开文档
getIt.registerLazySingleton<MessageHandler>(() => OpenDocumentHandler(), instanceName: 'openDocument');
/// 录音
......@@ -150,6 +151,9 @@ Future<void> setupLocator() async {
/// 下载文件
getIt.registerLazySingleton<MessageHandler>(() => DownloadFileHandler(), instanceName: 'downloadFile');
/// 设置标题和返回按钮
getIt.registerLazySingleton<MessageHandler>(() => SetTitleHandler(), instanceName: 'setTitle');
/// service
getIt.registerLazySingleton<ApiService>(() => ApiService(baseUrl: 'https://dev.banxiaoer.net'));
......
......@@ -3,5 +3,5 @@ import 'package:fluwx/fluwx.dart';
final Fluwx fluwx = Fluwx();
Future<void> registerWechatApi() async {
await fluwx.registerApi(appId: "wx8c32ea248f0c7765", universalLink: "https://univerallink.banxe.cn/link/");
await fluwx.registerApi(appId: "wx8c32ea248f0c7765", universalLink: "https://dev.banxiaoer.net/path/to/wechat/");
}
......@@ -3,6 +3,6 @@ import 'package:appframe/services/dispatcher.dart';
class AppInfoHandler extends MessageHandler {
@override
Future<Map<String, dynamic>> handleMessage(params) async {
return {"version": "0.1", "build": "light"};
return {"version": "0.1", "theme": "light"};
}
}
import 'dart:io';
import 'package:appframe/services/dispatcher.dart';
import 'package:http/http.dart' as http;
import 'package:path_provider/path_provider.dart';
import 'package:url_launcher/url_launcher.dart';
class OpenDocumentHandler extends MessageHandler {
@override
......@@ -10,80 +7,22 @@ class OpenDocumentHandler extends MessageHandler {
if (params is! Map<String, dynamic>) {
throw Exception('参数错误');
}
final url = params['url'] as String?;
if (url == null || url.isEmpty) {
final url = params['url'] as String;
if (url.isEmpty) {
throw Exception('参数错误');
}
if (url.startsWith("http://")) {
await saveNetworkImageToExternalStorage(url);
} else {
await saveLocalFileToExternalStorage(url);
}
return await _launchInBrowser(Uri.parse(url));
}
Future<bool> saveLocalFileToExternalStorage(String sourcePath) async {
try {
// 获取外部存储目录
final directory = await getExternalStorageDirectory();
// 获取文件名
final fileName = sourcePath.split('/').last;
var destinationPath = '${directory?.path}/$fileName';
// 检查文件是否存在,如果存在则生成新文件名
var counter = 1;
while (await File(destinationPath).exists()) {
final extension = fileName.split('.').last;
final nameWithoutExtension = fileName.substring(0, fileName.length - extension.length - 1);
destinationPath = '${directory?.path}/${nameWithoutExtension}_$counter.$extension}';
counter++;
}
// 复制文件
final sourceFile = File(sourcePath);
await sourceFile.copy(destinationPath);
return true;
} catch (e) {
print('保存文件失败: $e');
return false;
}
}
Future<bool> saveNetworkImageToExternalStorage(String imageUrl) async {
try {
// 获取外部存储目录
final directory = await getExternalStorageDirectory();
// 从URL获取文件名
final fileName = imageUrl.split('/').last;
var filePath = '${directory?.path}/$fileName';
// 检查文件是否存在,如果存在则生成新文件名
var counter = 1;
while (await File(filePath).exists()) {
final extension = fileName.split('.').last;
final nameWithoutExtension = fileName.substring(0, fileName.length - extension.length - 1);
filePath = '${directory?.path}/${nameWithoutExtension}_$counter.$extension}';
counter++;
}
// 下载网络图片
final response = await http.get(Uri.parse(imageUrl));
if (response.statusCode == 200) {
// 保存到外部存储
final file = File(filePath);
await file.writeAsBytes(response.bodyBytes);
return true;
} else {
print('下载失败: ${response.statusCode}');
return false;
}
} catch (e) {
print('保存失败: $e');
return false;
Future<bool> _launchInBrowser(Uri url) async {
if (await canLaunchUrl(url)) {
return await launchUrl(url, mode: LaunchMode.platformDefault);
} else {
throw Exception('Could not launch $url');
}
/*if (!await launchUrl(url, mode: LaunchMode.externalNonBrowserApplication)) {
throw Exception('Could not launch $url');
}*/
}
}
import 'package:appframe/config/locator.dart';
import 'package:appframe/bloc/web_cubit.dart';
import 'package:appframe/services/dispatcher.dart';
import 'package:shared_preferences/shared_preferences.dart';
class OrientationHandler extends MessageHandler {
late WebCubit? _webCubit;
late String? _message;
@override
void setCubit(WebCubit cubit) {
this._webCubit = cubit;
}
void _unfollowCubit() {
this._webCubit = null;
}
@override
void setMessage(String message) {
this._message = message;
}
@override
Future<dynamic> handleMessage(params) async {
final orientation = getIt.get<SharedPreferences>().get("orientation");
return {'type': orientation ?? 'portrait'};
_webCubit!.setOrientationCmdFlag(true, _message!);
}
}
import 'package:appframe/bloc/web_cubit.dart';
import 'package:appframe/services/dispatcher.dart';
class SetTitleHandler extends MessageHandler {
late WebCubit? _webCubit;
@override
void setCubit(WebCubit cubit) {
this._webCubit = cubit;
}
void _unfollowCubit() {
this._webCubit = null;
}
@override
Future<dynamic> handleMessage(params) async {
if (params is! Map<String, dynamic>) {
throw Exception('参数错误');
}
final String title = params['title'] as String;
final bool showBack = params['showBack'] as bool;
return _webCubit!.setTitle(title, showBack);
}
}
......@@ -19,8 +19,8 @@ class UploadFileHandler extends MessageHandler {
throw Exception('参数错误');
}
// final result = await compute(_handleUpload, {'filePath': tempFilePath});
final result = await _handleUpload({'filePath': tempFilePath});
final result = await compute(_handleUpload, {'filePath': tempFilePath});
// final result = await _handleUpload({'filePath': tempFilePath});
return result;
}
......@@ -57,7 +57,7 @@ class UploadFileHandler extends MessageHandler {
bxeApiService.close();
obsApiService.close();
return {'location': response.data['location']};
return {'url': response.data['location']};
}
/// 并行上传
......
import 'dart:convert';
import 'package:appframe/config/locator.dart';
import 'package:appframe/bloc/web_cubit.dart';
import 'package:appframe/services/dispatcher.dart';
import 'package:shared_preferences/shared_preferences.dart';
class WindowInfoHandler extends MessageHandler {
late WebCubit? _webCubit;
late String? _message;
@override
void setCubit(WebCubit cubit) {
this._webCubit = cubit;
}
void _unfollowCubit() {
this._webCubit = null;
}
@override
void setMessage(String message) {
this._message = message;
}
@override
Future<dynamic> handleMessage(dynamic params) async {
final windowInfo = getIt.get<SharedPreferences>().getString('windowInfo');
return jsonDecode(windowInfo!);
_webCubit!.setWindowInfoCmdFlag(true, _message!);
}
}
{
"@@locale": "en",
"appTitle": "WeChat Asset Picker Demo",
"appVersion": "Version: {version}",
"appVersionUnknown": "unknown",
"navMulti": "Multi",
"navSingle": "Single",
"navCustom": "Custom",
"selectedAssetsText": "Selected Assets",
"pickMethodNotice": "Pickers in this page are located at the {dist}, defined by `pickMethods`.",
"pickMethodImageName": "Image picker",
"pickMethodImageDescription": "Only pick image from device.",
"pickMethodVideoName": "Video picker",
"pickMethodVideoDescription": "Only pick video from device. (Includes Live Photos on iOS and macOS.)",
"pickMethodAudioName": "Audio picker",
"pickMethodAudioDescription": "Only pick audio from device.",
"pickMethodLivePhotoName": "Live Photo picker",
"pickMethodLivePhotoDescription": "Only pick Live Photos from device.",
"pickMethodCameraName": "Pick from camera",
"pickMethodCameraDescription": "Allow to pick an asset through camera.",
"pickMethodCameraAndStayName": "Pick from camera and stay",
"pickMethodCameraAndStayDescription": "Take a photo or video with the camera picker, select the result and stay in the entities list.",
"pickMethodCommonName": "Common picker",
"pickMethodCommonDescription": "Pick images and videos.",
"pickMethodThreeItemsGridName": "3 items grid",
"pickMethodThreeItemsGridDescription": "Picker will served as 3 items on cross axis. (pageSize must be a multiple of the gridCount)",
"pickMethodCustomFilterOptionsName": "Custom filter options",
"pickMethodCustomFilterOptionsDescription": "Add filter options for the picker.",
"pickMethodPrependItemName": "Prepend special item",
"pickMethodPrependItemDescription": "A special item will prepend to the assets grid.",
"pickMethodNoPreviewName": "No preview",
"pickMethodNoPreviewDescription": "You cannot preview assets during the picking, the behavior is like the WhatsApp/MegaTok pattern.",
"pickMethodKeepScrollOffsetName": "Keep scroll offset",
"pickMethodKeepScrollOffsetDescription": "Pick assets from same scroll position.",
"pickMethodChangeLanguagesName": "Change Languages",
"pickMethodChangeLanguagesDescription": "Pass AssetPickerTextDelegate to change between languages (e.g. EnglishAssetPickerTextDelegate).",
"pickMethodPreventGIFPickedName": "Prevent GIF being picked",
"pickMethodPreventGIFPickedDescription": "Use selectPredicate to banned GIF picking when tapped.",
"pickMethodCustomizableThemeName": "Customizable theme (ThemeData)",
"pickMethodCustomizableThemeDescription": "Picking assets with the light theme or with a different color.",
"pickMethodPathNameBuilderName": "Path name builder",
"pickMethodPathNameBuilderDescription": "Add \uD83C\uDF6D after paths name.",
"pickMethodWeChatMomentName": "WeChat Moment",
"pickMethodWeChatMomentDescription": "Pick assets with images or only 1 video.",
"pickMethodCustomImagePreviewThumbSizeName": "Custom image preview thumb size",
"pickMethodCustomImagePreviewThumbSizeDescription": "You can reduce the thumb size to get faster load speed.",
"customPickerNotice": "This page contains customized pickers with different asset types, different UI layouts, or some use case for specific apps. Contribute to add your custom picker are welcomed.\nPickers in this page are located at the lib/customs/pickers folder.",
"customPickerCallThePickerButton": "\uD83C\uDF81 Call the Picker",
"customPickerDirectoryAndFileName": "Directory+File picker",
"customPickerDirectoryAndFileDescription": "This is a custom picker built for `File`.\nBy browsing this picker, we want you to know that you can build your own picker components using the entity's type you desired.\n\nIn this page, picker will grab files from `getApplicationDocumentsDirectory`, then check whether it contains images. Put files into the path to see how this custom picker work.",
"customPickerMultiTabName": "Multi tab picker",
"customPickerMultiTabDescription": "The picker contains multiple tab with different types of assets for the picking at the same time.",
"customPickerMultiTabTab1": "All",
"customPickerMultiTabTab2": "Videos",
"customPickerMultiTabTab3": "Images",
"customPickerInstagramLayoutName": "Instagram layout picker",
"customPickerInstagramLayoutDescription": "The picker reproduces Instagram layout with preview and scroll animations. It's also published as the package insta_assets_picker."
}
\ No newline at end of file
{
"@@locale": "zh",
"appTitle": "WeChat Asset Picker 示例",
"appVersion": "版本:{version}",
"appVersionUnknown": "未知",
"navMulti": "多选",
"navSingle": "单选",
"navCustom": "自定义",
"selectedAssetsText": "已选的资源",
"pickMethodNotice": "该页面的所有选择器的代码位于 {dist},由 `pickMethods` 定义。",
"pickMethodCommonName": "常用选择",
"pickMethodCommonDescription": "选择图片和视频。",
"pickMethodImageName": "图片选择",
"pickMethodImageDescription": "仅选择图片。",
"pickMethodVideoName": "视频选择",
"pickMethodVideoDescription": "仅选择视频。",
"pickMethodAudioName": "音频选择",
"pickMethodAudioDescription": "仅选择音频。",
"pickMethodLivePhotoName": "实况图片选择",
"pickMethodLivePhotoDescription": "仅选择实况图片。",
"pickMethodCameraName": "从相机生成选择",
"pickMethodCameraDescription": "通过相机拍照生成并选择资源",
"pickMethodCameraAndStayName": "从相机生成选择并停留",
"pickMethodCameraAndStayDescription": "通过相机拍照生成选择资源,并停留在选择界面。",
"pickMethodThreeItemsGridName": "横向 3 格",
"pickMethodThreeItemsGridDescription": "选择器每行为 3 格。(pageSize 必须为 gridCount 的倍数)",
"pickMethodCustomFilterOptionsName": "自定义过滤条件",
"pickMethodCustomFilterOptionsDescription": "为选择器添加自定义过滤条件。",
"pickMethodPrependItemName": "往网格前插入 widget",
"pickMethodPrependItemDescription": "网格的靠前位置会添加一个自定义的 widget。",
"pickMethodNoPreviewName": "禁止预览",
"pickMethodNoPreviewDescription": "无法预览选择的资源,与 WhatsApp/MegaTok 的行为类似。",
"pickMethodKeepScrollOffsetName": "保持滚动位置",
"pickMethodKeepScrollOffsetDescription": "可以从上次滚动到的位置再次开始选择。",
"pickMethodChangeLanguagesName": "更改语言",
"pickMethodChangeLanguagesDescription": "传入 AssetPickerTextDelegate 手动更改选择器的语言(例如 EnglishAssetPickerTextDelegate)。",
"pickMethodPreventGIFPickedName": "禁止选择 GIF 图片",
"pickMethodPreventGIFPickedDescription": "通过 selectPredicate 来禁止 GIF 图片在点击时被选择。",
"pickMethodCustomizableThemeName": "自定义主题 (ThemeData)",
"pickMethodCustomizableThemeDescription": "可以用亮色或其他颜色及自定义的主题进行选择。",
"pickMethodPathNameBuilderName": "构建路径名称",
"pickMethodPathNameBuilderDescription": "在路径后添加 \uD83C\uDF6D 进行自定义。",
"pickMethodWeChatMomentName": "微信朋友圈模式",
"pickMethodWeChatMomentDescription": "允许选择图片或仅 1 个视频。",
"pickMethodCustomImagePreviewThumbSizeName": "自定义图片预览的缩略图大小",
"pickMethodCustomImagePreviewThumbSizeDescription": "通过降低缩略图的质量来获得更快的加载速度。",
"customPickerNotice": "本页面包含了多种方式、不同界面和特定应用的自定义选择器。欢迎贡献添加你自定义的选择器。\n该页面的所有选择器的代码位于 lib/customs/pickers 目录。",
"customPickerCallThePickerButton": "\uD83C\uDF81 开始选择资源",
"customPickerDirectoryAndFileName": "Directory+File 选择器",
"customPickerDirectoryAndFileDescription": "为 `File` 构建的自定义选择器。\n通过阅读该选择器的源码,你可以学习如何完全以你自定义的资源类型来构建并选择器的界面。\n\n该选择器会从 `getApplicationDocumentsDirectory` 目录获取资源,然后检查它是否包含图片。你需要将图片放在该目录来查看选择器的效果。",
"customPickerMultiTabName": "多 Tab 选择器",
"customPickerMultiTabDescription": "该选择器会以多 Tab 的形式同时展示多种资源类型的选择器。",
"customPickerMultiTabTab1": "全部",
"customPickerMultiTabTab2": "视频",
"customPickerMultiTabTab3": "图片",
"customPickerInstagramLayoutName": "Instagram 布局的选择器",
"customPickerInstagramLayoutDescription": "该选择器以 Instagram 的布局模式构建,在选择时可以同时预览。其已发布为单独的 package:insta_assets_picker。"
}
\ No newline at end of file
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'app_localizations.dart';
// ignore_for_file: type=lint
/// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations {
AppLocalizationsEn([String locale = 'en']) : super(locale);
@override
String get appTitle => 'WeChat Asset Picker Demo';
@override
String appVersion(Object version) {
return 'Version: $version';
}
@override
String get appVersionUnknown => 'unknown';
@override
String get navMulti => 'Multi';
@override
String get navSingle => 'Single';
@override
String get navCustom => 'Custom';
@override
String get selectedAssetsText => 'Selected Assets';
@override
String pickMethodNotice(Object dist) {
return 'Pickers in this page are located at the $dist, defined by `pickMethods`.';
}
@override
String get pickMethodImageName => 'Image picker';
@override
String get pickMethodImageDescription => 'Only pick image from device.';
@override
String get pickMethodVideoName => 'Video picker';
@override
String get pickMethodVideoDescription =>
'Only pick video from device. (Includes Live Photos on iOS and macOS.)';
@override
String get pickMethodAudioName => 'Audio picker';
@override
String get pickMethodAudioDescription => 'Only pick audio from device.';
@override
String get pickMethodLivePhotoName => 'Live Photo picker';
@override
String get pickMethodLivePhotoDescription =>
'Only pick Live Photos from device.';
@override
String get pickMethodCameraName => 'Pick from camera';
@override
String get pickMethodCameraDescription =>
'Allow to pick an asset through camera.';
@override
String get pickMethodCameraAndStayName => 'Pick from camera and stay';
@override
String get pickMethodCameraAndStayDescription =>
'Take a photo or video with the camera picker, select the result and stay in the entities list.';
@override
String get pickMethodCommonName => 'Common picker';
@override
String get pickMethodCommonDescription => 'Pick images and videos.';
@override
String get pickMethodThreeItemsGridName => '3 items grid';
@override
String get pickMethodThreeItemsGridDescription =>
'Picker will served as 3 items on cross axis. (pageSize must be a multiple of the gridCount)';
@override
String get pickMethodCustomFilterOptionsName => 'Custom filter options';
@override
String get pickMethodCustomFilterOptionsDescription =>
'Add filter options for the picker.';
@override
String get pickMethodPrependItemName => 'Prepend special item';
@override
String get pickMethodPrependItemDescription =>
'A special item will prepend to the assets grid.';
@override
String get pickMethodNoPreviewName => 'No preview';
@override
String get pickMethodNoPreviewDescription =>
'You cannot preview assets during the picking, the behavior is like the WhatsApp/MegaTok pattern.';
@override
String get pickMethodKeepScrollOffsetName => 'Keep scroll offset';
@override
String get pickMethodKeepScrollOffsetDescription =>
'Pick assets from same scroll position.';
@override
String get pickMethodChangeLanguagesName => 'Change Languages';
@override
String get pickMethodChangeLanguagesDescription =>
'Pass AssetPickerTextDelegate to change between languages (e.g. EnglishAssetPickerTextDelegate).';
@override
String get pickMethodPreventGIFPickedName => 'Prevent GIF being picked';
@override
String get pickMethodPreventGIFPickedDescription =>
'Use selectPredicate to banned GIF picking when tapped.';
@override
String get pickMethodCustomizableThemeName =>
'Customizable theme (ThemeData)';
@override
String get pickMethodCustomizableThemeDescription =>
'Picking assets with the light theme or with a different color.';
@override
String get pickMethodPathNameBuilderName => 'Path name builder';
@override
String get pickMethodPathNameBuilderDescription => 'Add 🍭 after paths name.';
@override
String get pickMethodWeChatMomentName => 'WeChat Moment';
@override
String get pickMethodWeChatMomentDescription =>
'Pick assets with images or only 1 video.';
@override
String get pickMethodCustomImagePreviewThumbSizeName =>
'Custom image preview thumb size';
@override
String get pickMethodCustomImagePreviewThumbSizeDescription =>
'You can reduce the thumb size to get faster load speed.';
@override
String get customPickerNotice =>
'This page contains customized pickers with different asset types, different UI layouts, or some use case for specific apps. Contribute to add your custom picker are welcomed.\nPickers in this page are located at the lib/customs/pickers folder.';
@override
String get customPickerCallThePickerButton => '🎁 Call the Picker';
@override
String get customPickerDirectoryAndFileName => 'Directory+File picker';
@override
String get customPickerDirectoryAndFileDescription =>
'This is a custom picker built for `File`.\nBy browsing this picker, we want you to know that you can build your own picker components using the entity\'s type you desired.\n\nIn this page, picker will grab files from `getApplicationDocumentsDirectory`, then check whether it contains images. Put files into the path to see how this custom picker work.';
@override
String get customPickerMultiTabName => 'Multi tab picker';
@override
String get customPickerMultiTabDescription =>
'The picker contains multiple tab with different types of assets for the picking at the same time.';
@override
String get customPickerMultiTabTab1 => 'All';
@override
String get customPickerMultiTabTab2 => 'Videos';
@override
String get customPickerMultiTabTab3 => 'Images';
@override
String get customPickerInstagramLayoutName => 'Instagram layout picker';
@override
String get customPickerInstagramLayoutDescription =>
'The picker reproduces Instagram layout with preview and scroll animations. It\'s also published as the package insta_assets_picker.';
}
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'app_localizations.dart';
// ignore_for_file: type=lint
/// The translations for Chinese (`zh`).
class AppLocalizationsZh extends AppLocalizations {
AppLocalizationsZh([String locale = 'zh']) : super(locale);
@override
String get appTitle => 'WeChat Asset Picker 示例';
@override
String appVersion(Object version) {
return '版本:$version';
}
@override
String get appVersionUnknown => '未知';
@override
String get navMulti => '多选';
@override
String get navSingle => '单选';
@override
String get navCustom => '自定义';
@override
String get selectedAssetsText => '已选的资源';
@override
String pickMethodNotice(Object dist) {
return '该页面的所有选择器的代码位于 $dist,由 `pickMethods` 定义。';
}
@override
String get pickMethodImageName => '图片选择';
@override
String get pickMethodImageDescription => '仅选择图片。';
@override
String get pickMethodVideoName => '视频选择';
@override
String get pickMethodVideoDescription => '仅选择视频。';
@override
String get pickMethodAudioName => '音频选择';
@override
String get pickMethodAudioDescription => '仅选择音频。';
@override
String get pickMethodLivePhotoName => '实况图片选择';
@override
String get pickMethodLivePhotoDescription => '仅选择实况图片。';
@override
String get pickMethodCameraName => '从相机生成选择';
@override
String get pickMethodCameraDescription => '通过相机拍照生成并选择资源';
@override
String get pickMethodCameraAndStayName => '从相机生成选择并停留';
@override
String get pickMethodCameraAndStayDescription => '通过相机拍照生成选择资源,并停留在选择界面。';
@override
String get pickMethodCommonName => '常用选择';
@override
String get pickMethodCommonDescription => '选择图片和视频。';
@override
String get pickMethodThreeItemsGridName => '横向 3 格';
@override
String get pickMethodThreeItemsGridDescription =>
'选择器每行为 3 格。(pageSize 必须为 gridCount 的倍数)';
@override
String get pickMethodCustomFilterOptionsName => '自定义过滤条件';
@override
String get pickMethodCustomFilterOptionsDescription => '为选择器添加自定义过滤条件。';
@override
String get pickMethodPrependItemName => '往网格前插入 widget';
@override
String get pickMethodPrependItemDescription => '网格的靠前位置会添加一个自定义的 widget。';
@override
String get pickMethodNoPreviewName => '禁止预览';
@override
String get pickMethodNoPreviewDescription =>
'无法预览选择的资源,与 WhatsApp/MegaTok 的行为类似。';
@override
String get pickMethodKeepScrollOffsetName => '保持滚动位置';
@override
String get pickMethodKeepScrollOffsetDescription => '可以从上次滚动到的位置再次开始选择。';
@override
String get pickMethodChangeLanguagesName => '更改语言';
@override
String get pickMethodChangeLanguagesDescription =>
'传入 AssetPickerTextDelegate 手动更改选择器的语言(例如 EnglishAssetPickerTextDelegate)。';
@override
String get pickMethodPreventGIFPickedName => '禁止选择 GIF 图片';
@override
String get pickMethodPreventGIFPickedDescription =>
'通过 selectPredicate 来禁止 GIF 图片在点击时被选择。';
@override
String get pickMethodCustomizableThemeName => '自定义主题 (ThemeData)';
@override
String get pickMethodCustomizableThemeDescription => '可以用亮色或其他颜色及自定义的主题进行选择。';
@override
String get pickMethodPathNameBuilderName => '构建路径名称';
@override
String get pickMethodPathNameBuilderDescription => '在路径后添加 🍭 进行自定义。';
@override
String get pickMethodWeChatMomentName => '微信朋友圈模式';
@override
String get pickMethodWeChatMomentDescription => '允许选择图片或仅 1 个视频。';
@override
String get pickMethodCustomImagePreviewThumbSizeName => '自定义图片预览的缩略图大小';
@override
String get pickMethodCustomImagePreviewThumbSizeDescription =>
'通过降低缩略图的质量来获得更快的加载速度。';
@override
String get customPickerNotice =>
'本页面包含了多种方式、不同界面和特定应用的自定义选择器。欢迎贡献添加你自定义的选择器。\n该页面的所有选择器的代码位于 lib/customs/pickers 目录。';
@override
String get customPickerCallThePickerButton => '🎁 开始选择资源';
@override
String get customPickerDirectoryAndFileName => 'Directory+File 选择器';
@override
String get customPickerDirectoryAndFileDescription =>
'为 `File` 构建的自定义选择器。\n通过阅读该选择器的源码,你可以学习如何完全以你自定义的资源类型来构建并选择器的界面。\n\n该选择器会从 `getApplicationDocumentsDirectory` 目录获取资源,然后检查它是否包含图片。你需要将图片放在该目录来查看选择器的效果。';
@override
String get customPickerMultiTabName => '多 Tab 选择器';
@override
String get customPickerMultiTabDescription =>
'该选择器会以多 Tab 的形式同时展示多种资源类型的选择器。';
@override
String get customPickerMultiTabTab1 => '全部';
@override
String get customPickerMultiTabTab2 => '视频';
@override
String get customPickerMultiTabTab3 => '图片';
@override
String get customPickerInstagramLayoutName => 'Instagram 布局的选择器';
@override
String get customPickerInstagramLayoutDescription =>
'该选择器以 Instagram 的布局模式构建,在选择时可以同时预览。其已发布为单独的 package:insta_assets_picker。';
}
import 'dart:convert';
import 'package:appframe/bloc/web_cubit.dart';
import 'package:appframe/config/locator.dart';
import 'package:appframe/data/models/message/h5_message.dart';
......@@ -5,11 +7,11 @@ import 'package:appframe/data/models/message/h5_resp.dart';
// 消息处理器抽象类
abstract class MessageHandler {
// Future<Map<String, dynamic>> handleMessage(Map<String, dynamic> params);
// Future<dynamic> handleMessage(Map<String, dynamic> params);
Future<dynamic> handleMessage(dynamic params);
void setCubit(WebCubit cubit) {}
void setMessage(String message) {}
}
// 消息分发器
......@@ -27,7 +29,10 @@ class MessageDispatcher {
}
// 分发处理
Future<void> dispatch(H5Message h5Message, Function callback, {WebCubit? webCubit}) async {
Future<void> dispatch(String message, Function callback, {WebCubit? webCubit}) async {
final Map<String, dynamic> data = json.decode(message);
H5Message h5Message = H5Message.fromJson(data);
var handler = _handlers[h5Message.cmd];
if (handler == null) {
try {
......@@ -43,11 +48,21 @@ class MessageDispatcher {
try {
// 设置传递的cubit,进行业务操作
if (h5Message.cmd == 'scanCode' || h5Message.cmd.startsWith("audio")) {
if (h5Message.cmd == 'scanCode' ||
h5Message.cmd == "getOrientation" ||
h5Message.cmd == "getWindowInfo" ||
h5Message.cmd == "chooseImage" ||
h5Message.cmd.startsWith("audio") ||
h5Message.cmd.startsWith("setTitle")) {
handler.setCubit(webCubit!);
handler.setMessage(message);
}
final result = await handler.handleMessage(h5Message.params);
// 有些命令需要通过监听器调用Cubit,触发调用时不需要返回结果,不处理回调
if (result == null) {
return;
}
H5Resp h5Resp = H5Resp(h5Message.unique, h5Message.cmd, result, '');
callback(h5Resp.toJson());
} catch (e) {
......
......@@ -6,8 +6,8 @@ import 'package:flutter/services.dart';
class LocalServerService {
// 启动本地HTTP服务器
Future<HttpServer> startLocalServer() async {
//HttpServer server = await HttpServer.bind(InternetAddress.loopbackIPv4, 35982);
HttpServer server = await HttpServer.bind(InternetAddress.loopbackIPv4, 8080);
HttpServer server = await HttpServer.bind(InternetAddress.loopbackIPv4, 35982);
// HttpServer server = await HttpServer.bind(InternetAddress.loopbackIPv4, 8080);
print('本地服务器启动在端口: ${server.port}');
server.listen((HttpRequest request) async {
......
......@@ -21,7 +21,7 @@ class _RecorderWidgetState extends State<RecorderWidget> {
late BuildContext _context;
@override
Widget build(BuildContext context) {
Widget build(BuildContext buildContext) {
return SizedBox(
);
}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!