dimens 0.0.6

Dart native
Flutter Android iOS

Android-like dimens generator

dimens #

Android-like dimens generator

Overview #

Dimens allows you to manage dimension resources and text styles.

Usage #

Add dev dependency to your pubspec.yaml.

dev_dependencies:
  dimens: any

Create sizes.json file under assets/sizes directory in your project.

Here you can declare two objects:

  • textStyles for text styles definitions
  • sizes for dimension definitions
{
  "textStyles": {
    "defaultHeadline": "headline6"
  },
  "sizes": {
    "defaultSpacing": 24.0
  }
}

Then you can define another file for particular screen configuration (only smallest width is supported now), like size-sw320.json. You can override some values here, and these values will be used on devices with smallest width larger or equal 320lp.

{
  "textStyles": {
    "defaultHeadline": "headline5"
  },
  "sizes": {
    "defaultSpacing": 32.0
  }
}

Now run flutter pub run dimens. It will generate dimens.g.dart file containing InheritedWidget called Dimens. Just place this widget at the top of your widget tree. Then you can access appropriate for your screen resource like this:

// ...
Widget build(BuildContext) => Container(
  height: Dimens.of(context).defaultSpacing,
);

Command arguments #

Command supports following arguments:

ArgumentAbbreviationTypeDescription
--output-dir-ostringDirectory in which output file will be generated. If not presented file is generated in the root of your project.
--format-fboolSet to true if you want to apply dartfmt to output file. False by default.