Im having an issue! I want to create an InAppWebView server that points to any folder in my external storage, but it only points to the assets of the project! Is it possible to start the server outside of the assets? I want to use '/storage/emulated/0/Download/mediplus-lite' as the root folder for my server, not a folder in assets!
class _InAppTestState extends State<InAppTest> {
final GlobalKey webviewKey = GlobalKey();
InAppWebViewController? webViewController;
InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
),
android: AndroidInAppWebViewOptions(useHybridComposition: true));
late PullToRefreshController pullToRefreshController;
String url = 'google.com';
double progress = 0;
final urlContrller = TextEditingController();
InAppLocalhostServer localhostServer = InAppLocalhostServer(
documentRoot: '/storage/emulated/0/Download/mediplus-lite');
@override
void initState() {
super.initState();
localhostServer.start();
pullToRefreshController = PullToRefreshController(
options: PullToRefreshOptions(color: Colors.blue),
onRefresh: () async {
if (Platform.isAndroid) {
webViewController?.reload();
}
},
);
}
@override
Widget build(BuildContext context) {
webViewController?.zoomBy(zoomFactor: 1);
webViewController?.injectCSSCode(source: 'body{transform: scale(1.0);}');
return Scaffold(
body: SafeArea(
child: Column(
children: [
SizedBox(
width: 200,
height: 200,
child: Stack(
children: [
InAppWebView(
key: webviewKey,
//initialUrlRequest: URLRequest(
// url: Uri.parse(
// 'file:///storage/emulated/0/Download/mediplus-lite/index.html')),
// initialFile:
// '/storage/emulated/0/Download/mediplus-lite/index.html',
initialUrlRequest: URLRequest(
url: Uri.parse('http://127.0.0.1:8080/index.html')),
initialOptions: options,
pullToRefreshController: pullToRefreshController,
onWebViewCreated: (controller) {
webViewController = controller;
},
onLoadStart: (controller, url) {
setState(() {
this.url = url.toString();
urlContrller.text = this.url;
});
},
androidOnPermissionRequest:
(controller, origin, resources) async {
return PermissionRequestResponse(
resources: resources,
action: PermissionRequestResponseAction.GRANT,
);
},
)
],
)),
TextButton(
onPressed: () {
webViewController?.zoomBy(zoomFactor: 0.1);
},
child: Text('Press'),
),
],
)),
);
}
}