【问题标题】:How to handle drawables in a Flutter plugin project如何在 Flutter 插件项目中处理可绘制对象
【发布时间】:2021-06-15 04:06:20
【问题描述】:

我正在尝试创建一个 Flutter 插件。

任何在 Android 端使用可绘制对象的尝试都会失败(未发现异常)。

R.drawable.myicon

或者

context.getResources().getIdentifier("icon", "id", context.getPackageName())

我在 android/src/main/res/drawable 和其他 dpi 特定的可绘制文件夹中都有一个 icon.png 文件。

如何在 Flutter 插件中使用可绘制文件?

谢谢

【问题讨论】:

    标签: android flutter flutter-plugin


    【解决方案1】:

    我傻了,答案是:

    context.getResources().getIdentifier("icon", "drawable", context.getPackageName())
    

    代替

    context.getResources().getIdentifier("icon", "id", context.getPackageName())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-20
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 2021-11-08
      • 2011-03-28
      相关资源
      最近更新 更多