对接 签名上传

修改pdf view 为 advance pdf viewer
hmxc
张萌 3 years ago
parent 6306a8e1c2
commit c161ab4730

@ -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:image_picker_for_web/image_picker_for_web.dart';
import 'package:package_info_plus_web/package_info_plus_web.dart'; import 'package:package_info_plus_web/package_info_plus_web.dart';
import 'package:shared_preferences_web/shared_preferences_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:url_launcher_web/url_launcher_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart';
@ -21,7 +20,6 @@ void registerPlugins(Registrar registrar) {
ImagePickerPlugin.registerWith(registrar); ImagePickerPlugin.registerWith(registrar);
PackageInfoPlugin.registerWith(registrar); PackageInfoPlugin.registerWith(registrar);
SharedPreferencesPlugin.registerWith(registrar); SharedPreferencesPlugin.registerWith(registrar);
SyncfusionFlutterPdfViewerPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar); UrlLauncherPlugin.registerWith(registrar);
registrar.registerMessageHandler(); registrar.registerMessageHandler();
} }

@ -1,6 +1,6 @@
import 'dart:io';
import 'dart:typed_data'; 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/base/base_style.dart';
import 'package:aku_community/constants/api.dart'; import 'package:aku_community/constants/api.dart';
import 'package:aku_community/ui/profile/house/download_contract_page.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:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
class ContractPreviewPage extends StatefulWidget { class ContractPreviewPage extends StatefulWidget {
@ -29,16 +28,34 @@ class ContractPreviewPage extends StatefulWidget {
class _ContractPreviewPageState extends State<ContractPreviewPage> { class _ContractPreviewPageState extends State<ContractPreviewPage> {
Uint8List? _signName; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var signName = GestureDetector( var signName = GestureDetector(
child: DottedBorder( child: DottedBorder(
child: Container( child: Container(
alignment: Alignment.center, alignment: Alignment.center,
width: 300.w, width: 200.w,
height: 200.w, height: 100.w,
color: Colors.white, color: Colors.white.withOpacity(0.7),
child: _signName != null child: _signName != null
? Image.memory( ? Image.memory(
_signName!, _signName!,
@ -49,38 +66,49 @@ class _ContractPreviewPageState extends State<ContractPreviewPage> {
), ),
onTap: () async { onTap: () async {
_signName = await SignNameBoard.defalutBoard(); _signName = await SignNameBoard.defalutBoard();
if (_signName != null) {
_signFile = File.fromRawPath(_signName!);
}
setState(() {}); setState(() {});
}, },
); );
return BeeScaffold( return BeeScaffold(
title: '合同预览', title: '合同预览',
body: ListView( body: Stack(
children: [ 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( bottomNavi: BottomButton(
onPressed: () async { onPressed: () async {
if (_signFile != null) { Function cancel = BotToast.showLoading();
Function cancel = BotToast.showLoading(); if (_signName != null) {
try { try {
String result = await HouseFunc().uploadSignName(_signFile!); String result = await HouseFunc().uploadSignName(_signName!);
String path = await HouseFunc() String path = await HouseFunc()
.generateContract(widget.id, widget.url, result); .generateContract(widget.id, widget.url, result);
Get.off(() => DownLoadContractPage( if (path.isNotEmpty)
path: path, Get.off(
id: widget.id, () => DownLoadContractPage(path: path, id: widget.id));
));
} catch (e) { } catch (e) {
LoggerData.addData(e); LoggerData.addData(e);
print(e);
} }
cancel();
} else { } else {
BotToast.showText(text: '请先签名!'); BotToast.showText(text: '请先签名!');
} }
cancel();
}, },
child: '生成合同'.text.size(32.sp).color(ktextPrimary).make()), child: '生成合同'.text.size(32.sp).color(ktextPrimary).make()),
); );

@ -1,4 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'dart:typed_data';
import 'package:aku_community/constants/api.dart'; import 'package:aku_community/constants/api.dart';
import 'package:aku_community/model/user/house_model.dart'; import 'package:aku_community/model/user/house_model.dart';
@ -116,23 +117,27 @@ class HouseFunc {
} }
/// ///
Future<String> uploadSignName(File file) async { Future<String> uploadSignName(Uint8List bytes) async {
BaseFileModel baseFileModel = BaseFileModel baseFileModel = await NetUtil().uploadUnit8List(
await NetUtil().upload(API.upload.uploadSignName, file); API.upload.uploadSignName,
bytes,
);
if (baseFileModel.status ?? false) { if (baseFileModel.status ?? false) {
BotToast.showText(text: baseFileModel.message!);
return baseFileModel.url!; return baseFileModel.url!;
} else { } else {
BotToast.showText(text: baseFileModel.message!);
return ''; return '';
} }
} }
/// ///
Future<String> generateContract(int id, String pUrl, String url) async { Future<String> generateContract(int id, String pUrl, String sUrl) async {
BaseModel baseModel = BaseModel baseModel =
await NetUtil().post(API.house.generateContract, params: { await NetUtil().post(API.house.generateContract, params: {
"id": id, "id": id,
"ContractPreviewImgUrl": pUrl, "contractPreviewImgUrl": pUrl,
"contractSignatureImgUrl": url, "contractSignatureImgUrl": sUrl,
}); });
if (baseModel.status ?? false) { if (baseModel.status ?? false) {

@ -1,4 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'dart:typed_data';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
@ -123,6 +124,20 @@ class NetUtil {
return BaseFileModel.err(); return BaseFileModel.err();
} }
Future<BaseFileModel> 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<List<String?>> uploadFiles(List<File> files, String api) async { Future<List<String?>> uploadFiles(List<File> files, String api) async {
List<String?> urls = []; List<String?> urls = [];
if (files.isEmpty) { if (files.isEmpty) {
@ -167,7 +182,7 @@ class NetUtil {
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false); final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
if (!model.status! && model.message == '登录失效,请登录' && userProvider.isLogin) { if (!model.status! && model.message == '登录失效,请登录' && userProvider.isLogin) {
userProvider.logout(); userProvider.logout();
Get.offAll(()=>SignInPage()); Get.offAll(() => SignInPage());
} }
if (!model.status! || showMessage) { if (!model.status! || showMessage) {
BotToast.showText(text: model.message!); BotToast.showText(text: model.message!);

@ -12,6 +12,7 @@ import package_info
import package_info_plus_macos import package_info_plus_macos
import path_provider_macos import path_provider_macos
import shared_preferences_macos import shared_preferences_macos
import sqflite
import url_launcher_macos import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
@ -22,5 +23,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
} }

@ -8,6 +8,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "21.0.0" 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: amap_flutter_base:
dependency: "direct main" dependency: "direct main"
description: description:
@ -398,6 +405,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" 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: flutter_easyrefresh:
dependency: "direct main" dependency: "direct main"
description: description:
@ -590,6 +604,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "4.5.1" 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: intl:
dependency: "direct main" dependency: "direct main"
description: description:
@ -676,6 +697,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.0" version: "1.0.0"
numberpicker:
dependency: transitive
description:
name: numberpicker
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.1"
open_file: open_file:
dependency: "direct main" dependency: "direct main"
description: description:
@ -916,6 +944,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.0+1" version: "1.1.0+1"
rxdart:
dependency: transitive
description:
name: rxdart
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.27.1"
share: share:
dependency: "direct main" dependency: "direct main"
description: description:
@ -1019,6 +1054,20 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.3" 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: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -1054,41 +1103,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.0" 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: synchronized:
dependency: transitive dependency: transitive
description: description:
@ -1187,6 +1201,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.0" version: "2.0.0"
uuid:
dependency: transitive
description:
name: uuid
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.4"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:

@ -105,8 +105,8 @@ dependencies:
#model 插件 #model 插件
equatable: ^2.0.0 equatable: ^2.0.0
#pdf文件预览 #pdf文件预览
syncfusion_flutter_pdfviewer: ^19.1.69-beta # flutter_cached_pdfview: ^0.4.0-nullsafety
advance_pdf_viewer: ^2.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save