【问题标题】:Create flutter library to support both web and mobile创建 Flutter 库以同时支持 Web 和移动设备
【发布时间】:2020-02-11 19:53:47
【问题描述】:

我需要创建一个实现数据持久性的库,该库应该可以跨移动设备和 Web 工作。对于网络,我需要import 'dart:html',对于移动设备,我会使用共享首选项。

问题是,如果“dart:html”被导入,该项目将无法针对移动设备进行编译。有没有办法解决这个问题?也许我可以有条件导入?

【问题讨论】:

    标签: flutter dart flutter-dependencies dart-html flutter-web


    【解决方案1】:

    可以通过判断加载不同的handler ?(我支持你写这个库)

    import '_network_image_io.dart' if (dart.library.html) '_network_image_web.dart' as network_image;
    

    【讨论】:

    • 非常感谢。一旦我找到一些空闲时间,我很想围绕这个写一个包。
    猜你喜欢
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 2012-12-27
    • 1970-01-01
    相关资源
    最近更新 更多