Issue
I was using flutter to develop a app with url_launcher 5.7.2 package https://pub.dev/packages/url_launcher that launch webivew only for the google form when user tap some button.
However I find that if using the shorten URL of google form it will hit error of ERR_UNKNOWN_URL_SCHEME, using the original url is working.
I was using this example https://pub.dev/packages/url_launcher/example and replace the url to https://forms.gle/mEwVA8jXmwJEFn5X6 and then click the button of Launch in app(JavaScript ON)
await launch(url,forceSafariVC: true,
forceWebView: true,
enableJavaScript: true,);
If using the original long URL https://docs.google.com/forms/d/e/1FAIpQLSfzXnHMRe890CJj5rSxN-jonjrvZ8HvRBSFcdyJD5IDhOr-IQ/viewform?usp=sf_link is working.
I already add android:usesCleartextTraffic="true" to my AndroidManifest.xml but still not working for short url
Solution
I suggest you using 'flutter_webview_plugin' package instead of 'url_launcher'.
This problem is occurred by redirecting and browser can not understand starts of 'intent' in android.
import 'dart:async';
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 MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
WebViewPage(url: 'https://forms.gle/mEwVA8jXmwJEFn5X6'),
),
);
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget _buildBody() {
return Container();
}
}
class WebViewPage extends StatefulWidget {
final String url;
WebViewPage({Key key, this.url}) : super(key: key);
@override
_WebViewPageState createState() => _WebViewPageState();
}
class _WebViewPageState extends State<WebViewPage> {
final flutterWebviewPlugin = FlutterWebviewPlugin();
@override
void initState() {
super.initState();
}
@override
void dispose() {
flutterWebviewPlugin.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
child: WebviewScaffold(
appBar: AppBar(
title: Text('WebView Page'),
),
url: widget.url,
userAgent: 'Fake',
clearCookies: false,
clearCache: false,
hidden: true,
appCacheEnabled: true,
supportMultipleWindows: true,
),
);
}
}
Answered By - KuKu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.