getResource method

Future<Image> getResource(
  1. String materialVariety, {
  2. required String directory,
  3. required String extension,
})

Default asset-path based resource loader.

Host apps should generally prefer passing BoardThemeConfig.pieceImageProvider instead of relying on this method.

Implementation

Future<Image> getResource(
  String materialVariety, {
  required String directory,
  required String extension,
}) async {
  bool sameFolderForBothColors =
      materialsResources[materialVariety] is List<String>;
  String path =
      '$directory/$materialVariety/${sameFolderForBothColors ? '' : '${color.name}/'}${type.name}.$extension';

  return Image.asset(
    path,
    color: sameFolderForBothColors ? color.toColor() : null,
    fit: BoxFit.contain,
  );
}