I want to open my index.html in the assets folder but with parameters, I tried to open like this:
initialFile: "assets/index.html?name=foo&lastname=Bar" but it doesn´t work.
return Container(
child: InAppWebView(
//initialFile: "assets/index.html",
initialOptions: inAppWebViewGroupOptions,
initialUrlRequest: URLRequest(
url: Uri.parse("file:///assets/index.html"),
method: 'GET',
body:
Uint8List.fromList(utf8.encode("name=foo&lastname=Bar")),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}),
),
);
}
maybe you can just set WebView cookie to pass paramerters.
You can use In-App Localhost Server.
Related
I have added a pdfviewer in my Apps using Library flutter: flutter_cached_pdfview
some part of the code:
import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';
goToReading(String link){
Navigator.push(context, MaterialPageRoute(
builder: (_)=> PDF(
enableSwipe: true,
swipeHorizontal: false,
autoSpacing: false,
pageFling: false,
onError: (error) {
print(error.toString());
},
onPageError: (page, error) {
print('$page: ${error.toString()}');
},
).fromUrl(link,
placeholder: (progress) => Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Lottie.asset(
'assets/images/data.json',
height: 200,
controller: _controller,
onLoaded: (composition) {
_controller..duration = composition.duration..forward();
},
),
),
)
)
));
}
What I want is to open every link inside the pdf to open in webview for now it open in external browser (Chrome, safari),
************************************************************************I want it to open in internal webview inside the app it may be possible by using urllauncher but i dont know how to use it,
See this to understand my problem
See this to understand the current status
You have to set onLinkHandle and preventLinkNavigation:true in your file.
On onLinkHandle, you can set it to open WebView inside your app instead of opening the browser for it. Becuase by default it will always open web browser if you don't specify those things.
I am trying to download a .pdf file from an URL having a POST request with body in Flutter.
I am using Dio plugin for network calls.
Here is what I tried to do so far:
Dio dio = Dio();
late Response response;
Future<APIResponse> downloadFile({token}) async {
await dio
.post('https://www.example.com/sample/download',
data: {
{"month": "January", "year": "2022"}
},
options: Options(
headers: {
'Authorization': 'Bearer $token',
},
))
.then((value) {
if (value.statusCode == 200) {
response = value;
// here I need the file to be downloaded
// specific folder would be /downloads folder in Internal Storage
}
});
return APIResponse.fromJson(response.data);
}
But Dio doesn't have POST method with download option, as far as I have checked.
This is what is given in Dio docs:
For downloading a file:
response = await dio.download('https://www.google.com/', './xx.html');
But here we cannot add request body or headers.
Also I need to download the file to a specific folder in the device such as /downloads folder in internal storage.
When download is successful, we can open the file right from that screen.
How to proceed? I am very new to Flutter.
You can use options parameter. You also can add cookie or other parameters.
response = await dio.download(
'https://www.google.com/', './xx.html',
options: Options(
headers: {'cookie': 'any_cookie'},
method: 'POST',
),
);
We need to pass headers to server that hosts mp3 files and using following code but somehow header field is showing as null in logs, can you review and let us know if we are missing something or not using the headers correctly:
await _player
.setAudioSource(
ConcatenatingAudioSource(
children: queue
.map(
(item) => AudioSource.uri(
Uri.parse(item.id),
headers: {'header1': 'media.Ourhost', 'header2': 'media.Ourhost.app'},
tag: '',
),
)
.toList(),
),
)
I want to write an application that makes me register from app and send post request and get response to inappwebview just like exam below
InAppWebView(
initialUrl: widget.initUrls,
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
mediaPlaybackRequiresUserGesture: false,
debuggingEnabled: true,
),
),
onWebViewCreated: (InAppWebViewController c){
_controller = c;
if(staticEmail != null && staticPass != null) {
_controller.postUrl(url: "https://xxxxxxx.com/my-account", postData: utf8.encode(
"email=${staticEmail}&password=${staticPass}&wooc_user_phone=${staticShop}&wooc_user_name=${staticShop}&woocommerce-register-nonce=5d1b626841&_wp_http_referer=/my-account/®ister=Register") )
.whenComplete(() => {print("done")}).catchError((err){print("err : ${err}");
isloading = false;
});
}
},
);
and it login fine.
But when I go to another link or when I close app and login again it ask me to login again i just want to save cookie or session id that doesn't make me login every time
You can make use of the CookieManager of this flutter_inappwebview package to get and set cookies. This is a singleton that the plugin uses, you can access it via:
CookieManager.instance()
I am trying to openning sign-in google with webview in flutter application. I installed flutter_inappwebview: ^3.1.0 and this is my code:
child: InAppWebView(
initialUrl: url.toString(),
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
debuggingEnabled: true,
)),
but when i open google sin in page i got this error:
Using webview_flutter package you can fix the problem by adding userAgent: 'random', in the web view constructor. So, it will look like this:
WebView(
initialUrl: 'https://abdulrazakzakieh.com/',
userAgent: 'random',
)
change userAgent to random like -> userAgent: "random". works perfectly! but then it will most likely low end mobile interface for google page. that's the only drawback. else works perfectly fine !
For my case, It worked for this-
InAppWebView(
initialUrlRequest: URLRequest(url: Uri.parse("www.myurl.com")),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(userAgent: "random"),)
...)