AdobeXD / xd-to-flutter-plugin

Generate assets from XD for use in an existing Flutter project
BSD 2-Clause "Simplified" License
950 stars 96 forks source link

Export an image assets lookup file #22

Open amreniouinnovent opened 4 years ago

amreniouinnovent commented 4 years ago

I have used spider plugin for generating images from folder I think it would be helpful to use it or making a similar grouping for images https://pub.dev/packages/spider

gskinner commented 4 years ago

Good idea. We could easily export something similar to the Color Assets file we currently generate.

class XDImages {
  static const String background = 'assets/background.png';
}

I want to be careful about cluttering our UI with "one off" features, but would love to hear (even just thumbs ups) if people would find this useful.

cyrsis commented 4 years ago

Emm..interesting..

The way I solve it to export it in my XD plug in

cmd + option + k

then use Dart to pull the asset into the dir

import 'dart:io';

import 'package:path/path.dart';
import 'package:watcher/watcher.dart';

main(List<String> arguments) {
//  if (arguments.length != 1) {
//    print("Usage: watch <directory path>");
//    return;
//  }

//  var watcher = DirectoryWatcher(p.absolute(arguments[0]));
  var watcher = DirectoryWatcher(
      "/var/folders/fc/xmsxx52n5f37q18t3ppy7tyh0000gp/T/B8356C59-3925-466E-81F4-07D3AB65DE33/bb7d71ec/");
  watcher.events.listen((event) async {
    print(event);
    if (event.type == ChangeType.ADD) {
      print("The path is ${event.path}");
      var filename = basename(event.path);
      print("File name is ${filename}");
      await moveFile(File(event.path),
          "/Users/victor/Documents/Dev/fluttersandbox2018/assets/arupvisitor/${filename}");
    }
  });
}

Future<File> moveFile(File sourceFile, String newPath) async {
  try {
    // prefer using rename as it is probably faster
    return await sourceFile.rename(newPath);
  } on FileSystemException catch (e) {
    // if rename fails, copy the source file and then delete it
    final newFile = await sourceFile.copy(newPath);
    await sourceFile.delete();
    return newFile;
  }
}