diff --git a/lib/order/invoices_manage/invoices_detail_page.dart b/lib/order/invoices_manage/invoices_detail_page.dart index 68247a8b..54bbae9a 100644 --- a/lib/order/invoices_manage/invoices_detail_page.dart +++ b/lib/order/invoices_manage/invoices_detail_page.dart @@ -53,7 +53,7 @@ class _InvoicesDetailPage extends State { context: context, token: value.getString('token'), ), - queryInvoices("1797587255380934656"), + queryInvoices(widget?.arguments["id"] ??""), }); } @@ -104,7 +104,7 @@ class _InvoicesDetailPage extends State { Completer completer = Completer(); print("Start download file from internet!"); try { - final url = "https://file.oa.yixinhuixiang.com/2024/08/06/e716b61ed0c4444db4e8e33bf2712432.pdf"; + final url = invoicesDetailInfo?.ossUrl ?? ""; final filename = url.substring(url.lastIndexOf("/") + 1); var request = await HttpClient().getUrl(Uri.parse(url)); var response = await request.close(); @@ -478,7 +478,7 @@ class _InvoicesDetailPage extends State { ); } - ///打开浏览器 + ///下载电子发票 launchBrowser() async { String url = invoicesDetailInfo?.ossUrl ?? ""; if (await canLaunch(url)) { diff --git a/lib/order/invoices_manage/pdf_screen.dart b/lib/order/invoices_manage/pdf_screen.dart index fe8b6511..2e165377 100644 --- a/lib/order/invoices_manage/pdf_screen.dart +++ b/lib/order/invoices_manage/pdf_screen.dart @@ -8,179 +8,188 @@ class PDFScreen extends StatefulWidget { final String path; final int inlet; - PDFScreen({Key key, this.path,this.inlet}) : super(key: key); + PDFScreen({Key key, this.path, this.inlet}) : super(key: key); _PDFScreenState createState() => _PDFScreenState(); } class _PDFScreenState extends State with WidgetsBindingObserver { - final Completer _controller = Completer(); + final Completer _controller = + Completer(); int pages = 0; int currentPage = 0; - int pageTotal =1; + int pageTotal = 0; bool isReady = false; String errorMessage = ''; @override Widget build(BuildContext context) { - return widget.inlet == 1 ?Material( - type: MaterialType.transparency, - child: Stack( - children: [ - Center( - child: Container( - height:250, - decoration: BoxDecoration( - color: Colors.white, - ), - child: PDFView( - filePath: widget.path, - enableSwipe: true, - swipeHorizontal: true, - autoSpacing: false, - pageFling: true, - pageSnap: true, - defaultPage: currentPage, - fitPolicy: FitPolicy.BOTH, - preventLinkNavigation: - false, // if set to true the link is handled in flutter - onRender: (_pages) { - setState(() { - pages = _pages; - isReady = true; - }); - }, - onError: (error) { - setState(() { - errorMessage = error.toString(); - }); - print(error.toString()); - }, - onPageError: (page, error) { - setState(() { - errorMessage = '$page: ${error.toString()}'; - }); - print('$page: ${error.toString()}'); - }, - onViewCreated: (PDFViewController pdfViewController) { - _controller.complete(pdfViewController); - }, - onLinkHandler: (String uri) { - print('goto uri: $uri'); - }, - onPageChanged: (int page, int total) { - if(total >0){ - print('page change: $page/$total'); - setState(() { - currentPage = page +1; - pageTotal = total; - }); - }else{ - pageTotal = 1; - } - }, - ), - ), - ), - errorMessage.isEmpty - ? !isReady - ? Center( - child: CircularProgressIndicator(), - ) - : Container() - : Center( - child: Text(errorMessage), - ), - //pdfindex显示 - Positioned( - width: MediaQuery.of(context).size.width, - bottom:45, - child: Center( - child: Text("${currentPage}/${pageTotal}",style: TextStyle(color: Colors.white,fontSize: 16)), + return widget.inlet == 1 + ? Material( + type: MaterialType.transparency, + child: Stack( + children: [ + Center( + child: Container( + height: 250, + decoration: BoxDecoration( + color: Colors.white, + ), + child: PDFView( + filePath: widget.path, + enableSwipe: true, + swipeHorizontal: true, + autoSpacing: false, + pageFling: true, + pageSnap: true, + defaultPage: currentPage, + fitPolicy: FitPolicy.BOTH, + preventLinkNavigation: false, + // if set to true the link is handled in flutter + onRender: (_pages) { + setState(() { + pages = _pages; + isReady = true; + }); + }, + onError: (error) { + setState(() { + errorMessage = error.toString(); + }); + print(error.toString()); + }, + onPageError: (page, error) { + setState(() { + errorMessage = '$page: ${error.toString()}'; + }); + print('$page: ${error.toString()}'); + }, + onViewCreated: (PDFViewController pdfViewController) { + _controller.complete(pdfViewController); + }, + onLinkHandler: (String uri) { + print('goto uri: $uri'); + }, + onPageChanged: (int page, int total) { + if (total > 0) { + print('page change: $page/$total'); + setState(() { + currentPage = page + 1; + pageTotal = total; + }); + } else { + pageTotal = 1; + } + }, + ), + ), + ), + errorMessage.isEmpty + ? !isReady + ? Center( + child: CircularProgressIndicator(), + ) + : Container() + : Center( + child: Text(errorMessage), + ), + //pdfindex显示 + Positioned( + width: MediaQuery.of(context).size.width, + bottom: 45, + child: Center( + child: Text("${currentPage}/${pageTotal}", + style: TextStyle(color: Colors.white, fontSize: 16)), + ), + ), + ], ), - ), - ], - ), - ):Scaffold( - body: Stack( - children: [ - PDFView( - filePath: widget.path, - enableSwipe: true, - swipeHorizontal: true, - autoSpacing: false, - pageFling: true, - pageSnap: true, - defaultPage: currentPage, - fitPolicy: FitPolicy.BOTH, - preventLinkNavigation: - false, // if set to true the link is handled in flutter - onRender: (_pages) { - setState(() { - pages = _pages; - isReady = true; - }); - }, - onError: (error) { - setState(() { - errorMessage = error.toString(); - }); - print(error.toString()); - }, - onPageError: (page, error) { - setState(() { - errorMessage = '$page: ${error.toString()}'; - }); - print('$page: ${error.toString()}'); - }, - onViewCreated: (PDFViewController pdfViewController) { - _controller.complete(pdfViewController); - }, - onLinkHandler: (String uri) { - print('goto uri: $uri'); - }, - onPageChanged: (int page, int total) { if(total >0){ - print('page change: $page/$total'); - setState(() { - currentPage = page +1; - pageTotal = total; - }); - }else{ - pageTotal = 1; - } - }, - ), - errorMessage.isEmpty - ? !isReady - ? Center( - child: CircularProgressIndicator(), ) - : Container() - : Center( - child: Text(errorMessage), - ), - //pdfindex显示 - Positioned( - bottom: 45, - width: MediaQuery.of(context).size.width, - child: Center( - child: Text("${currentPage+1}/${pageTotal}",style: TextStyle(color: Colors.black,fontSize: 16)), - ), - ), - Positioned(//右上角关闭按钮 - right: 10, - top: MediaQuery.of(context).padding.top, - child: IconButton( - icon: Icon(Icons.close,size: 30,color: Colors.black,), - onPressed: (){ - Navigator.of(context).pop(); - }, + : Scaffold( + body: Stack( + children: [ + PDFView( + filePath: widget.path, + enableSwipe: true, + swipeHorizontal: true, + autoSpacing: false, + pageFling: true, + pageSnap: true, + defaultPage: currentPage, + fitPolicy: FitPolicy.BOTH, + preventLinkNavigation: false, + // if set to true the link is handled in flutter + onRender: (_pages) { + setState(() { + pages = _pages; + isReady = true; + }); + }, + onError: (error) { + setState(() { + errorMessage = error.toString(); + }); + print(error.toString()); + }, + onPageError: (page, error) { + setState(() { + errorMessage = '$page: ${error.toString()}'; + }); + print('$page: ${error.toString()}'); + }, + onViewCreated: (PDFViewController pdfViewController) { + _controller.complete(pdfViewController); + }, + onLinkHandler: (String uri) { + print('goto uri: $uri'); + }, + onPageChanged: (int page, int total) { + if (total > 0) { + print('page change: $page/$total'); + setState(() { + currentPage = page + 1; + pageTotal = total; + }); + } else { + pageTotal = 1; + } + }, + ), + errorMessage.isEmpty + ? !isReady + ? Center( + child: CircularProgressIndicator(), + ) + : Container() + : Center( + child: Text(errorMessage), + ), + //pdfindex显示 + Positioned( + bottom: 45, + width: MediaQuery.of(context).size.width, + child: Center( + child: Text("${currentPage}/${pageTotal}", + style: TextStyle(color: Colors.black, fontSize: 16)), + ), + ), + Positioned( + //右上角关闭按钮 + right: 10, + top: MediaQuery.of(context).padding.top, + child: IconButton( + icon: Icon( + Icons.close, + size: 30, + color: Colors.black, + ), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ), + ], ), - ), - ], - ), - - ); - + ); } -} \ No newline at end of file +}