AssetsGen instal the new version for mac2/21/2024 ![]() String get bee => 'assets/video/bee.mp4' You will have to add the file imports to the relevant layout files: import './gen/' ĭepending on how you named your asset files, a class will be created to read its path string.įor example, if we added a video in the format below, a string class is created and can be accessed: // getter - contains generated code for your font assets.- contains generated code for your image, video, animation, and JSON assets.In this case, since two parsers are specified, assets and fonts, two files are generated for each: This command will generate the files for related assets in the lib/gen folder. Run flutter packages pub run build_runner build in your root app directory. The starter app contains the assets and fonts. Note the types of parsers used, assets, and fonts. asset: assets/fonts/RobotoMono-Italic.ttf asset: assets/fonts/RobotoMono-Bold.ttf asset: assets/fonts/RobotoMono-Regular.ttf ![]() Specify assets in your pubspec.yaml file as shown: flutter: Run the command below in your root app directory to install FlutterGen: $ flutter pub get Use FlutterGen We will install it as part of build_runner.Īdd build_runner and flutter_gen as part of your dev_dependencies in the pubspec.yaml file: dev_dependencies: You can install FlutterGen in several ways: To set up FlutterGen in your app: Install FlutterGen Learn how to get started with FlutterGen next. You can find the final app with the generated code in the FlutterGen branch. You will generate the code for the assets and access them using static variables instead. The assets have been loaded in the app but with path strings. It is good practice to group your assets based on type as shown in the folder structure.īelow is the folder structure and app look: The app has the following assets added under the assets folder in the root directory: To follow along, you can get the starter app here. ![]() When working with assets such as animations, FlutterGen offers the following integrations: Colors - this configuration generates the file under lib/gen.Fonts - this configuration generates the file under lib/gen.Assets - this configuration generates the file under lib/gen.The following are available parsers you can configure: You can then load your assets using the classes generated.FlutterGen will then generate the related Dart files under the lib/gen directory by default. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |