From c161ab47306ca4cefde63f36a08e8772e6c177de Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Tue, 29 Jun 2021 18:25:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=20=E7=AD=BE=E5=90=8D?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=20=E4=BF=AE=E6=94=B9pdf=20view=20=E4=B8=BA?= =?UTF-8?q?=20advance=20pdf=20viewer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/generated_plugin_registrant.dart | 2 - .../profile/house/contract_preview_page.dart | 66 ++++++++++---- lib/ui/profile/house/house_func.dart | 17 ++-- lib/utils/network/net_util.dart | 17 +++- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 91 ++++++++++++------- pubspec.yaml | 4 +- 7 files changed, 134 insertions(+), 65 deletions(-) diff --git a/lib/generated_plugin_registrant.dart b/lib/generated_plugin_registrant.dart index a8fa733e..222a4e7a 100644 --- a/lib/generated_plugin_registrant.dart +++ b/lib/generated_plugin_registrant.dart @@ -9,7 +9,6 @@ import 'package:firebase_core_web/firebase_core_web.dart'; import 'package:image_picker_for_web/image_picker_for_web.dart'; import 'package:package_info_plus_web/package_info_plus_web.dart'; import 'package:shared_preferences_web/shared_preferences_web.dart'; -import 'package:syncfusion_flutter_pdfviewer_web/pdfviewer_web.dart'; import 'package:url_launcher_web/url_launcher_web.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; @@ -21,7 +20,6 @@ void registerPlugins(Registrar registrar) { ImagePickerPlugin.registerWith(registrar); PackageInfoPlugin.registerWith(registrar); SharedPreferencesPlugin.registerWith(registrar); - SyncfusionFlutterPdfViewerPlugin.registerWith(registrar); UrlLauncherPlugin.registerWith(registrar); registrar.registerMessageHandler(); } diff --git a/lib/ui/profile/house/contract_preview_page.dart b/lib/ui/profile/house/contract_preview_page.dart index 62772cd6..af2b6b3b 100644 --- a/lib/ui/profile/house/contract_preview_page.dart +++ b/lib/ui/profile/house/contract_preview_page.dart @@ -1,6 +1,6 @@ -import 'dart:io'; import 'dart:typed_data'; +import 'package:advance_pdf_viewer/advance_pdf_viewer.dart'; import 'package:aku_community/base/base_style.dart'; import 'package:aku_community/constants/api.dart'; import 'package:aku_community/ui/profile/house/download_contract_page.dart'; @@ -14,7 +14,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:power_logger/power_logger.dart'; -import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; import 'package:velocity_x/velocity_x.dart'; class ContractPreviewPage extends StatefulWidget { @@ -29,16 +28,34 @@ class ContractPreviewPage extends StatefulWidget { class _ContractPreviewPageState extends State { Uint8List? _signName; - File? _signFile; + PDFDocument? doc; + int _currentPage = -1; + @override + void initState() { + Future.delayed(Duration(milliseconds: 300), () async { + Function cancel = BotToast.showLoading(); + doc = await PDFDocument.fromURL(API.image(widget.url)); + cancel(); + _currentPage = 0; + setState(() {}); + }); + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + @override Widget build(BuildContext context) { var signName = GestureDetector( child: DottedBorder( child: Container( alignment: Alignment.center, - width: 300.w, - height: 200.w, - color: Colors.white, + width: 200.w, + height: 100.w, + color: Colors.white.withOpacity(0.7), child: _signName != null ? Image.memory( _signName!, @@ -49,38 +66,49 @@ class _ContractPreviewPageState extends State { ), onTap: () async { _signName = await SignNameBoard.defalutBoard(); - if (_signName != null) { - _signFile = File.fromRawPath(_signName!); - } setState(() {}); }, ); return BeeScaffold( title: '合同预览', - body: ListView( + body: Stack( children: [ - SfPdfViewer.network(API.image(widget.url)), + Center( + child: doc == null + ? SizedBox() + : PDFViewer( + showPicker: false, + onPageChanged: (value) { + _currentPage = value; + setState(() {}); + }, + document: doc!), + ), + Positioned( + right: 70.w, + bottom: 200.w, + child: _currentPage != 0 ? SizedBox() : signName), ], ), bottomNavi: BottomButton( onPressed: () async { - if (_signFile != null) { - Function cancel = BotToast.showLoading(); + Function cancel = BotToast.showLoading(); + if (_signName != null) { try { - String result = await HouseFunc().uploadSignName(_signFile!); + String result = await HouseFunc().uploadSignName(_signName!); String path = await HouseFunc() .generateContract(widget.id, widget.url, result); - Get.off(() => DownLoadContractPage( - path: path, - id: widget.id, - )); + if (path.isNotEmpty) + Get.off( + () => DownLoadContractPage(path: path, id: widget.id)); } catch (e) { LoggerData.addData(e); + print(e); } - cancel(); } else { BotToast.showText(text: '请先签名!'); } + cancel(); }, child: '生成合同'.text.size(32.sp).color(ktextPrimary).make()), ); diff --git a/lib/ui/profile/house/house_func.dart b/lib/ui/profile/house/house_func.dart index 6a9ed507..2cf77c4a 100644 --- a/lib/ui/profile/house/house_func.dart +++ b/lib/ui/profile/house/house_func.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'dart:typed_data'; import 'package:aku_community/constants/api.dart'; import 'package:aku_community/model/user/house_model.dart'; @@ -116,23 +117,27 @@ class HouseFunc { } ///上传合同签名 - Future uploadSignName(File file) async { - BaseFileModel baseFileModel = - await NetUtil().upload(API.upload.uploadSignName, file); + Future uploadSignName(Uint8List bytes) async { + BaseFileModel baseFileModel = await NetUtil().uploadUnit8List( + API.upload.uploadSignName, + bytes, + ); if (baseFileModel.status ?? false) { + BotToast.showText(text: baseFileModel.message!); return baseFileModel.url!; } else { + BotToast.showText(text: baseFileModel.message!); return ''; } } ///生成正式合同(未盖章 - Future generateContract(int id, String pUrl, String url) async { + Future generateContract(int id, String pUrl, String sUrl) async { BaseModel baseModel = await NetUtil().post(API.house.generateContract, params: { "id": id, - "ContractPreviewImgUrl": pUrl, - "contractSignatureImgUrl": url, + "contractPreviewImgUrl": pUrl, + "contractSignatureImgUrl": sUrl, }); if (baseModel.status ?? false) { diff --git a/lib/utils/network/net_util.dart b/lib/utils/network/net_util.dart index 86832d5b..b34ef307 100644 --- a/lib/utils/network/net_util.dart +++ b/lib/utils/network/net_util.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'dart:typed_data'; import 'package:bot_toast/bot_toast.dart'; import 'package:dio/dio.dart'; @@ -123,6 +124,20 @@ class NetUtil { return BaseFileModel.err(); } + Future uploadUnit8List(String path, Uint8List bytes) async { + try { + Response res = await _dio!.post(path, + data: FormData.fromMap({ + 'file': await MultipartFile.fromBytes(bytes,filename: 'signName.png'), + })); + BaseFileModel baseListModel = BaseFileModel.fromJson(res.data); + return baseListModel; + } on DioError catch (e) { + print(e); + } + return BaseFileModel.err(); + } + Future> uploadFiles(List files, String api) async { List urls = []; if (files.isEmpty) { @@ -167,7 +182,7 @@ class NetUtil { final userProvider = Provider.of(Get.context!, listen: false); if (!model.status! && model.message == '登录失效,请登录' && userProvider.isLogin) { userProvider.logout(); - Get.offAll(()=>SignInPage()); + Get.offAll(() => SignInPage()); } if (!model.status! || showMessage) { BotToast.showText(text: model.message!); diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 0634634c..b71bc3b1 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -12,6 +12,7 @@ import package_info import package_info_plus_macos import path_provider_macos import shared_preferences_macos +import sqflite import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { @@ -22,5 +23,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) + SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index ffc67ea6..38116db3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -8,6 +8,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "21.0.0" + advance_pdf_viewer: + dependency: "direct main" + description: + name: advance_pdf_viewer + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.0" amap_flutter_base: dependency: "direct main" description: @@ -398,6 +405,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_cache_manager: + dependency: transitive + description: + name: flutter_cache_manager + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.1.2" flutter_easyrefresh: dependency: "direct main" description: @@ -590,6 +604,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "4.5.1" + infinite_listview: + dependency: transitive + description: + name: infinite_listview + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" intl: dependency: "direct main" description: @@ -676,6 +697,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0" + numberpicker: + dependency: transitive + description: + name: numberpicker + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.1" open_file: dependency: "direct main" description: @@ -916,6 +944,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0+1" + rxdart: + dependency: transitive + description: + name: rxdart + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.27.1" share: dependency: "direct main" description: @@ -1019,6 +1054,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.3" + sqflite: + dependency: transitive + description: + name: sqflite + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.0+3" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.0+2" stack_trace: dependency: transitive description: @@ -1054,41 +1103,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" - syncfusion_flutter_core: - dependency: transitive - description: - name: syncfusion_flutter_core - url: "https://pub.flutter-io.cn" - source: hosted - version: "19.1.69" - syncfusion_flutter_pdf: - dependency: transitive - description: - name: syncfusion_flutter_pdf - url: "https://pub.flutter-io.cn" - source: hosted - version: "19.1.69-beta" - syncfusion_flutter_pdfviewer: - dependency: "direct main" - description: - name: syncfusion_flutter_pdfviewer - url: "https://pub.flutter-io.cn" - source: hosted - version: "19.1.69-beta" - syncfusion_flutter_pdfviewer_platform_interface: - dependency: transitive - description: - name: syncfusion_flutter_pdfviewer_platform_interface - url: "https://pub.flutter-io.cn" - source: hosted - version: "19.1.69-beta" - syncfusion_flutter_pdfviewer_web: - dependency: transitive - description: - name: syncfusion_flutter_pdfviewer_web - url: "https://pub.flutter-io.cn" - source: hosted - version: "19.1.69-beta" synchronized: dependency: transitive description: @@ -1187,6 +1201,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" + uuid: + dependency: transitive + description: + name: uuid + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.4" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 55f87de6..25daf620 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -105,8 +105,8 @@ dependencies: #model 插件 equatable: ^2.0.0 #pdf文件预览 - syncfusion_flutter_pdfviewer: ^19.1.69-beta - + # flutter_cached_pdfview: ^0.4.0-nullsafety + advance_pdf_viewer: ^2.0.0 dev_dependencies: flutter_test: