How to specify the encoding for a dart Uri in a Flutter project

2,412

You can get the encoding like this:

Encoding.getByName('utf-8')

See also How to render a local HTML file in Flutter

Share:
2,412
Suragch
Author by

Suragch

Read my story here: Programming was my god

Updated on December 10, 2022

Comments

  • Suragch
    Suragch over 1 year

    I am trying to display some static html in an app using the webview_flutter plugin.

    body: WebView(
      initialUrl: Uri.dataFromString(
          htmlString, 
          mimeType: 'text/html', 
          encoding: Encoding('utf-8')
      ).toString(),
    ),
    

    I was getting an error about an invalid character error, and I assumed that is because Uri defaults to ASCII. I am trying to set the character encoding to UTF-8 but I can't figure out how to do it. Encoding('utf-8') is obviously not right.

    How do I set the encoding?