Comments (6)
Thanks for the report @YashExpert10
Can you narrow down code sample only to minimal and filter out unnecessary implementation to make it reduced code sample to work with ?
Also, is there a way for you to check the native Android behavior if it works as expected ? This is just to narrow down if the behavior is specific to Flutter or occurs in native as well.
from flutter.
Thanks for response @darshankawar
//I am Tested this code on my real Android device, I haven't tested on iOS
//Here is minimal code
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
runApp(const MaterialApp(home: TabsView()));
}
class TabsView extends StatefulWidget {
const TabsView({super.key});
@override
_TabsViewState createState() => _TabsViewState();
}
class _TabsViewState extends State<TabsView> {
int _currentIndex = 0;
int tabIndex = 0;
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
/// Added Stack Widget
children: [
Offstage(
offstage: _currentIndex != 0,
child: const First(),
),
Offstage(
offstage: _currentIndex != 1,
child: const Second(),
),
],
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
selectedItemColor: Colors.deepOrange[800],
backgroundColor: Colors.grey[300],
unselectedItemColor: Colors.grey[800],
currentIndex: _currentIndex,
onTap: onTabTapped,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Webview 1',
),
BottomNavigationBarItem(
icon: Icon(Icons.web),
label: 'Webview 2',
),
],
),
);
}
}
class First extends StatefulWidget {
const First({super.key});
@override
State<First> createState() => _FirstState();
}
class _FirstState extends State<First> {
late final WebViewController _controller1;
@override
void initState() {
super.initState();
_controller1 = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse('https://stackoverflow.com'));
}
Future<bool> _goBackCall1(BuildContext context) async {
if (await _controller1.canGoBack()) {
_controller1.goBack();
return Future.value(false);
} else {
// SystemNavigator.pop();
return Future.value(true);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Flutter WebView1"),
),
body: PopScope(
canPop: false,
onPopInvoked: (bool didPop) {
if (didPop) {
print('didPop call: $didPop');
return;
}
_goBackCall1(context);
},
child: SafeArea(
child: Stack(
children: [
WebViewWidget(controller: _controller1),
],
),
),
),
);
}
}
class Second extends StatefulWidget {
const Second({super.key});
@override
State<Second> createState() => _SecondState();
}
class _SecondState extends State<Second> {
late final WebViewController _controller2;
@override
void initState() {
super.initState();
_controller2 = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse('https://google.com'));
}
Future<bool> _goBackCall2(BuildContext context) async {
if (await _controller2.canGoBack()) {
_controller2.goBack();
return Future.value(false);
} else {
// SystemNavigator.pop();
return Future.value(true);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Flutter WebView2"),
),
body: PopScope(
canPop: false,
onPopInvoked: (bool didPop) {
if (didPop) {
print('didPop call: $didPop');
return;
}
_goBackCall2(context);
},
child: SafeArea(
child: Stack(
children: [
WebViewWidget(controller: _controller2),
],
),
),
),
);
}
}
from flutter.
Controller should be different for different window.
[...]
Controllers and runJavaScript and other method should not be conflict for different Class.
The issue description is describing this as being a problem where calling goBack
on one controller is affecting two web views, but that not what's happening. Both onPopInvoked
methods are being called when back
is pressed, meaning this code is calling goBack
on each webview individually. webview_flutter
is therefore behavior correctly here, and the issue is with the code calling it, not the plugin.
from flutter.
Controller should be different for different window.
[...]
Controllers and runJavaScript and other method should not be conflict for different Class.The issue description is describing this as being a problem where calling
goBack
on one controller is affecting two web views, but that not what's happening. BothonPopInvoked
methods are being called whenback
is pressed, meaning this code is callinggoBack
on each webview individually.webview_flutter
is therefore behavior correctly here, and the issue is with the code calling it, not the plugin.
Thanks Sir for your Guidance @stuartmorgan
Can u please give me full example code Or Edit my example code so i understand where i am doing wrong ?
from flutter.
@YashExpert10
Would be best to raise this in support channels like StackOverflow or https://www.reddit.com/r/flutterhelp/ to get code assistance for your case. I'll close this based on Stuart's comment.
from flutter.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v
and a minimal reproduction of the issue.
from flutter.
Related Issues (20)
- toStringAsFixed and Number format does not work correctly
- [web] Implement `AppLifecycleState.detached` properly
- TextPainter getFullHeightForCaret returns confusing values with nested TextSpans HOT 1
- "run suite safari-dart2js-html-ui" test failed: `[Webdriver][Error] Unable to start the server: Operation not permitted`
- Xcode compilation is slow on macOS 14 bots HOT 10
- iOS embedder always creates overlay layer, even when its empty. HOT 4
- WidgetsBindingObserver doesn't report gaining / losing focus on GNOME when changing workspace views
- [camera_android_camerax] `ResolutionPreset.max` gets different camera aspect ratio compare to `camera_android`
- [camera_android_camerax] `setZoomLevel` is slow or throttled compare to `camera_android`
- [tool_crash] SocketException: Send failed, OS Error: No route to host, errno = 65
- AndroidView touch event issue
- [tool_crash] Flutter crashes when filesystem doesn't support symbolic links HOT 1
- HarmonyOS next HOT 1
- android_deferred_components_setup_files generates invalid build.gradle
- Blur doesn't apply properly when a platform view gets rounded HOT 1
- Unable to Launch Microsoft Edge for Flutter
- [tool] `TestBed` doesn't include a stub for `Analytics`
- [tool_crash] FileSystemException: Failed to decode data using encoding 'utf-8', null HOT 1
- [tool] some tests test for sending GA3 analytics events but not GA4
- GoRouter should better deal with multiple path separators
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.