flutter:webview_flutter和flutter_inappwebview的简单使用
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebViewExample extends StatefulWidget {
@override
_WebViewExampleState createState() => _WebViewExampleState();
}
class _WebViewExampleState extends State<WebViewExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('WebView Example'),
),
body: WebView(
initialUrl: 'https://flutter.dev',
),
);
}
}
对于flutter_inappwebview
,可以参考以下示例代码:
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class InAppWebViewExample extends StatefulWidget {
@override
_InAppWebViewExampleState createState() => _InAppWebViewExampleState();
}
class _InAppWebViewExampleState extends State<InAppWebViewExample> {
InAppWebViewController webView;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('InAppWebView Example'),
),
body: InAppWebView(
initialUrl: 'https://flutter.dev',
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
),
);
}
}
这两个示例都展示了如何在Flutter应用中嵌入一个WebView来加载和显示网页。webview_flutter
是Flutter官方提供的一个WebView插件,而flutter_inappwebview
则提供了更多的功能和可定制性。根据你的具体需求选择合适的插件。
评论已关闭