'Flutter align items adjacent to center aligned item in row
How is it possible to align a widget center of the row and align other items adjacent to centered widget without breaking centered item position?
Example; in the image below, blue widgets should be centered (could be in different width) and align orange widgets to each side of the blue widgets by keeping blue widgets in the center? All widgets could be different size in width.
I solved the issue by measuring middle items and moving other items by half of their sizes but it is very inefficient and I need to setState rowCount times. There should be a simple and correct approach to this. Any help would be great thanks in advance.
Widget _getRow(int index) {
double _middleWidgetWidth = _middleWigetsWidths[index];
if (_middleWidgetWidth == -1) {
return MeasureSize(
child: _getColumnWidget(index, Position.middle),
onChange: (size) {
setState(() {_middleWidgetWidths[index] = size.width;});
},
);
} else {
return Stack(
children: [
AlignPositioned.expand(
alignment: Alignment.center,
child: Text(_getText(index, Position.left)),
moveByContainerWidth: -0.5,
moveByChildWidth: -0.5
),
Text(_getText(index, Position.middle)),
AlignPositioned.expand(
alignment: Alignment.center,
child: Text(_getText(index, Position.right)),
moveByContainerWidth: 0.5,
moveByChildWidth: 0.5
),
],
);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

