import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:fluttertoast/fluttertoast.dart';
class WebViewScreen extends StatefulWidget {
const MarketingScreen({super.key});
@override
WebViewScreenState createState() => WebViewScreenScreenState();
}
class WebViewScreenState extends State< WebViewScreen > {
final GlobalKey webViewKey = GlobalKey();
late final String url;
InAppWebViewController? webViewController;
InAppWebViewSettings settings = InAppWebViewSettings(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
javaScriptEnabled: true,
javaScriptCanOpenWindowsAutomatically: true,
);
@override
void initState() {
super.initState();
try {
url = "https://google.com";
if (url.isEmpty) {
showToast("Error: URL is empty");
} else {
showToast("URL: $url");
}
} catch (e) {
showToast("Error initializing URL: $e");
print("Error initializing URL: $e");
}
}
void showToast(String message) {
Fluttertoast.showToast(
msg: message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.black,
textColor: Colors.white,
fontSize: 16.0,
);
}
@override
Widget build(BuildContext context) {
if (url.isEmpty) {
return Scaffold(
body: Center(
child: Text('Error: URL is empty'),
),
);
}
return Scaffold(
body: SafeArea(
child: InAppWebView(
key: webViewKey,
initialUrlRequest: URLRequest(url: WebUri(url)),
initialSettings: settings,
onWebViewCreated: (controller) {
webViewController = controller;
},
onLoadStart: (controller, url) {
setState(() {
showToast("start: $url");
});
},
onReceivedError: (controller, request, error) {
showToast("Error: $error");
},
),
),
);
}
}
I am developing a web app that runs on both AOS and iOS with flutter.
The reason it is made as a web app is because it is planned to be distributed without being released on the AppStore or PlayStore.
When I used an iframe, the Notion site gave a Content Security Policy warning and only the AppBar was visible. Inappwebview and flutter webview do not show the AppBar, so it seems that the view itself cannot be drawn.
How can I solve this?
I need help.