make webview change data with certain triggers on flutter

151

First create a Controller for your WebView

WebViewController _webViewController = WebViewController();

then assign it to webview

new Container(
height: 50,
width: 250,
child: WebView(
    controller: _webViewController,
    initialUrl: '${dataQuestions["list_question"][_counter]["data_option"][loop]["option_text"]}',
    javascriptMode: JavascriptMode.unrestricted,
    onWebViewCreated: (WebViewController webViewController) {
    _controller.complete(webViewController);},
)),

In your nextButton press callback(where you are increasing _counter and loop variables) load next through _webViewController

_webViewController.loadUrl('${dataQuestions["list_question"][_counter]["data_option"][loop]["option_text"]}');
Share:
151
uknown18user
Author by

uknown18user

Updated on December 28, 2022

Comments

  • uknown18user
    uknown18user over 1 year

    I have a flutter quiz project with a radio widget and when the next button is pressed the data will change (change questions) I try to use WebView on the question or question text but there is no data change,

    The following is a quiz with text

    Container(
         width: 250,
         child: new Text(
                                                 
         "${dataQuestions["list_question"][_counter]["data_option"][loop]["option_text"]}",
         maxLines: 2,
         overflow: TextOverflow.ellipsis,),)
    

    and that I do with the WebView

    new Container(
        height: 50,
        width: 250,
        child: WebView(
            initialUrl: '${dataQuestions["list_question"][_counter]["data_option"][loop]["option_text"]}',
            javascriptMode: JavascriptMode.unrestricted,
            onWebViewCreated: (WebViewController webViewController) {
            _controller.complete(webViewController);},
        )),
    
  • uknown18user
    uknown18user about 3 years
    thanks for the answer. but for webview flutter if I use data in the form of <p> tag it is read or not?
  • Abhi Tripathi
    Abhi Tripathi about 3 years
    Please clarify the query. The "data" you're talking about is it a HTML page? If yes then this sounds like you have problem in your HTML page it's not the webview.