How to render image using HTML, CSS using flutter to create iOS-App?

后端 未结 1 330
我在风中等你
我在风中等你 2020-12-19 05:51

I am trying to create the PDF using HTML, CSS in flutter. So, In some cases I have to render the asset image using html and css.

It is rendering in

相关标签:
1条回答
  • 2020-12-19 06:16

    The current implementation, the FLTWebViewController and FLTWebViewFactory class in webview plugin don’t have access to registrar, so I changed their initWithMessenger method to initWithRegistrar. Now we have the answer to loading asset file in iOS webview:

    NSString* key = [_registrar lookupKeyForAsset:url];
    NSURL* nsUrl = [[NSBundle mainBundle] URLForResource:key withExtension:nil];
    [_webView loadFileURL:nsUrl allowingReadAccessToURL:[NSURL URLWithString:@"file:///"]];
    

    as pull request: https://github.com/flutter/plugins/pull/1247/files

    Example :

    <html>
     <head>
     </head>
     <body>
        <img src="image_name.jpg">
     </body>
    </html>
    

    Then create a assets folder in the root of the Flutter project :

    assets:
      - assets/image_name.jpg
      - assets/htmlfile.html
    

    Create the WebView The dart code below creates the WebView and renders the local assets/htmlfile.html file.

      return WebView(
              initialUrl: 'assets/htmlfile.html',
              javascriptMode: JavascriptMode.unrestricted,
              onWebViewCreated: (WebViewController webViewController) {
                _controller.complete(webViewController);
              },
            );
    

    Loading Local Assets in WebView in Flutter

    0 讨论(0)
提交回复
热议问题