Skip to content

Instantly share code, notes, and snippets.

@letsar
Created May 6, 2020 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letsar/69952dcc130d00e9c6bd272850ee83a2 to your computer and use it in GitHub Desktop.
Save letsar/69952dcc130d00e9c6bd272850ee83a2 to your computer and use it in GitHub Desktop.
RenderGap
class _RenderGap extends RenderBox {
_RenderGap({
double mainAxisExtent,
}) : _mainAxisExtent = mainAxisExtent;
double get mainAxisExtent => _mainAxisExtent;
double _mainAxisExtent;
set mainAxisExtent(double value) {
if (_mainAxisExtent != value) {
_mainAxisExtent = value;
markNeedsLayout();
}
}
@override
void performLayout() {
final AbstractNode flex = parent;
if (flex is RenderFlex) {
if (flex.direction == Axis.horizontal) {
size = constraints.constrain(Size(mainAxisExtent, 0));
} else {
size = constraints.constrain(Size(0, mainAxisExtent));
}
} else {
throw FlutterError(
'A Gap widget must be placed directly inside a Flex widget',
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment