assorted_layout_widgets 1.0.14

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

pub package

assorted_layout_widgets #

Widgets in this package:

  • ColumnSuper
  • RowSuper
  • FitHorizontally
  • Box
  • TextOneLine

I will slowly but surely add interesting widgets to this package.

ColumnSuper #

Given a list of children widgets, this will arrange them in a column. It can overlap cells, add separators and more.

ColumnSuper({  
    List<Widget> children,    
    double outerDistance,
    double innerDistance,
    bool invert,
    Alignment alignment,
    Widget separator,
    bool separatorOnTop,
  });

  • children is the list of widgets that represent the column cells, just like in a regular Column widget. However, the list may contain nulls, which will be ignored.

  • outerDistance is the distance in pixels before the first and after the last widget. It can be negative, in which case the cells will overflow the column.

  • innerDistance is the distance in pixels between the cells. It can be negative, in which case the cells will overlap.

  • invert if true will paint the cells that come later on top of the ones that came before. This is specially useful when cells overlap (negative innerDistance).

  • alignment will align the cells horizontally if they are smaller than the available horizontal space.

  • separator is a widget which will be put between each cells. Its height doesn't matter, since the distance between cells is given by innerDistance (in other words, separators don't occupy space). The separator will overflow if its width is larger than the column's width.

  • separatorOnTop if true (the default) will paint the separator on top of the cells. If false will paint the separator below the cells.

Note: This is not a substitute for Flutter's native Column, it doesn't try to have a similar API, and it doesn't do all that Column does. In special, Expanded and Flexible widget don't work inside of ColumnSuper, and it will overflow if the column is not big enough to fit its contents. ColumnSuper is meant only to certain use cases where Column won't work, like when you need overlapping cells.

Try running the ColumnSuper example.

RowSuper #

Given a list of children widgets, this will arrange them in a row. It can overlap cells, add separators and more.

RowSuper({  
    List<Widget> children,    
    double outerDistance,
    double innerDistance,
    bool invert,
    Alignment alignment,
    Widget separator,
    bool separatorOnTop,
    bool fitHorizontally,
    double shrinkLimit,
    MainAxisSize mainAxisSize,
  });

On contrary to ColumnSuper and the native Row (which will overflow if the cells are not big enough to fit their content), RowSuper will resize its cells, proportionately to the width of the minimum intrinsic width of each cell content.

Try running the RowSuper example.

Most parameters are the same as the ones of ColumnSuper, except:

  • fitHorizontally if true will resize the cells content, horizontally only, until the shrinkLimit is reached.

  • shrinkLimit by default is 67%, which means the cell contents will shrink until 67% of their original width, and then overflow. Make shrinkLimit equal to 0.0 if you want the cell contents to shrink with no limits. Note, if fitHorizontally is false, the shrinkLimit is not used.

  • mainAxisSize by default is MainAxisSize.min, which means the row will occupy no more than its content's width. Make it MainAxisSize.max to expand the row to occupy the whole horizontal space.

You can also use a RowSpacer to add empty space (if available) between cells. For example:

RowSuper(
   children: [
      widget1, 
      RowSpacer(), 
      widget2, 
      widget3,
      ]
   )
);   

Try running the RowSuper with FitHorizontally example.

Note: This is not a substitute for Flutter's native Row, it doesn't try to have a similar API, and it doesn't do all that Row does. In special, Expanded and Flexible widget don't work inside of RowSuper, since RowSuper will resize cells proportionately when content doesn't fit. RowSuper is meant only to certain use cases where Row won't work, like when you need overlapping cells, or when you need to scale the contents of the cells when they don't fit.

FitHorizontally #

FitHorizontally({
    Widget child,  
    double shrinkLimit,
    bool fitsHeight,
    AlignmentGeometry alignment,
  });

The child will be asked to define its own intrinsic height. If fitsHeight is true, the child will be proportionately resized (keeping its aspect ratio) to fit the available height.

Then, if the child doesn't fit the width, it will be shrinked horizontally only (not keeping its aspect ratio) until it fits, unless shrinkLimit is larger than zero, in which case it will shrink only until that limit. Note if shrinkLimit is 1.0 the child will not shrink at all. The default is 0.67 (67%).

This is specially useful for text that is displayed in a single line. When text doesn't fit the container it will shrink only horizontally, until it reaches the shrink limit. From that point on it will clip, display ellipsis or fade, according to the text's Text.overflow property.

Note: FitHorizontally with shrinkLimit 0.0 is not the same as FittedBox with BoxFit.fitWidth, because FitHorizontally will only scale horizontally, while FittedBox will maintain the aspect ratio.

Try running the FitHorizontally example.

Box #

Box is something between a Container and a SizedBox, which is less verbose and can be made const.

const Box({
    bool show,
    Color color,
    double top,
    double right,
    double bottom,
    double left,
    double width,
    double height,
    Alignment alignment,
    Widget child,
  });

Since it can be made const, it's good for creating colored boxes, with or without a child and padding:

const Box(color: Colors.red, width: 50, height:30);

The padding is given by top, right, bottom and left values, but they are only applied if the child is not null. If the child, width and height are all null, this means the box will occupy no space (will be hidden). Note: This will be extended in the future, so that it ignores horizontal padding when the child has zero width, and ignores vertical padding when the child has zero height.

You can also hide the box by making the show parameter equal to false.

Debugging: #

  • If need to quickly and temporarily add a color to your box so that you can see it, you can use the constructors Box.r for red, Box.g for green, Box.b for blue, and Box.y for yellow.

    Box(child: myChild);
    Box.r(child: myChild);
    Box.g(child: myChild);
    Box.b(child: myChild);
    Box.y(child: myChild);
    
  • If you want to see rebuilds, you can use the Box.rand constructor. It will then change its color to a random one, whenever its build method is called.

    Box.rand(child: myChild);  
    

TextOneLine #

TextOneLine is a substitute for Text when maxLines: 1, to fix this issue: https://github.com/flutter/flutter/issues/18761 filled by myself a long time ago.

It uses a special fade-with-ellipsis, which is much better than the current buggy and ugly-looking ellipsis-that-cuts-the-whole-word.

For example, this:

Text("This isAVeryLongWordToDemonstrateAProblem", maxLines: 1, softWrap: false);  

Will print this in the screen:

This ...  

While this:

TextOneLine("This isAVeryLongWordToDemonstrateAProblem");  

Will print this:

This isAVeryLongWordToDemonst...  

This widget probably only makes sense while that issue is not fixed.

AlignPositioned #

See package align_positioned for widgets AlignPositioned and its siblings AnimatedAlignPositioned and AnimChain. They should be part of this package, but will remain in their own package for historical reasons.


The Flutter packages I've authored:


Marcelo Glasberg:
https://github.com/marcglasberg
https://twitter.com/glasbergmarcelo
https://stackoverflow.com/users/3411681/marcg
https://medium.com/@marcglasberg

[1.0.13] - 2019/12/11

[1.0.13] - 2019/12/04

  • Alignment fix.

[1.0.12] - 2019/11/27

  • Box.

[1.0.10] - 2019/11/25

  • FitHorizontally.
  • RowSpacer.

[1.0.0] - 2019/11/24

  • RowSuper and ColumnSuper.

example/README.md

Examples #

  1. ColumnSuper Example

  2. RowSuper Example

  3. FitHorizontally Example

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  assorted_layout_widgets: ^1.0.14

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:assorted_layout_widgets/assorted_layout_widgets.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/src/fit_horizontally.dart. (-0.50 points)

Analysis of lib/src/fit_horizontally.dart reported 1 hint:

line 378 col 5: Avoid using unnecessary statements.

Fix lib/src/text_one_line.dart. (-0.50 points)

Analysis of lib/src/text_one_line.dart reported 1 hint:

line 752 col 16: The value of the local variable 'textDidExceedMaxLines' isn't used.

Format lib/src/box.dart.

Run flutter format to format lib/src/box.dart.

Format lib/src/column_super.dart.

Run flutter format to format lib/src/column_super.dart.

Format lib/src/row_super.dart.

Run flutter format to format lib/src/row_super.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
flutter 0.0.0
matrix4_transform ^1.1.3 1.1.3
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
test ^1.6.3