Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1K
Views
Flutter webview_flutter_plus webview error Uncaught ReferenceError: function is not defined

I am using webview_flutter_plus with flutter and using local files from assets folder. Page is loading fine but sometimes (every now and then), I keep getting below error in console even though I have setUserData() function setup in js file. Surprisingly sometimes it works and prints through js file.

I/chromium( 7190): [INFO:CONSOLE(1)] "Uncaught ReferenceError: setUserData is not defined", source: http://localhost:42369/assets/html/home.html (1)

Function in js file:

function setUserData(json) {
    console.log(json);
}

First I load data from SQFLite and display on webpage. After that if device is online, app downloads data from online server and updates SQFLite. Below is the dart file:

late WebViewPlusController _webViewPlusController;
Timer? timer;
bool _webViewInitialized = false;

void _checkIfWebViewInitialized(){
    timer = Timer.periodic(const Duration(seconds: 1), (Timer t) {
        if(_webViewInitialized){
            timer?.cancel();
            _getSqliteDetails();
        }
    });
}

Future<void> _getSqliteDetails() async {
    final userDetails = Map.of(await UserProfileCrud.getUserDetailsByDisplayId(1917));
    if(userDetails.isNotEmpty) {
        userDetails['status'] = 'Success';
        final encodedUserData = convert.jsonEncode(userDetails);

        _webViewPlusController.webViewController.runJavascript("setUserData('$encodedUserData')");
    }
    // Check Online Server Data
}

@override
Widget build(BuildContext context) {
    return Scaffold(
        body: WebViewPlus(
            javascriptMode: JavascriptMode.unrestricted,
            initialUrl: 'assets/html/home.html',
            onWebViewCreated: (controller){
                _webViewPlusController = controller;
                //CookieManager().clearCookies();
                setState((){
                    _webViewInitialized = true;
                });
            },
        ),
    );
}

Is there any other way to it that I am unaware of? Kindly help as new to flutter.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!