Flutter 6 个建议改善你的代码结构

1,720 阅读1分钟

原文

itnext.io/5-flutter-t…

正文

1. 将 init 操作与 main 函数分离,使其更加清晰

2. 你可以简单地管理这样的 GetX 路由,而不需要任何麻烦

  • 用法
Get.toNamed(Routes.login);
  • 怎么做

3. 你也可以在一个地方管理你的样式风格

  • 用法
// S stands for Styles

S.colors.red
S.textStyles.f10Medium
S.shadows.softShadow
  • 怎么做

4. 像 boss 一样管理你的资源

  • 用法
// R stands for Resources// Animations

R.anims.loading// SVG images
R.icons.logo// `mages
R.images.
  • 怎么做

5. 集中管理你的常量

  • 用法
// C stands for Constants

C.title
C.names
C.descp
  • 怎么做

6. 建立你的工具类 utils,我们在一个地方使用所有的时间

  • 用法
Utils.formatDate(date,locale);

Utils.formatters.onlyTwoDecimalDigits;

Utils.show.dialog();
  • 怎么做


© 猫哥