4

I want to use something similar to androids dimens.xml to enforce consistency through out my app.

I was sure Material Design would have some predefined values to use, considering how heavily integrated it is in Flutter, but I cant find anything like it.

Have I just missed it? If not, whats the best approach of implementing it? Just a class holding static variables?

Joel Broström
  • 3,530
  • 1
  • 34
  • 61
  • Sounds like you are looking for https://docs.flutter.io/flutter/material/ThemeData-class.html (https://docs.flutter.io/flutter/material/Theme-class.html). – Günter Zöchbauer Mar 07 '19 at 11:00
  • 2
    Hi again! Not quite. I want to use dimens for padding, margins and fixed sizes by referring to some collection of predefined values. For example, I might want to create a button with `height = dimens.buttonHeight`, `width = demens.buttonWidth`, `padding = dimen.buttonPadding` and `margin = dimen.buttonMargin`. In android development there is a file called `dimens.xml` where you can predefine these (which I'm sure you already know) and I always set it up to follow material designs "rule of 8" (multiple of 8). I figured it might be implemented by default. If not, it could be a nice addition! – Joel Broström Mar 07 '19 at 11:11
  • I did not do any Android development and don't know about that (tried to Google but didn't read much into it), but it still think themes are the closest you get in Flutter. – Günter Zöchbauer Mar 07 '19 at 11:13
  • ThemedData is very confusing and poorly documented. Maybe it's just me. Most importantly, it doesn't have any params for padding, margins or size which is what I'm asking for. Apart from this there is conflicting params that lacks relation information, like primarySwatch/PrimaryColor. There are also arguments in the docs that does not appear in my editor, like appBarTheme. Again, this is probably just me. – Joel Broström Mar 07 '19 at 11:29
  • I think you can create a class with static variables and just import and call it when you need it. – droidBomb Mar 07 '19 at 11:31
  • @droidBomb Yes, it looks like my best bet atm. Can you leave suggestions to the Flutter-team somewhere or do I just open an Issue in the repo? – Joel Broström Mar 07 '19 at 11:34
  • 1
    ThemedData is what is used by all provided material widgets (Cupertino widgets use something similar), so in the end you'd need to create something like that. For your custom widgets you can build something similar yourself. – Günter Zöchbauer Mar 07 '19 at 11:34

1 Answers1

0

Not sure whether this fully answers your question. But there is a new pub package for Android like dimens.xml file. This package is released in Aug 2020.

https://pub.dev/packages/dimens

At the time of writing this, this package only supports Smallest width based (like sw320) categorization of devices. Hope they expand the library to include dencity based categorization as well.

The only other option I can think of right now is to use a static class with constant values.

Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167