Flutter で webView を実装しましたが、サーバー上にある PHP Web サイトが開きません。何が間違っているのでしょうか。
私は Flutter の初心者で、Webview を使用して Web サイトの Web ページをアプリケーションに統合しようとしましたが、うまくいきませんでした。
Widget build(BuildContext context) {
// TODO: implement build
return WebviewScaffold(
appBar: AppBar(iconTheme:IconThemeData(color: Colors.white),title: Text("Intake Form",style:new TextStyle(color: Colors.white,fontWeight: FontWeight.bold)),backgroundColor:Colors.indigoAccent,automaticallyImplyLeading: false),
url: url,
//url: "http://xxxxxxxx/",
withJavascript: true,
supportMultipleWindows: true,
withLocalStorage: true,
allowFileURLs: true,
enableAppScheme: true,
appCacheEnabled: true,
hidden: false,
scrollBar: true,
geolocationEnabled: false,
clearCookies: true,
// usesCleartextTraffic="true"
);
}
実行中の Webview としての出力を期待していますが、エラーがスローされます。
ベストアンサー1
Flutter プロジェクトのメイン ディレクトリには、次の 3 つのメイン フォルダーがあります。
- lib = your Dart code
- ios = generated structure for iOS platform
- android = generated structure for Android platform
ディレクトリに注目してくださいandroid
。開くと、「典型的な Android アプリの構造」が表示されます。
したがって、次の 2 つのことを行う必要があります。
1) 新しいファイルを追加するres
ディレクトリへ移動:
my_flutter_project/android/app/src/main/res/
ディレクトリを作成しますxml
( にres
!)
そして、その中にxml
名前network_security_config.xml
と内容の新しいファイルを追加します:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
network_security_config.xml
パスに配置する必要があります:
my_flutter_project/android/app/src/main/res/xml/network_security_config.xml
このファイルに関する詳細情報は、以下を参照してください。
2) AndroidManifest.xmlを変更する
次の場所に移動します:
flutter_project/android/app/src/main/AndroidManifest.xml
AndroidManifest.xml
XML ファイルであり、構造は次のようになります。
<manifest>
<application>
<activity>
...
</activity>
<meta-data >
</application>
</manifest>
したがって、<application>
PROPERTIES には 1 行追加する必要があります。
android:networkSecurityConfig="@xml/network_security_config"
覚えておかなければならないプロパティとして追加する(application
開始タグ内):
<application
SOMEWHERE HERE IS OK
>
タグとしてではない:
<application> <--- opening tag
HERE IS WRONG!!!!
<application/> <--- closing tag