loadString method

  1. @override
Future<String> loadString(
  1. String path
)
override

读一份文本资产。

读不到时抛 HyperlensAssetException(核心资产:模板 / marked / purify / 主题 CSS)或由调用方降级(增强资产:KaTeX / Mermaid / mhchem)—— 分级见 README。

Implementation

@override
Future<String> loadString(String path) async {
  try {
    return await rootBundle.loadString(path);
  } on FlutterError catch (error) {
    // 资产没打进包(pubspec 漏了 `flutter: assets:` 或发布产物不全)时
    // rootBundle 抛的是 FlutterError —— 换成自己的类型,调用方好分级处理。
    throw HyperlensAssetException(path, error);
  }
}