How to add a Webview in Flutter?

前端 未结 7 1625
逝去的感伤
逝去的感伤 2020-12-15 17:43

I know its possible to add a WebView as a full page but couldn\'t find any sample code to do it. I assume you could use a PageView as it\'s base but not sure how to call the

7条回答
  •  Happy的楠姐
    2020-12-15 18:34

    In pubspec.yml file add dependency:

    webview_flutter: ^0.1.1
    

    For ioS App below keys paste in .plist file inside the ios project folder

    io.flutter.embedded_views_previewyes
    NSAppTransportSecurity
    
        NSAllowsArbitraryLoads
        
        NSAllowsArbitraryLoadsInWebContent
        
    
    

    and this is class code:

    import 'package:flutter/material.dart';
    import 'package:webview_flutter/webview_flutter.dart';
    import 'dart:async';
    
    class WebViewClass extends StatefulWidget {
      @override
      _WebViewClassState createState() => _WebViewClassState();
    }
    
    class _WebViewClassState extends State {
      Completer _controller = Completer();
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('WebView'),
          ),
          body: WebView(
            initialUrl: 'https://google.com',
            onWebViewCreated: (WebViewController webViewController) {
              _controller.complete(webViewController);
            },
          ),
        );
      }
    }
    

提交回复
热议问题