open a local IP web page in flutter - flutter

I need to open a local IP web page in flutter like 192.168.4.1,
but it didn't open wit me ...
can you help me :
this is my code
final Completer<WebViewController> _controller = Completer<WebViewController>();
String src = 'http://192.168.4.1/';
Scaffold(
appBar: AppBar(
title: Text('Easy Web View'),
leading: IconButton(
icon: Icon(Icons.access_time),
onPressed: () {
setState(() {
print("Click!");
open = !open;
});
},
),
),
body: WebView(
initialUrl: src,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
gestureNavigationEnabled: true,
)
)

Find out the location of adb.exe(mine is USERNAME\AppData\Local\Android\Sdk\platform-tools\adb.exe), then run the following command,
adb.exe reverse tcp:3000 tcp:3000
I am using the physical phone, and it's working for me.

Related

How to add circular indicator to webview in flutter

i am new here. Please forgive me if I make a mistake. I'm trying to make a payment screen. But I can't solve a small problem. I couldn't understand the cause of the problem. when i click to 'start payment' button it's show me that screen about 2 second.And it's look bad. Bad View
But good news it's skip automatically normal payment screen. How can I show something else(Circular progress indicator, Lineer progres indicator etc.) on the screen instead of that String? My codes are below;
if (data['Status'] != "failure") {
Navigator.of(context).push(MaterialPageRoute(
builder: ((context) => CoreWebView(
htmlCode: data['paymentUrl'],
))));
}
It's my WebView
WebViewPlus(
initialUrl: "https://example.com",
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
//widget.html==data['paymentUrl'];
var page = 'r"""${widget.htmlCode}"""';
controller.loadString(page);
},
zoomEnabled: false,
),
Make your widget a StatefulWidget.
Add a variable as bool isLoading = true;.
Change your code as:
Stack(
children: [
WebViewPlus(
onPageFinished: (url) {
setState(() {
isLoading = false;
});
},
initialUrl: "https://example.com",
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
//widget.html==data['paymentUrl'];
var page = 'r"""${widget.htmlCode}"""';
controller.loadString(page);
},
zoomEnabled: false,
),
if(isLoading)
Center(child: CircularProgressIndicator()
)
],
),

Null check operator used on a null value Error in reload webview

Please I'm working on a flutter WebView project and I need to reload my page if I click a button but it gave me this Error : Null check operator used on a null value. Thank you in advance
this is my code :
WebView(
initialUrl: "https://wikoget.com",
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_webViewController = webViewController;
_controller.complete(webViewController);
},
onPageFinished: (String url) {
_webViewController
.evaluateJavascript("javascript:(function() { " +
"var head = document.getElementsByClassName('main-header-bar-wrap')[0];" +
"head.parentNode.style.cssText = ' position: sticky;position: -webkit-sticky; top : 0 ';" +
"var footer = document.getElementsByTagName('footer')[0];" +
"footer.parentNode.removeChild(footer);" +
"})()")
.then((value) => debugPrint('Page finished loading Javascript'));
},
onWebResourceError: (error) => setState(() {
isError = true;
}),
),
if (isError)Center(
child :RaisedButton(
padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 30),
onPressed: ()=> _webViewController.reload(),
color: Color(int.parse("0xff135888")),
shape:const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(30)),
),
child:const Text("Réessayez",style: TextStyle(color:Colors.white),)
),
],
),
),
Although your code is incomplete, here's what you need to make your webview reload easily.
Create a webview controller and initialize it when the webview is created to the controller of the webview:
WebViewController? webViewController;
.
.
.
onWebViewCreated: (controller){
webViewController = controller;
}
reload when your button is pressed:
onPressed: () {
webViewController!.reload();
},
Click here to read more about making your webview work excellently

Popup is not working in Flutter Web VIew package

I am using 'flutter_webview' package for payment the web view working fine. but on payment its open new popup, that popup is working in other external browser but not in mobile view.
please guide me to handle the popup in webview.
Expanded(
child: WebView(
debuggingEnabled: true,
initialUrl: paymentUrl,
allowsInlineMediaPlayback: true,
javascriptMode: JavascriptMode.unrestricted,
gestureNavigationEnabled: true,
onWebViewCreated: (WebViewController webViewController) {
_controller = webViewController;
},
onWebResourceError: (WebResourceError webviewerrr) {
print("Handle your Error Page here");
},
javascriptChannels: Set.from([
JavascriptChannel(
name: 'Alert',
onMessageReceived: (JavascriptMessage message) {
// alert message = Test alert Message
print(message.message);
// TODO popup
},
)
]),
),
),
I found the solution, while using the razor pay we have to integrate razorpay_flutter package instead of going with the webview_flutter

Flutter handle on click events in Webview

I am trying to build webview in my mobile application
In the webview when click on search all the records to particular time period are shown it works but when click on Export To Excel button it should download the excel sheet but nothing works in my application..
Below is the code what I have done
Thanks for help!![enter image description here][1]
PS: URL hidden for security reasons..
`
Stack(
children: [
Container(
padding: EdgeInsets.all(10.0),
child: progress < 1.0
? LinearProgressIndicator(
value: progress,
backgroundColor: Colors.amber,
)
: Container()),
WebView(
initialUrl:
"URL",
javascriptMode: JavascriptMode.unrestricted,
gestureNavigationEnabled: true,
onWebViewCreated: (WebViewController controller) {
_webViewController = controller;
},
onProgress: (int progress) {
setState(() {
this.progress = progress / 100;
});
},
onPageFinished: (finish) {
setState(
() {
isLoading = false;
},
);
},
),
],
),
Use navigationDelegate parameter in Webview constructor.
WebView(
initialUrl: 'https://google.com',
navigationDelegate: (action) {
if (action.url.contains('mail.google.com')) {
print('Trying to open Gmail');
Navigator.pop(context); // Close current window
return NavigationDecision.prevent; // Prevent opening url
} else if (action.url.contains('youtube.com')) {
print('Trying to open Youtube');
return NavigationDecision.navigate; // Allow opening url
} else {
return NavigationDecision.navigate; // Default decision
}
},
),
That's it. Enjoy coding!

Flutter InAppWebView does not allow non english content in textfield

I'm having a weird issue with the Flutter InAppWebView plugin version 4.0.0+4 here https://pub.dev/packages/flutter_inappwebview where I try to load the simple contact us form into the plugin and realize that I can't enter the content into html input text field if I use non English keyboard, in my case I use Vietnamese keyboard. If I switch the keyboard to English one then its working. I double checked the contact us form and made sure its working 100% on Chrome browser outside of the Flutter app using even non English keyboard. I don't use any special code or settings for the plugin, just same as the one mentioned in the pub.dev. I'm using Flutter channel stable v. 1.22.6
This is my code in case you need it:
class WebViewerWidget extends StatefulWidget {
final Map<String, String> metaData;
WebViewerWidget({this.metaData});
#override
_WebViewerWidgetState createState() => _WebViewerWidgetState();
}
class _WebViewerWidgetState extends State<WebViewerWidget> {
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
InAppWebViewController _webviewCtrl;
double progressIndicator = 0;
return Scaffold(
backgroundColor: ColorPalette.white,
appBar: PreferredSize(
child: TopNavWidget(
title: widget.metaData['title'] ?? '',
),
preferredSize: Size.fromHeight(50.0),
),
body: Builder(
builder: (BuildContext context) {
return Container(
child: Column(
children: [
Container(
child: progressIndicator < 1
? LinearProgressIndicator(
value: progressIndicator,
backgroundColor: Colors.black12,
valueColor:
AlwaysStoppedAnimation<Color>(Colors.blue),
)
: Container()),
Expanded(
child: InAppWebView(
initialUrl: widget.metaData['url'] ?? 'about:blank',
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
javaScriptEnabled: true,
useShouldInterceptAjaxRequest: true,
useShouldInterceptFetchRequest: true,
),
ios: IOSInAppWebViewOptions(),
android: AndroidInAppWebViewOptions(),
),
onWebViewCreated:
(InAppWebViewController webviewController) {
_webviewCtrl = webviewController;
},
onProgressChanged:
(InAppWebViewController controller, int progress) {
setState(() {
progressIndicator = progress / 100;
});
},
),
),
],
),
);
},
));
}
}
Thanks.
Ok, after spending a couple days fixing the issue, I had to give up on this one. Its definitely a bug from the plugin, found someone had the similar issue here https://github.com/pichillilorenzo/flutter_inappwebview/issues/560. I then tried another plugin called WebView https://pub.dev/packages/webview_flutter and it worked perfectly.
This has been fixed with new version 5.0.0 (the latest version now is 5.0.5+3): use useHybridComposition: true Android-specific webview option, all the issues related to the Android keyboard are fixed.