Giter Site home page Giter Site logo

flr-as-plugin's Introduction

Flr Plugin

java jetbrains plugin version jetbrains plugin downloads

Flr (Flutter-R) Plugin: A Flutter Resource Manager Android Studio Plugin, which can help flutter developer to auto specify assets in pubspec.yaml and generate r.g.dart file after he changes the flutter project assets. With r.g.dart, flutter developer can apply the asset in code by referencing it's asset ID function.

Flr Usage Example

๐Ÿ“– Read this in other languages: English, ็ฎ€ไฝ“ไธญๆ–‡

Feature

  • Support auto service that automatically specify assets in pubspec.yaml and generate r.g.dart file, which can be triggered manually or by monitoring asset changes

  • Support R.x (such as R.image.test(), R.svg.test(width: 100, height: 100), R.txt.test_json()) code struct

  • Support for processing image assets ( .png, .jpg, .jpeg, .gif, .webp, .icon, .bmp, .wbmp, .svg )

  • Support for processing text assets ( .txt, .json, .yaml, .xml )

  • Support for processing font assets ( .ttf, .otf, .ttc)

  • Support for processing image asset variants

  • Support for processing asset whichโ€™s filename is bad:

    • filename has illegal character (such as blank, ~, @, # ) which is outside the range of valid characters (0-9, A-Z, a-z, _, +, -, ., ยท, !, @, &, $, ๏ฟฅ)
    • filename begins with a number or character _ or character$
  • Support for processing assets with the same filename but different path

Install Flr plugin

Use the IDE's plugin manager to install the latest version of the plugin:

Preferences > Plugins > Marketplace > Search for "Flr" > Install Plugin

Install Flr

Usage

  1. Init your flutter project: Click Tools > Flr > Init

    The Flr Init action will check to see if the current project is a legal flutter project, add flr configuration and dependency r_dart_library into pubspec.yaml.

    Attention:

    The Flutter SDK is currently in an unstable state, so if you get a build error of r_dart_library , you can fix it by modify the dependent version of r_dart_library.

    You can select the correct version of r_dart_library based on this dependency relationship table.

  2. Open pubspec.yaml file, find the configuration item for Flr, and then configure the resource directory that needs to be scanned by Flr, such as:

    flr:
      core_version: 1.0.0
      # just use for flr-cli and flr-vscode-extension
      dartfmt_line_length: 80
      # config the image and text resource directories that need to be scanned
      assets:
        - lib/assets/images
        - lib/assets/texts
      # config the font resource directories that need to be scanned
      fonts:
        - lib/assets/fonts
  3. Scan assets, specify assets, and generate r.g.dart: Click Tools > Flr > Generate

    After invoke Flr Generate action, Flr will scan the resource directories configured in pubspec.yaml, then specify scanned assets in pubspec.yaml, and generate r.g.dart file.

    If you want Flr to do the above operations automatically every time a asset changes, you can invoke Flr Start Monitor action. (Click Tools > Flr > Start Monitor ) Then Flr will launche a monitoring service that continuously monitors resource directories configured in pubspec.yaml. If the service detects any asset changes, Flr will automatically scan the asset directories, then specify scanned assets in pubspec.yaml, and generate "r.g.dart" file.

    You can terminate this monitoring service by invoke Flr Stop Monitor action. (Click Tools > Flr > Stop Monitor )

Recommended Flutter Resource Structure

Flr the following flutter resource structure schemes:

  • scheme 1:

    flutter_project_root_dir
    โ”œโ”€โ”€ build
    โ”‚   โ”œโ”€โ”€ ..
    โ”œโ”€โ”€ lib
    โ”‚   โ”œโ”€โ”€ assets
    โ”‚   โ”‚   โ”œโ”€โ”€ images // image resource directory of all modules
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{module} // image resource directory of a module
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{main_image_asset}
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{variant-dir} // image resource directory of a variant
    โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{image_asset_variant}
    โ”‚   โ”‚   โ”‚   โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ home // image resource directory of home module
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ home_badge.svg
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ home_icon.png
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ 3.0x // image resource directory of a 3.0x-ratio-variant
    โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ home_icon.png
    โ”‚   โ”‚   โ”‚   โ”‚		
    โ”‚   โ”‚   โ”œโ”€โ”€ texts // text resource directory
    โ”‚   โ”‚   โ”‚   โ”‚     // (you can also break it down further by module)
    โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ test.json
    โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ test.yaml
    โ”‚   โ”‚   โ”‚   โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ fonts // font resource directory of all font-families
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{font-family} // font resource directory of a font-family
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{font-family}-#{font_weight_or_style}.ttf
    โ”‚   โ”‚   โ”‚   โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri // font resource directory of Amiri font-family
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri-Regular.ttf
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri-Bold.ttf
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri-Italic.ttf
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri-BoldItalic.ttf
    โ”‚   โ”œโ”€โ”€ ..
    
    
  • scheme 2:

    flutter_project_root_dir
    โ”œโ”€โ”€ build
    โ”‚   โ”œโ”€โ”€ ..
    โ”œโ”€โ”€ lib
    โ”‚   โ”œโ”€โ”€ ..
    โ”œโ”€โ”€ assets
    โ”‚   โ”œโ”€โ”€ images // image resource directory of all modules
    โ”‚   โ”‚   โ”œโ”€โ”€ #{module} // image resource directory of a module
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{main_image_asset}
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{variant-dir} // image resource directory of a variant
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{image_asset_variant}
    โ”‚   โ”‚   โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ home // image resource directory of home module
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ home_badge.svg
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ home_icon.png
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ 3.0x // image resource directory of a 3.0x-ratio-variant
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ home_icon.png
    โ”‚   โ”‚   โ”‚		
    โ”‚   โ”œโ”€โ”€ texts // text resource directory
    โ”‚   โ”‚   โ”‚     // (you can also break it down further by module)
    โ”‚   โ”‚   โ””โ”€โ”€ test.json
    โ”‚   โ”‚   โ””โ”€โ”€ test.yaml
    โ”‚   โ”‚   โ”‚
    โ”‚   โ”œโ”€โ”€ fonts // font resource directory of all font-families
    โ”‚   โ”‚   โ”œโ”€โ”€ #{font-family} // font resource directory of a font-family
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ #{font-family}-#{font_weight_or_style}.ttf
    โ”‚   โ”‚   โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ Amiri // font resource directory of Amiri font-family
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri-Regular.ttf
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri-Bold.ttf
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri-Italic.ttf
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Amiri-BoldItalic.ttf
    โ”‚   โ”œโ”€โ”€ ..
    
    

Big Attention, the resource structure in the root directory of the font resource MUST follow the structure described above: name the subdirectory with a font family name, and place the font resources of the font family in the subdirectory. Otherwise, Flr may not scan the font resource correctly.

r.g.dart

After you invoke Flr Generate action or Flr Start Monitor action, Flr will scan the asset directories configured in pubspec.yaml, then specify scanned assets in pubspec.yaml, and generate r.g.dart file.

r.g.dart defines a asset access interface class: R, which allows flutter developer to apply the asset in code by referencing it's asset ID function, such as:

import 'package:flutter_r_demo/r.g.dart';

// test_sameName.png
var normalImageWidget = Image(
  width: 200,
  height: 120,
  image: R.image.test_sameName(),
);

// test_sameName.gif
var gifImageWidget = Image(
  image: R.mage.test_sameName_gif(),
);

// test.svg
var svgImageWidget = Image(
  width: 100,
  height: 100,
  image: R.svg.test(width: 100, height: 100),
);

// test.json
var jsonString = await R.text.test_json();

// test.yaml
var yamlString = await R.text.test_yaml();

// Amiri Font Style
var amiriTextStyle = TextStyle(fontFamily: R.fontFamily.amiri);

_R_X class

r.g.dart defines several private _R_X asset management classes: _R_Image, _R_Svg, _R_Text, _R_FontFamily. These private asset management classes are used to manage the asset IDs of the respective asset types:

  • _R_Image: manage the asset IDs of non-svg type image assets ( .png, .jpg, .jpeg, .gif, .webp, .icon, .bmp, .wbmp )
  • _R_Svg: manage the asset IDs of svg type image assets
  • _R_Text: manage the asset IDs of text assets ( .txt, .json, .yaml, .xml )
  • _R_FontFamily: manage the asset IDs of font assets ( .ttf, .otf, .ttc)

R class and R.x struct

r.g.dart defines a asset access interface class: R, which is used to manage common information, aggregate the _R_X asset management classes, and implement R.x code struct:

/// This `R` class is generated and contains references to static asset resources.
class R {
  /// package name: flutter_r_demo
  static const package = "flutter_r_demo";

  /// This `R.image` struct is generated, and contains static references to static non-svg type image asset resources.
  static const image = _R_Image();

  /// This `R.svg` struct is generated, and contains static references to static svg type image asset resources.
  static const svg = _R_Svg();

  /// This `R.text` struct is generated, and contains static references to static text asset resources.
  static const text = _R_Text();
}

  /// This `R.fontFamily` struct is generated, and contains static references to static font resources.
  static const fontFamily = _R_FontFamily();
}

Example

Here are some example demos to show how to use Flr tool in flutter project and show how to use R class in your code:

License

The plugin is available as open source under the terms of the MIT License.

flr-as-plugin's People

Contributors

yk-unit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flr-as-plugin's Issues

Be less controlling of pubspec.yaml

Hi,

love using your plugin, it does exactly what I wanted.
My only complaint so far is that every time it generates, it totally messes up my pubspec.yaml in unnecessary ways:

  1. deletes all my comments;
  2. deletes all my empty line;
  3. assets are kept at the wrong indent, should be 2 spaces further to the right;
  4. it writes every resource to pubspec.yaml, when it should be enough to write the folders;

Thanks alot,
regards,

Please add support for null-safety

Hi:

This plugin is wonderful, but when I updated my project to flutter 2.0, like this below:

environment:
  sdk: '>=2.12.0 <3.0.0'

r.g.dart reported some errors for null-safety . So, could you please add support for null-safety?

thanks a lot.

Flr plugin ๆ— ๆณ•ไธ‹่ฝฝ

Flr plugin ๅœจ Android Studio Plugin Marketๆฃ€็ดขไธๅˆฐใ€‚ไปŽๅฎ˜็ฝ‘ๅฏไปฅๆ‰พๅˆฐๆ’ไปถ๏ผŒไฝ†ๆ˜ฏไธ‹่ฝฝไธ‹ๆฅไปŽๆœฌๅœฐๅฏผๅ…ฅๆŠฅ้”™ใ€‚

image
image

ไธๆ”ฏๆŒๅคšๆจกๅ—

ๆฏ”ๅฆ‚flutterๆจกๅ—Aไพ่ต–flutterๆจกๅ—B๏ผŒBๆจกๅ—assets็›ฎๅฝ•ไธ‹ๆœ‰่ต„ๆบๆ–‡ไปถ๏ผŒๅœจBๆจกๅ—็š„pubspec.yamlไธญๅขžๅŠ ๅฏนr_dart_library็š„ไพ่ต–๏ผŒๅฆ‚ๆžœstudioๆ‰“ๅผ€Aๆจกๅ—๏ผŒๆˆ‘ๅ‘็ŽฐBๆจกๅ—ๆ— ๆณ•็”Ÿๆˆr.dartๆ–‡ไปถ๏ผŒๅฆ‚ๆžœstudioๆ‰“ๅผ€Bๆจกๅ—๏ผŒๅฏไปฅ็”Ÿๆˆr.dartๆ–‡ไปถ๏ผŒไฝ†ๆ˜ฏpubspec.yamlๆฒกๆœ‰ๆทปๅŠ ๅฏนassetsไธ‹้ข่ต„ๆบๆ–‡ไปถ็š„ๅผ•็”จ

ๅผ€ๅฏ็›‘ๆต‹๏ผŒ็ฒ˜่ดด็š„ๆ–‡ไปถๅ˜ๅŠจๆ— ๆณ•ๆฃ€ๆต‹ๅˆฐๅ—๏ผŸ

้—ฎ้ข˜ๆ่ฟฐ๏ผš
ๆˆ‘ๅผ€ๅฏไบ†่‡ชๅŠจๆฃ€ๆต‹่ฟ™ไธชๅŠŸ่ƒฝ๏ผŒไฝ†ๆ˜ฏcopyๅ›พ็‰‡ ็ฒ˜่ดดๅˆฐ assets ้‡Œๆฒกๆœ‰่‡ชๅŠจไฟฎๆ”น yaml ๆ–‡ไปถใ€‚ไฝ†ๆ˜ฏๅœจ่ฏฅ็›ฎๅฝ•้‡Œ ๆ–ฐๅปบๆ–‡ไปถๆ˜ฏๅฏไปฅ็š„๏ผŒ่ฏท้—ฎๆ˜ฏไธๆ”ฏๆŒๅ—๏ผŸ

็Žฏๅขƒ๏ผš
macOS็‰ˆๆœฌ๏ผš
image

Android studio ็‰ˆๆœฌ๏ผš4.1.3
Flutter็‰ˆๆœฌ๏ผš2.2.2
Dart็‰ˆๆœฌ๏ผš2.13.3

Flr ๆ’ไปถ็‰ˆๆœฌ๏ผš201.3.3.1

ๆŽงๅˆถๅฐ่พ“ๅ‡บ๏ผš
image

need update

As ๆœ€ๆ–ฐ็‰ˆๆœฌ่ฏทๆ”ฏๆŒไธ€ไธ‹

ๆ‰“ๅผ€้žflutterๅทฅ็จ‹๏ผŒๆ’ไปถไผšๆŠฅ้”™

andoridstudio 4.2.1
ๆœ€ๆ–ฐ็‰ˆๆœฌ็š„ๆ’ไปถ
ๆ‰“ๅผ€flutterๅทฅ็จ‹ๆฒก้—ฎ้ข˜๏ผŒๆ‰“ๅผ€androidๅทฅ็จ‹ไผšๆŠฅ้”™

Plugin 'com.fly-mix.flr' failed to initialize and will be disabled.  Please restart Android Studio.

java.lang.NullPointerException
    at com.flr.command.FlrCommand.initFlagOfShouldSupportNullsafety(FlrCommand.java:67)
    at com.flr.command.FlrCommand.<init>(FlrCommand.java:61)
    at com.flr.FlrApp.<init>(FlrApp.java:14)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at com.intellij.serviceContainer.ConstructorInjectionKt.instantiateUsingPicoContainer(constructorInjection.kt:52)
    at com.intellij.serviceContainer.ComponentManagerImpl.instantiateClassWithConstructorInjection(ComponentManagerImpl.kt:664)
    at com.intellij.serviceContainer.MyComponentAdapter.doCreateInstance(MyComponentAdapter.kt:35)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstanceUncached(BaseComponentAdapter.kt:113)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstance(BaseComponentAdapter.kt:67)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstance$default(BaseComponentAdapter.kt:60)
    at com.intellij.serviceContainer.ComponentManagerImpl.createComponents(ComponentManagerImpl.kt:260)
    at com.intellij.openapi.project.impl.ProjectImpl.init(ProjectImpl.java:110)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.initProject(ProjectManagerImpl.java:177)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl.prepareProject(ProjectManagerExImpl.kt:221)
    at com.intellij.openapi.project.impl.ProjectManagerExI

Messing up with fonts declaration

@YK-Unit This is a great plugin really appreciate your team efforts. But actually its messing up with my fonts declaration. So am unable to use it. Can you please address that!

image

image

Am using latest stable android studio & latest flutter SDK version

image

image

ๅช’ไฝ“ๆ–‡ไปถๅฆ‚ไฝ•ๆทปๅŠ ๅˆฐassetsไธญ

Flrๅพˆๅฅฝ็”จ๏ผŒ่Š‚็œไบ†ๅพˆๅคšๆžฏ็‡ฅ็š„ๆ“ไฝœ๏ผŒๆœ€้‡่ฆ็š„ๆ˜ฏ็”จไธ€ไบ›่ต„ๆบๆ—ถ๏ผŒ็ปˆไบŽๆœ‰ๆ็คบไบ†

ๆˆ‘ๆƒณ็Ÿฅ้“ๅฏนไบŽFlr็Žฐๅœจไธๆ”ฏๆŒ็š„ๆ–‡ไปถ็ฑปๅž‹๏ผŒๆฏ”ๅฆ‚้Ÿณไนๆˆ–่€…่ง†้ข‘ๆ–‡ไปถ๏ผŒๆˆ‘่ฏฅๅฆ‚ไฝ•ๆทปๅŠ ๅˆฐassetsไธญ

ๆˆ‘ๅนถไธ้œ€่ฆFlrๆ”ฏๆŒ่ฟ™ไบ›็ฑปๅž‹๏ผŒๅ› ไธบๆ•ฐ้‡ๅพˆๅฐ๏ผŒไฝ†ๆˆ‘ไธ€ๆ—ฆๆ‰‹ๅŠจๆทปๅŠ ๅˆฐassetsไธญ๏ผŒไป–ๅฐฑไผš่ขซ่‡ชๅŠจ็”Ÿๆˆ็š„ไปฃ็ ่ฆ†็›–๏ผŒๆˆ‘็œ‹ไบ†ๆ–‡ๆกฃๅ’Œ็คบไพ‹๏ผŒ้ƒฝๆฒกๆœ‰่งฃๅ†ณๆ–นๆกˆใ€‚ๅปบ่ฎฎๅœจflr็š„้…็ฝฎ้‡ŒๅŠ ไธŠไธ€ไธช่‡ชๅฎšไน‰assets๏ผŒ็”Ÿๆˆไปฃ็ ๆ—ถ๏ผŒๅช้œ€่ฆๅฐ†่‡ชๅฎšไน‰้‡Œ็š„่ทฏๅพ„ๅŽŸๅฐไธๅŠจ็š„ๆฌ่ฟ‡ๅŽปๅฐฑๅฏไปฅใ€‚

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.