0

I have 4 menu in bottom navigation, and two of them is webview using inappwebview.

first webview is : https://google.com

second webview is : https://flutter.dev/

If I click first webview then I click second webview, the webview is not redirect to new url, and vice versa.

but if after click first webview then I click other menus that are not webview, then click second webview it's normal redirect to second webview

so how to redirect to new url when webviewpage is still active (not close using click other menu)

this my inappwebview

InAppWebView(
                initialUrlRequest: URLRequest(url: Uri.parse(widget.url)),
                onWebViewCreated: (
                    InAppWebViewController controller) async {
                  _webViewController = controller;
                },
                androidOnPermissionRequest: (controller, origin, resources) async {
                  return PermissionRequestResponse(
                      resources: resources,
                      action: PermissionRequestResponseAction.GRANT);
                },
                onProgressChanged: (InAppWebViewController controller,
                    int progress) {
                  setState(() {
                    this.progress = progress / 100;
                  });
                },
              )

this the bottom navigation

_children = [
        HomePage(),
        ProfilePage(),
        MyWebview(url: web_inbox, statusAppbar: false, webMenu: web_menu_inbox,),
        MyWebview(url: web_feedback, statusAppbar: false, webMenu: web_menu_feedback,),
      ]

BottomNavigationBar(
          onTap: onTappedBar,
          currentIndex: _current,
          backgroundColor: Color(0xFF003c85),
          selectedFontSize: 12,
          unselectedFontSize: 12,
          selectedItemColor: Color(0xFFf4931f),
          unselectedItemColor: Color(0xFFc0bfbf),
          type: BottomNavigationBarType.fixed,
          items: [
            BottomNavigationBarItem(
                icon: Image.asset('asset/images/abba-home-pasif.png', height: 25, width: 25, fit: BoxFit.fill,),
                activeIcon: Image.asset('asset/images/abba-home-aktif.png', height: 25, width: 25, fit: BoxFit.fill,),
                label: "Home"
            ),
            BottomNavigationBarItem(
                icon: Image.asset('asset/images/profile-pasif.png', height: 25, width: 25, fit: BoxFit.fill,),
                activeIcon: Image.asset('asset/images/profile-aktif.png', height: 25, width: 25, fit: BoxFit.fill,),
                label: "Profile"
            ),
            BottomNavigationBarItem(
                icon: Image.asset('asset/images/inbox-pasif.png', height: 25, width: 32, fit: BoxFit.fill,),
                activeIcon: Image.asset('asset/images/inbox-aktif.png', height: 25, width: 32, fit: BoxFit.fill,),
                label: "Inbox"
            ),
            BottomNavigationBarItem(
                icon: Image.asset('asset/images/comment-pasif.png', height: 27, width: 30, fit: BoxFit.fill,),
                activeIcon: Image.asset('asset/images/comment-aktif.png', height: 27, width: 30, fit: BoxFit.fill,),
                label: "Feedback"
            )
          ],
        )

void onTappedBar(int index){
    setState((){
      _current = index;
    });
  }

1 Answer 1

1

Finally, I found some solution

add ValueNotifier to listen if variable url is changed

add ValueNotifier<String> newurl = ValueNotifier<String>(''); to webviewPage as a global variable

add newurl.addListener(changeUrl); to initstate in webviewpage

webviewpage will like this

ValueNotifier<String> newurl = ValueNotifier<String>('');

class MyWebview extends StatefulWidget {
  late String url = "";
  late bool statusAppbar = true;
  late String webMenu = "";

  MyWebview({required this.url, required this.statusAppbar, required this.webMenu});

  @override
  _MyWebviewState createState() => new _MyWebviewState();
}

class _MyWebviewState extends State<MyWebview> {

  late InAppWebViewController _webViewController;
  double progress = 0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    newurl.addListener(changeUrl);
  }

  void changeUrl(){
    _webViewController.loadUrl(urlRequest: URLRequest(url: Uri.parse(newurl.value)));
  }
}

and add value of valuelistener when menu bottom navigation is cliked

void onTappedBar(int index){
    setState((){
      if(index==2) // inbox
        newurl.value=web_inbox;
      else if(index==3) // feedback
        newurl.value=web_feedback;
      else
        newurl.value="";

      _current = index;
    });
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.