'Flutter: Invalid argument: Instance of 'NavigatorUAData' script

Following is the class NavigatorUAData that I'm addding to a script in_app_webview_options.dart script to have userAgentData available and not only the default userAgent.

class NavigatorUAData{
  final List<String> brands;
  final bool mobile;
  final String platform;
  const NavigatorUAData({
    required this.brands,
    required this.mobile,
    required this.platform,
  });
}

Following is an stripped down version of the class InAppWebViewOptions on that script, as I'm trying to show, the userAgent that was there by default, and my new userAgentData.

class InAppWebViewOptions implements WebViewOptions, BrowserOptions, AndroidOptions, IosOptions {
  
  String userAgent;
  NavigatorUAData userAgentData;

  InAppWebViewOptions(
    {
      this.userAgent = "",
      this.userAgentData = const NavigatorUAData(brands: ['Chrome', '91'], mobile: false, platform: 'w'),
    })
  
  @override
  Map<String, dynamic> toMap() {
    return {
      "userAgent": userAgent,
      "userAgentData": userAgentData,
    };
  }

  static InAppWebViewOptions fromMap(Map<String, dynamic> map) {
    InAppWebViewOptions options = InAppWebViewOptions();
    options.userAgent = map["userAgent"];
    options.userAgentData = map["userAgentData"];
    return options;
  }
}

Afterwards, In my main.dart, I'm using the class as:

crossPlatform: InAppWebViewOptions(
        userAgent: "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36",
        userAgentData: const NavigatorUAData(brands: ['Chrome', '91'], mobile: false, platform: 'w'),
        ),

But when running the app, I'm getting this error: [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Invalid argument: Instance of 'NavigatorUAData'

I've been putting consts as the compiler was showing errors like Expected const most of the time.

What do I need to do to sort it out?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source