Baishun's Space

Tips on handling submodules(packages)

By Baishun on Mar 20, 2024
flutter packages

Summary

as our flutter packages grow up, we need to split them into different packages, but some thing we need to handle, today we will talk about these things.

Assets

you can keep your assets in different packages, just notice when to use these assets, you cannot just do like in the main app:

image: DecorationImage(
  image:
      AssetImage("assets/background/main.jpg"),// this will be an error(if you dont copy the image to your main assets folder)
  fit: BoxFit.cover,
),

you should add the package name to the assets path like this:

image: DecorationImage(
  image:
      AssetImage("packages/yes_or_no/assets/background/main.jpg"),
  fit: BoxFit.cover,
),

Localization

To use localization in Flutter sub package is almost the same as use it in main package, just we need to take care of the location of generated class.

The main steps is here Flutter - how to set localization in sub packages

For business cooperation or you have any questions, please send email to : lecy.cc.app@gmail.com
© Copyright 2024 by Baishun Space. Built with ♥ by Lecy. Origin theme of this blog is from ixartz. Social Icons are copied from astro-social-share