flutter_gen icon indicating copy to clipboard operation
flutter_gen copied to clipboard

Support arbitrary files

Open shilangyu opened this issue 4 years ago • 3 comments

Sometimes I have assets that are not on the list of supported extensions but I would still like to have strings generated for them. At the moment flutter_gen just ignores these files and generates no strings for them.

Example:

For the following snippet from pubspec.yaml:

flutter:
  assets:
    - CHANGELOG.md

I would expect to have a string generated for CHANGLELOG.md to avoid using hardcoded strings in my code to reference this asset.

shilangyu avatar Dec 18 '20 16:12 shilangyu

@shilangyu

Thank you for using the FlutterGen. Recently, We fixed the bug by 1.3.0 and 1.3.1.

So please upgrade to 1.3.1+.

$ brew upgrade fluttergen/tap/fluttergen

or

$ dart pub global activate flutter_gen

And just now I add some arbitrary files to sample settings.

https://github.com/FlutterGen/flutter_gen/commit/3cd380eda1c72a3406f62c91237e61293fb92fac

wasabeef avatar Dec 18 '20 17:12 wasabeef

But this means I need to have my files in a specific folder? For example my changelog.md file is in the root of the project, and the string is not generated for it (as in the example from my initial comment)

shilangyu avatar Dec 18 '20 17:12 shilangyu

The quick workaround using rootBundle:

import 'package:flutter/services.dart' show rootBundle;

FutureBuilder(
  future: rootBundle.loadString('CHANGELOG.md'),
  builder: (context, data) {
    if (!data.hasData) {
      return Container();
    }
    return Markdown(
      data: data.data!,
    );
  }
)

Tienisto avatar Dec 28 '22 00:12 Tienisto