如何在webview flutter中打开pdf内的链接

jjjwad0x  于 2023-01-31  发布在  Flutter
关注(0)|答案(1)|浏览(408)

我已经添加了一个pdfviewer在我的应用程序使用库flutter:flutter_cached_pdf查看部分代码:

import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';
  
  goToReading(String link){
    Navigator.push(context, MaterialPageRoute(
        builder: (_)=> PDF(
          enableSwipe: true,
          swipeHorizontal: false,
          autoSpacing: false,
          pageFling: false,
          onError: (error) {
            print(error.toString());
          },
          onPageError: (page, error) {
            print('$page: ${error.toString()}');
          },
        ).fromUrl(link,
            placeholder: (progress) => Scaffold(
              backgroundColor: Colors.white,
              body: Center(
                child: Lottie.asset(
                  'assets/images/data.json',
                  height: 200,
                  controller: _controller,
                  onLoaded: (composition) {
                    _controller..duration = composition.duration..forward();
                  },
                ),
              ),
            )
        )
    ));
  }

我想要的是打开PDF文件内的每一个链接在WebView中打开,现在它在外部浏览器(Chrome,Safari)中打开,

*****************************************************************************我希望它在应用程序内的内部webview中打开,可以使用urllauncher,但我不知道如何使用它,

See this to understand my problem
See this to understand the current status

o75abkj4

o75abkj41#

您必须在文件中设置onLinkHandlepreventLinkNavigation:true
onLinkHandle上,你可以设置它在你的应用中打开WebView,而不是打开浏览器。因为默认情况下,如果你不指定这些设置,它将总是打开网页浏览器。

相关问题