Browse Source

pdf展示更换依赖pdfx;

接口文档新增Uint8List文件转换;
优惠券页面ui网络异常显示更改;
wr_2024_invoice
wurong 5 months ago
parent
commit
12c1a1cfa4
  1. 3
      lib/main.dart
  2. 57
      lib/mine/coupon_page.dart
  3. 28
      lib/order/invoices_manage/invoices_detail_page.dart
  4. 2
      lib/order/invoices_manage/invoices_history.dart
  5. 8
      lib/order/invoices_manage/pdf_screen.dart
  6. 125
      lib/order/invoices_manage/pinch_page.dart
  7. 2
      lib/retrofit/retrofit_api.dart
  8. 16
      lib/retrofit/retrofit_api.g.dart
  9. 88
      pubspec.lock
  10. 2
      pubspec.yaml

3
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_history.dart';
import 'order/invoices_manage/invoices_manage_page.dart'; import 'order/invoices_manage/invoices_manage_page.dart';
import 'order/invoices_manage/invoices_title_info.dart'; import 'order/invoices_manage/invoices_title_info.dart';
import 'order/invoices_manage/pinch_page.dart';
void main() async { void main() async {
@ -426,6 +427,8 @@ Map<String, WidgetBuilder> routers = <String, WidgetBuilder>{
GroupPageDetails(arguments:arguments), GroupPageDetails(arguments:arguments),
'/router/photo_view_gallery_screen': (context, {arguments}) => '/router/photo_view_gallery_screen': (context, {arguments}) =>
PhotoViewGalleryScreen(), PhotoViewGalleryScreen(),
'/router/pinch_page': (context, {arguments}) =>
PinchPage(),
'/router/system_details': (context, {arguments}) => '/router/system_details': (context, {arguments}) =>
SystemDetails(arguments: arguments), SystemDetails(arguments: arguments),
'/router/invitation_record': (context, {arguments}) => '/router/invitation_record': (context, {arguments}) =>

57
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:flutter_screenutil/flutter_screenutil.dart';
import 'package:shimmer/shimmer.dart'; import 'package:shimmer/shimmer.dart';
import '../utils/flutter_utils.dart';
class CouponPage extends StatefulWidget { class CouponPage extends StatefulWidget {
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -33,6 +35,7 @@ class _CouponPage extends State<CouponPage> {
ApiService apiService; ApiService apiService;
RefreshController _refreshController; RefreshController _refreshController;
int networkStatus = 0; int networkStatus = 0;
String networkError = "";
@override @override
void dispose() { void dispose() {
@ -69,7 +72,9 @@ class _CouponPage extends State<CouponPage> {
"searchKey": "", "searchKey": "",
"state": state "state": state
}).catchError((error) { }).catchError((error) {
networkError = AppUtils.dioErrorTypeToString(error.type);
networkStatus = -1; networkStatus = -1;
setState(() {});
_refreshController.loadFailed(); _refreshController.loadFailed();
_refreshController.refreshFailed(); _refreshController.refreshFailed();
}); });
@ -231,7 +236,7 @@ class _CouponPage extends State<CouponPage> {
), ),
onRefresh: _onRefresh, onRefresh: _onRefresh,
onLoading: queryCard, onLoading: queryCard,
child: networkStatus == 0 ? ListView.builder( child: networkStatus == -1?noNetwork():(networkStatus == 0 ? ListView.builder(
itemCount: 10, itemCount: 10,
physics: BouncingScrollPhysics(), physics: BouncingScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
@ -291,7 +296,7 @@ class _CouponPage extends State<CouponPage> {
text: state == 1 ? "目前暂无优惠券,请到领劵中心领取哦~" :(state == 2 ? "目前暂无已使用的优惠券哦~" :"目前暂无失效的优惠券哦~"), text: state == 1 ? "目前暂无优惠券,请到领劵中心领取哦~" :(state == 2 ? "目前暂无已使用的优惠券哦~" :"目前暂无失效的优惠券哦~"),
fontSize: 16.sp, fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h, left: 60, right: 60), margin: EdgeInsets.only(top: 120.h, left: 60, right: 60),
)), ))),
), ),
), ),
], ],
@ -436,4 +441,52 @@ class _CouponPage extends State<CouponPage> {
); );
} }
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),
)),
)
],
),
);
}
} }

28
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_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.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/pdf_screen.dart';
import 'package:huixiang/order/invoices_manage/pinch_page.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:pdfx/pdfx.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:shimmer/shimmer.dart'; import 'package:shimmer/shimmer.dart';
@ -43,6 +45,7 @@ class _InvoicesDetailPage extends State<InvoicesDetailPage> {
String networkError = ""; String networkError = "";
int networkStatus = 0; int networkStatus = 0;
final RefreshController refreshController = RefreshController(); final RefreshController refreshController = RefreshController();
PdfController pdfDoc;
@override @override
void initState() { void initState() {
@ -53,7 +56,7 @@ class _InvoicesDetailPage extends State<InvoicesDetailPage> {
context: context, context: context,
token: value.getString('token'), token: value.getString('token'),
), ),
queryInvoices(widget?.arguments["id"] ?? ""), queryInvoices("1797587255380934656"),
}); });
} }
@ -84,6 +87,10 @@ class _InvoicesDetailPage extends State<InvoicesDetailPage> {
}); });
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
invoicesDetailInfo = baseData.data; invoicesDetailInfo = baseData.data;
final pdfFile = await createFileOfPdfUrl();
pdfDoc = PdfController(
document: PdfDocument.openFile(pdfFile.path),
);
createFileOfPdfUrl().then((f) { createFileOfPdfUrl().then((f) {
setState(() { setState(() {
remotePDFpath = f.path; remotePDFpath = f.path;
@ -104,7 +111,7 @@ class _InvoicesDetailPage extends State<InvoicesDetailPage> {
Completer<File> completer = Completer(); Completer<File> completer = Completer();
print("Start download file from internet!"); print("Start download file from internet!");
try { try {
final url = invoicesDetailInfo?.ossUrl ?? ""; final url = "https://file.oa.yixinhuixiang.com/2024/08/06/e716b61ed0c4444db4e8e33bf2712432.pdf";
final filename = url.substring(url.lastIndexOf("/") + 1); final filename = url.substring(url.lastIndexOf("/") + 1);
var request = await HttpClient().getUrl(Uri.parse(url)); var request = await HttpClient().getUrl(Uri.parse(url));
var response = await request.close(); var response = await request.close();
@ -298,12 +305,21 @@ class _InvoicesDetailPage extends State<InvoicesDetailPage> {
onTap: () { onTap: () {
if ((invoicesDetailInfo?.ossUrl ?? "") if ((invoicesDetailInfo?.ossUrl ?? "")
.endsWith("pdf")) { .endsWith("pdf")) {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => PDFScreen(
// path: remotePDFpath,
// inlet: 0,
// ),
// ),
// );
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => PDFScreen( builder: (context) => PinchPage(
path: remotePDFpath, path: "https://file.oa.yixinhuixiang.com/2024/08/06/e716b61ed0c4444db4e8e33bf2712432.pdf",
inlet: 0, inlet:0
), ),
), ),
); );
@ -473,7 +489,7 @@ class _InvoicesDetailPage extends State<InvoicesDetailPage> {
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return PDFScreen(path: remotePDFpath, inlet: 1); return PDFScreen(path:remotePDFpath, inlet: 1);
}, },
); );
} }

2
lib/order/invoices_manage/invoices_history.dart

@ -201,7 +201,7 @@ class _InvoicesHistory extends State<InvoicesHistory> {
return GestureDetector( return GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
if(records[position].state == "AUDIT_PASS") // if(records[position].state == "AUDIT_PASS")
Navigator.of(context) Navigator.of(context)
.pushNamed('/router/invoices_detail_page',arguments: { .pushNamed('/router/invoices_detail_page',arguments: {
"id":records[position].id ?? "" "id":records[position].id ?? ""

8
lib/order/invoices_manage/pdf_screen.dart

@ -69,11 +69,15 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
print('goto uri: $uri'); print('goto uri: $uri');
}, },
onPageChanged: (int page, int total) { onPageChanged: (int page, int total) {
if(total >0){
print('page change: $page/$total'); print('page change: $page/$total');
setState(() { setState(() {
currentPage = page; currentPage = page +1;
pageTotal = total; pageTotal = total;
}); });
}else{
pageTotal = 1;
}
}, },
), ),
), ),
@ -92,7 +96,7 @@ class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
bottom:45, bottom:45,
child: Center( 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)),
), ),
), ),
], ],

125
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<PinchPage> createState() => _PinchPageState();
}
enum DocShown { sample, tutorial, hello, password }
class _PinchPageState extends State<PinchPage> {
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<DefaultBuilderOptions>(
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<DefaultBuilderOptions>(
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),
),
),
),
),
),
],
);
}
}

2
lib/retrofit/retrofit_api.dart

@ -615,6 +615,8 @@ abstract class ApiService {
@GET("/ipJson.jsp") @GET("/ipJson.jsp")
Future<IpData> getIpInfo(); Future<IpData> getIpInfo();
Future<Uint8List> getUrlFile(String url);
/// ///
@POST("order/invoiceOrderList") @POST("order/invoiceOrderList")
Future<BaseData<InvoiceList>> invoiceOrderList(@Body() Map<String, dynamic> param); Future<BaseData<InvoiceList>> invoiceOrderList(@Body() Map<String, dynamic> param);

16
lib/retrofit/retrofit_api.g.dart

@ -2190,6 +2190,22 @@ class _ApiService implements ApiService {
return value; return value;
} }
@override
Future<Uint8List> getUrlFile(String url) async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
final _result = await _dio.request<List<int>>(url,
queryParameters: queryParameters,
options: RequestOptions(
method: 'GET',
extra: _extra,
baseUrl: baseUrl,
responseType: ResponseType.bytes),
data: _data);
return _result.data;
}
@override @override
Future<BaseData<dynamic>> orderVip(param) async { Future<BaseData<dynamic>> orderVip(param) async {
ArgumentError.checkNotNull(param, 'param'); ArgumentError.checkNotNull(param, 'param');

88
pubspec.lock

@ -169,6 +169,54 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.5" 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: dio:
dependency: "direct main" dependency: "direct main"
description: description:
@ -209,6 +257,14 @@ 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"
extension:
dependency: transitive
description:
name: extension
sha256: "755224c11fcbfb81d622e38befd05581b52566529a08f2407e424219200ac7cf"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.0"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -701,6 +757,14 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.7" 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: permission_handler:
dependency: "direct main" dependency: "direct main"
description: description:
@ -1026,6 +1090,14 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "19.4.56" 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: table_calendar:
dependency: "direct main" dependency: "direct main"
description: description:
@ -1099,6 +1171,14 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.2.7" 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: url_launcher:
dependency: "direct main" dependency: "direct main"
description: description:
@ -1131,6 +1211,14 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.1.3" 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: vector_math:
dependency: transitive dependency: transitive
description: description:

2
pubspec.yaml

@ -20,6 +20,8 @@ dependencies:
#pdf展示 #pdf展示
flutter_pdfview: ^1.3.2 flutter_pdfview: ^1.3.2
pdfx: ^2.0.1+2
gradient_widgets: ^0.6.0 gradient_widgets: ^0.6.0
keframe: ^3.0.0 keframe: ^3.0.0

Loading…
Cancel
Save