make webview change data with certain triggers on flutter

Viewed 189

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);},
    )),
1 Answers

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"]}');
Related