twitter facebook

【Flutter】Undefined name 'rootBundle'. Try correcting the name to one that is defined

final html = await rootBundle.loadString('assets/index.html');
final uri = Uri.dataFromString(
  html,
  mimeType: 'text/html',
  encoding: Encoding.getByName('utf-8'),
);
flutter で ローカルHTML を読み込む際などに使用する rootBundle.loadString で下記のようなエラーが出た場合
Undefined name 'rootBundle'. Try correcting the name to one that is defined, or defining the name.
以下でエラー解除されます。
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter/services.dart' show rootBundle;
    
// 省略
final html = await rootBundle.loadString('assets/index.html');
final uri = Uri.dataFromString(
  html,
  mimeType: 'text/html',
  encoding: Encoding.getByName('utf-8'),
);
AUTHOR
@えのえの
最終更新日 2024/11/12
FAVORITE good stock
LINK TAG
記法を見る
1732369004