From 12c1a1cfa4df51a98422608a5dc8321d75ad04a1 Mon Sep 17 00:00:00 2001 From: wurong <953969641@qq.com> Date: Tue, 13 Aug 2024 11:12:41 +0800 Subject: [PATCH] =?UTF-8?q?pdf=E5=B1=95=E7=A4=BA=E6=9B=B4=E6=8D=A2?= =?UTF-8?q?=E4=BE=9D=E8=B5=96pdfx;=20=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=96=B0=E5=A2=9EUint8List=E6=96=87=E4=BB=B6=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?;=20=E4=BC=98=E6=83=A0=E5=88=B8=E9=A1=B5=E9=9D=A2ui=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E5=BC=82=E5=B8=B8=E6=98=BE=E7=A4=BA=E6=9B=B4=E6=94=B9?= =?UTF-8?q?;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 3 + lib/mine/coupon_page.dart | 57 +++++++- .../invoices_manage/invoices_detail_page.dart | 28 +++- .../invoices_manage/invoices_history.dart | 2 +- lib/order/invoices_manage/pdf_screen.dart | 16 ++- lib/order/invoices_manage/pinch_page.dart | 125 ++++++++++++++++++ lib/retrofit/retrofit_api.dart | 2 + lib/retrofit/retrofit_api.g.dart | 16 +++ pubspec.lock | 88 ++++++++++++ pubspec.yaml | 2 + 10 files changed, 324 insertions(+), 15 deletions(-) create mode 100644 lib/order/invoices_manage/pinch_page.dart diff --git a/lib/main.dart b/lib/main.dart index 882d4d1e..253ad21e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -175,6 +175,7 @@ import 'order/invoices_manage/invoices_detail_page.dart'; import 'order/invoices_manage/invoices_history.dart'; import 'order/invoices_manage/invoices_manage_page.dart'; import 'order/invoices_manage/invoices_title_info.dart'; +import 'order/invoices_manage/pinch_page.dart'; void main() async { @@ -426,6 +427,8 @@ Map routers = { GroupPageDetails(arguments:arguments), '/router/photo_view_gallery_screen': (context, {arguments}) => PhotoViewGalleryScreen(), + '/router/pinch_page': (context, {arguments}) => + PinchPage(), '/router/system_details': (context, {arguments}) => SystemDetails(arguments: arguments), '/router/invitation_record': (context, {arguments}) => diff --git a/lib/mine/coupon_page.dart b/lib/mine/coupon_page.dart index c7edf812..c4e2a51b 100644 --- a/lib/mine/coupon_page.dart +++ b/lib/mine/coupon_page.dart @@ -22,6 +22,8 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shimmer/shimmer.dart'; +import '../utils/flutter_utils.dart'; + class CouponPage extends StatefulWidget { @override State createState() { @@ -33,6 +35,7 @@ class _CouponPage extends State { ApiService apiService; RefreshController _refreshController; int networkStatus = 0; + String networkError = ""; @override void dispose() { @@ -69,7 +72,9 @@ class _CouponPage extends State { "searchKey": "", "state": state }).catchError((error) { + networkError = AppUtils.dioErrorTypeToString(error.type); networkStatus = -1; + setState(() {}); _refreshController.loadFailed(); _refreshController.refreshFailed(); }); @@ -231,7 +236,7 @@ class _CouponPage extends State { ), onRefresh: _onRefresh, onLoading: queryCard, - child: networkStatus == 0 ? ListView.builder( + child: networkStatus == -1?noNetwork():(networkStatus == 0 ? ListView.builder( itemCount: 10, physics: BouncingScrollPhysics(), shrinkWrap: true, @@ -291,7 +296,7 @@ class _CouponPage extends State { text: state == 1 ? "目前暂无优惠券,请到领劵中心领取哦~" :(state == 2 ? "目前暂无已使用的优惠券哦~" :"目前暂无失效的优惠券哦~"), fontSize: 16.sp, margin: EdgeInsets.only(top: 120.h, left: 60, right: 60), - )), + ))), ), ), ], @@ -436,4 +441,52 @@ class _CouponPage extends State { ); } + Widget noNetwork() { + return Container( + width: double.infinity, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + // "无法连接到网络", + networkError.substring(0, networkError.indexOf(",")), + style: TextStyle( + fontSize: 14.sp, + color: Color(0xFF0D0D0D), + fontWeight: MyFontWeight.bold), + ), + Padding( + padding: EdgeInsets.symmetric(vertical: 10.h), + child: Text( + "请检查网络设置或稍后重试", + style: TextStyle( + fontSize: 12.sp, + color: Color(0xFF7A797F), + fontWeight: MyFontWeight.regular), + ), + ), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + _onRefresh(); + }, + child: Container( + decoration: BoxDecoration( + color: Color(0xff32A060), + borderRadius: BorderRadius.circular(15), + ), + padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 3.h), + child: Text( + "重试", + style: TextStyle( + fontSize: 14.sp, + color: Colors.white, + fontWeight: MyFontWeight.regular), + )), + ) + ], + ), + ); + } + } diff --git a/lib/order/invoices_manage/invoices_detail_page.dart b/lib/order/invoices_manage/invoices_detail_page.dart index 60c72891..d291c48b 100644 --- a/lib/order/invoices_manage/invoices_detail_page.dart +++ b/lib/order/invoices_manage/invoices_detail_page.dart @@ -9,7 +9,9 @@ import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/order/invoices_manage/pdf_screen.dart'; +import 'package:huixiang/order/invoices_manage/pinch_page.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:pdfx/pdfx.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:shimmer/shimmer.dart'; @@ -43,6 +45,7 @@ class _InvoicesDetailPage extends State { String networkError = ""; int networkStatus = 0; final RefreshController refreshController = RefreshController(); + PdfController pdfDoc; @override void initState() { @@ -53,7 +56,7 @@ class _InvoicesDetailPage extends State { context: context, token: value.getString('token'), ), - queryInvoices(widget?.arguments["id"] ?? ""), + queryInvoices("1797587255380934656"), }); } @@ -84,6 +87,10 @@ class _InvoicesDetailPage extends State { }); if (baseData != null && baseData.isSuccess) { invoicesDetailInfo = baseData.data; + final pdfFile = await createFileOfPdfUrl(); + pdfDoc = PdfController( + document: PdfDocument.openFile(pdfFile.path), + ); createFileOfPdfUrl().then((f) { setState(() { remotePDFpath = f.path; @@ -104,7 +111,7 @@ class _InvoicesDetailPage extends State { Completer completer = Completer(); print("Start download file from internet!"); try { - final url = invoicesDetailInfo?.ossUrl ?? ""; + final url = "https://file.oa.yixinhuixiang.com/2024/08/06/e716b61ed0c4444db4e8e33bf2712432.pdf"; final filename = url.substring(url.lastIndexOf("/") + 1); var request = await HttpClient().getUrl(Uri.parse(url)); var response = await request.close(); @@ -298,12 +305,21 @@ class _InvoicesDetailPage extends State { onTap: () { if ((invoicesDetailInfo?.ossUrl ?? "") .endsWith("pdf")) { + // Navigator.push( + // context, + // MaterialPageRoute( + // builder: (context) => PDFScreen( + // path: remotePDFpath, + // inlet: 0, + // ), + // ), + // ); Navigator.push( context, MaterialPageRoute( - builder: (context) => PDFScreen( - path: remotePDFpath, - inlet: 0, + builder: (context) => PinchPage( + path: "https://file.oa.yixinhuixiang.com/2024/08/06/e716b61ed0c4444db4e8e33bf2712432.pdf", + inlet:0 ), ), ); @@ -473,7 +489,7 @@ class _InvoicesDetailPage extends State { showDialog( context: context, builder: (BuildContext context) { - return PDFScreen(path: remotePDFpath, inlet: 1); + return PDFScreen(path:remotePDFpath, inlet: 1); }, ); } diff --git a/lib/order/invoices_manage/invoices_history.dart b/lib/order/invoices_manage/invoices_history.dart index 79a4c3b5..6a94cd4c 100644 --- a/lib/order/invoices_manage/invoices_history.dart +++ b/lib/order/invoices_manage/invoices_history.dart @@ -201,7 +201,7 @@ class _InvoicesHistory extends State { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - if(records[position].state == "AUDIT_PASS") + // if(records[position].state == "AUDIT_PASS") Navigator.of(context) .pushNamed('/router/invoices_detail_page',arguments: { "id":records[position].id ?? "" diff --git a/lib/order/invoices_manage/pdf_screen.dart b/lib/order/invoices_manage/pdf_screen.dart index ed87f604..7e1079fa 100644 --- a/lib/order/invoices_manage/pdf_screen.dart +++ b/lib/order/invoices_manage/pdf_screen.dart @@ -69,11 +69,15 @@ class _PDFScreenState extends State with WidgetsBindingObserver { print('goto uri: $uri'); }, onPageChanged: (int page, int total) { - print('page change: $page/$total'); - setState(() { - currentPage = page; - pageTotal = total; - }); + if(total >0){ + print('page change: $page/$total'); + setState(() { + currentPage = page +1; + pageTotal = total; + }); + }else{ + pageTotal = 1; + } }, ), ), @@ -92,7 +96,7 @@ class _PDFScreenState extends State with WidgetsBindingObserver { width: MediaQuery.of(context).size.width, bottom:45, child: Center( - child: Text("${currentPage+1}/${pageTotal}",style: TextStyle(color: Colors.white,fontSize: 16)), + child: Text("${currentPage}/${pageTotal}",style: TextStyle(color: Colors.white,fontSize: 16)), ), ), ], diff --git a/lib/order/invoices_manage/pinch_page.dart b/lib/order/invoices_manage/pinch_page.dart new file mode 100644 index 00000000..99c8e7ba --- /dev/null +++ b/lib/order/invoices_manage/pinch_page.dart @@ -0,0 +1,125 @@ +import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:pdfx/pdfx.dart'; + +import '../../retrofit/retrofit_api.dart'; + +class PinchPage extends StatefulWidget { + final String path; + final int inlet; + const PinchPage({Key key,this.path,this.inlet}) : super(key: key); + + @override + State createState() => _PinchPageState(); +} + +enum DocShown { sample, tutorial, hello, password } + +class _PinchPageState extends State { + static const int _initialPage = 1; + PdfControllerPinch _pdfControllerPinch; + ApiService apiService; + + @override + void initState() { + apiService = ApiService( + Dio(), + context: context, + ); + _pdfControllerPinch = PdfControllerPinch( + document: PdfDocument.openData( + apiService.getUrlFile(widget.path ?? "") + ), + initialPage: _initialPage, + ); + super.initState(); + } + + @override + void dispose() { + _pdfControllerPinch.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return widget.inlet == 0 ? Scaffold( + backgroundColor: Colors.white, + body: Column( + children: [ + Container( + alignment: Alignment.topRight, + padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top,right:10), + child: IconButton( + icon: Icon(Icons.close,size: 30,color: Colors.black,), + onPressed: (){ + Navigator.of(context).pop(); + }, + ), + ), + Expanded(child: PdfViewPinch( + builders: PdfViewPinchBuilders( + options: const DefaultBuilderOptions(), + documentLoaderBuilder: (_) => + const Center(child: CircularProgressIndicator()), + pageLoaderBuilder: (_) => + const Center(child: CircularProgressIndicator()), + errorBuilder: (_, error) => Center(child: Text(error.toString())), + ), + controller: _pdfControllerPinch, + )), + Container( + padding:EdgeInsets.only(bottom:45,top:20), + width: MediaQuery.of(context).size.width, + child: Center( + child: PdfPageNumber( + controller: _pdfControllerPinch, + builder: (_, loadingState, page, pagesCount) => Container( + alignment: Alignment.center, + child: Text( + '$page/${pagesCount ?? 0}', + style: const TextStyle(fontSize:16), + ), + ), + ), + ), + ), + ], + ), + ):Column( + children: [ + Expanded(child: Padding( + padding: EdgeInsets.symmetric(vertical:200), + child: PdfViewPinch( + builders: PdfViewPinchBuilders( + options: const DefaultBuilderOptions(), + documentLoaderBuilder: (_) => + const Center(child: CircularProgressIndicator()), + pageLoaderBuilder: (_) => + const Center(child: CircularProgressIndicator()), + errorBuilder: (_, error) => Center(child: Text(error.toString())), + ), + controller: _pdfControllerPinch, + ), + )), + Container( + padding:EdgeInsets.only(bottom:45,top:20), + width: MediaQuery.of(context).size.width, + child: Center( + child: PdfPageNumber( + controller: _pdfControllerPinch, + builder: (_, loadingState, page, pagesCount) => Container( + alignment: Alignment.center, + child: Text( + '$page/${pagesCount ?? 0}', + style: const TextStyle(fontSize:16,color: Colors.white), + ), + ), + ), + ), + ), + ], + ); + } +} \ No newline at end of file diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index 89992773..d00fa53c 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -615,6 +615,8 @@ abstract class ApiService { @GET("/ipJson.jsp") Future getIpInfo(); + Future getUrlFile(String url); + ///查询订单状态完成的并且可以开发票的订单列表 @POST("order/invoiceOrderList") Future> invoiceOrderList(@Body() Map param); diff --git a/lib/retrofit/retrofit_api.g.dart b/lib/retrofit/retrofit_api.g.dart index 1687b97c..a2d78c6a 100644 --- a/lib/retrofit/retrofit_api.g.dart +++ b/lib/retrofit/retrofit_api.g.dart @@ -2190,6 +2190,22 @@ class _ApiService implements ApiService { return value; } + @override + Future getUrlFile(String url) async { + const _extra = {}; + final queryParameters = {}; + final _data = {}; + final _result = await _dio.request>(url, + queryParameters: queryParameters, + options: RequestOptions( + method: 'GET', + extra: _extra, + baseUrl: baseUrl, + responseType: ResponseType.bytes), + data: _data); + return _result.data; + } + @override Future> orderVip(param) async { ArgumentError.checkNotNull(param, 'param'); diff --git a/pubspec.lock b/pubspec.lock index 29986636..ba22c5dc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -169,6 +169,54 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.5" + device_info_plus: + dependency: transitive + description: + name: device_info_plus + sha256: c2386729379f04cd39ee0d5d4c48d8c8a0e70f7622dac626cbf5e396392602fd + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.2.4" + device_info_plus_linux: + dependency: transitive + description: + name: device_info_plus_linux + sha256: e4eb5db4704f5534e872148a21cfcd39581022b63df556da6720d88f7c9f91a9 + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.1" + device_info_plus_macos: + dependency: transitive + description: + name: device_info_plus_macos + sha256: "38871fd2ad31871399d8307630c9f4eb5941dd2c643ee221c44d58de95d367a1" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.3" + device_info_plus_platform_interface: + dependency: transitive + description: + name: device_info_plus_platform_interface + sha256: b2743934f0efc3e291880d76fb341ea114b7e8417d77ee0f93bd21f5dfd3e8d2 + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.6.1" + device_info_plus_web: + dependency: transitive + description: + name: device_info_plus_web + sha256: "38715ad1ef3bee8915dd7bee08a9ac9ab54472a8df425c887062a3046209f663" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.0" + device_info_plus_windows: + dependency: transitive + description: + name: device_info_plus_windows + sha256: "8fb1403fc94636d6ab48aeebb5f9379f2ca51cde3b337167ec6f39db09234492" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.1" dio: dependency: "direct main" description: @@ -209,6 +257,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" + extension: + dependency: transitive + description: + name: extension + sha256: "755224c11fcbfb81d622e38befd05581b52566529a08f2407e424219200ac7cf" + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.2.0" fake_async: dependency: transitive description: @@ -701,6 +757,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.7" + pdfx: + dependency: "direct main" + description: + name: pdfx + sha256: bdd269f7316630698b514778dd071c602cf1862c6e8c6661a74308970db1dc67 + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.1+2" permission_handler: dependency: "direct main" description: @@ -1026,6 +1090,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "19.4.56" + synchronized: + dependency: transitive + description: + name: synchronized + sha256: "5fcbd27688af6082f5abd611af56ee575342c30e87541d0245f7ff99faa02c60" + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.1.0" table_calendar: dependency: "direct main" description: @@ -1099,6 +1171,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.2.7" + universal_platform: + dependency: transitive + description: + name: universal_platform + sha256: "64e16458a0ea9b99260ceb5467a214c1f298d647c659af1bff6d3bf82536b1ec" + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" url_launcher: dependency: "direct main" description: @@ -1131,6 +1211,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.1.3" + uuid: + dependency: transitive + description: + name: uuid + sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313" + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.7" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4cffcde9..9085c17b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,6 +20,8 @@ dependencies: #pdf展示 flutter_pdfview: ^1.3.2 + pdfx: ^2.0.1+2 + gradient_widgets: ^0.6.0 keframe: ^3.0.0