对接 签名上传

修改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: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();
}

@ -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<ContractPreviewPage> {
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<ContractPreviewPage> {
),
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()),
);

@ -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<String> uploadSignName(File file) async {
BaseFileModel baseFileModel =
await NetUtil().upload(API.upload.uploadSignName, file);
Future<String> 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<String> generateContract(int id, String pUrl, String url) async {
Future<String> 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) {

@ -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<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 {
List<String?> urls = [];
if (files.isEmpty) {
@ -167,7 +182,7 @@ class NetUtil {
final userProvider = Provider.of<UserProvider>(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!);

@ -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"))
}

@ -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:

@ -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:

Loading…
Cancel
Save