一個最簡單的app嵌套webview的案例代碼

字號+ 編輯: 国内TP粉 修訂: 面向ICU 來源: 原创 2023-09-11 我要說兩句(0)

就簡簡單單一個頁面

首先找到flutter项目根目录下的pubspec.yaml, 在里面添加一行webview的组件, 类似这样:

dependencies:
  flutter:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  flutter_webview_plugin: ^0.3.0+2

dev_dependencies:
  flutter_test:
    sdk: flutter

上述代码中, 支架了flutter_webview_plugin这一行。注意,是在dependencies的缩进区域布置的, 别搞错了...


找到flutter项目目录/lib/main.dart这个文件, 代码如下:

import "package:flutter/material.dart";
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

void main()=>runApp(MyApp());

class MyApp extends StatelessWidget
{
  @override
  Widget build(BuildContext context)
  {
    return new MaterialApp(
      routes: {
        "/": (_) => new WebviewScaffold(
          url: "https://www.baidu.com",
          appBar: new AppBar(
            title: new Text("Widget webview"),
          ),
        )
      },
    );
  }
}

在测试的时候, 你可能会发现大于8.0版本的android系统无法读入网页, ios有时候不读非https的页面, 这是另外的故障, 需要修改一些配置, 在这里暂时不多加探讨。


閲完此文,您的感想如何?
  • 有用

    0

  • 沒用

    4

  • 開心

    1

  • 憤怒

    1

  • 可憐

    0

1.如文章侵犯了您的版權,請發郵件通知本站,該文章將在24小時内刪除;
2.本站標注原創的文章,轉發時煩請注明來源;
3.交流群: PHP+JS聊天群

相關課文
  • Invalid prop custom validator check failed for prop navigationBarTextStyle

  • svg是什麽文件格式?如何打開svg文件?

  • Cordova報錯Could not find an installed version of Gradle either in Android Studio

  • flutter基礎名詞和簡單代碼案例

我要說說
網上賓友點評