micha_core 0.0.1
micha_core: ^0.0.1 copied to clipboard
Extensions and widgets that are missing in Flutter's SDK.
Extensions and widgets that are missing in Flutter's SDK.
Features #
- Declarative extensions to avoid loops and imperative logic.
- Useful widgets, like a
Gapwidget to avoid the use ofPadding.
Usage #
Separate items of collections #
Need to add some items between existing items of a List or Iterable? Use collection.separated(separator):
[1, 2, 3].separated(0); // [1, 0, 2, 0, 3]
Are these separators dependent on preceding and succeeding items? Use collection.separatedBy((before, after) => separator):
[1, 2, 3].separatedBy((before, after) => before + after); // [1, 3, 2, 5, 3]
Gap #
We often require some small space between widgets. Flutter's widget catalog has limited options:
- Flutter's
Spacertakes up all available space, which is often more than we want. - Flutter's
Paddingunfortunately needs to be wrapped around widgets, adding boilerplate, while also being hard to read inside of lists. - The best that Flutter offers is a
SizedBoxwith a specifiedwidthorheight.
However, this still has some problems: We need to set eitherwidthorheight, depending on whether theSizedBoxis placed inside aRoworColumn.
We also need to repeat the same constant pixel size all throughout the application.
Instead, consider using a Gap:
@override
Widget build(BuildContext context) {
return Column(
children: [
Text('first'),
Gap(),
Text('second'),
],
);
}
Gap takes up a fixed space of 16 pixels in both directions.
When you need a little more or a little less space, just multiply or divide the Gap, like Gap() * 2 or Gap() / 2.
StyledText #
Avoid accessing ThemeData manually to set a themed textStyle. Use a StyledText widget instead:
return StyledText.headlineMedium('Some headline');