当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Dart IOOverrides用法及代码示例

dart:io 库中IOOverrides 类的用法介绍如下。

使用模拟实现覆盖 dart:io 的各种 API 的工具。

这个抽象基类应该通过重写来扩展构建模拟所需的操作。此基类中的实现默认为实际的dart:io 实现。例如:

class MyDirectory implements Directory {
  ...
  // An implementation of the Directory interface
  ...
}

void main() {
  IOOverrides.runZoned(() {
    ...
    // Operations will use MyDirectory instead of dart:io's Directory
    // implementation whenever Directory is used.
    ...
  }, createDirectory: (String path) => new MyDirectory(path));
}

相关用法


注:本文由纯净天空筛选整理自dart.dev大神的英文原创作品 IOOverrides class。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。