The widgets have different heights, that are dynamic. I need the height to be a multiple of 20, so it fits in the grid I created.
Is there a possibility to force the widgets to increase their height by 20 pixels at a time if they need to expand?
In othe words I need it to snap to a grid I pre defined.
import 'package:flutter/material.dart';
class TreeNode extends StatelessWidget {
const TreeNode({
Key? key,
required this.child,
required this.minSize,
required this.maxSize,
}) : super(key: key);
final Widget child;
final int minSize, maxSize;
@override
Widget build(BuildContext context) {
return FittedBox(
child: Container(
color: Colors.green,
width: MediaQuery.of(context).size.width <= 400
? minSize.toDouble()
: maxSize.toDouble(),
height: 200, // needs to be changed
child: Visibility(
visible: true,
child: child,
maintainSize: true,
maintainState: true,
maintainAnimation: true,
),
),
);
}
}
Thanks for your help. Example of how it looks now:

EDIT: I figured it out. For anybody else who has a similar Problem.
I used IntrinsicWidth() with stepHeight and stepWidth It may be quite expensive to do, but it fits my needs.
New Code:
import 'package:flutter/material.dart';
class TreeNode extends StatelessWidget {
const TreeNode({
Key? key,
required this.child,
required this.minSize,
required this.maxSize,
}) : super(key: key);
final Widget child;
final int minSize, maxSize;
@override
Widget build(BuildContext context) {
return IntrinsicWidth(
stepHeight: 20,
stepWidth: 20,
child: Container(
color: Colors.green,
width: MediaQuery.of(context).size.width <= 400
? minSize.toDouble()
: maxSize.toDouble(),
child: Visibility(
visible: false,
child: child,
maintainSize: true,
maintainState: true,
maintainAnimation: true,
),
),
);
}
}