I am using a selection area with a selectable region and need to make the direction of selection from right to left (I tried all the RTL solutions for example wrapping with directionality). but I am not using text, I am using containers here are snippets of my code here is the demo : video
return SelectionArea(
child: Stack(
// clipBehavior: Clip.antiAlias,
// textDirection: TextDirection.rtl,
// alignment: Alignment.topRight,
children: [
...state.wordsInPage.map((e) {
double widthScaleFactor = 794.r / width;
double heightScaleFactor = 1123.r / hight;
double scaledLeft = e.bbox.x1 * widthScaleFactor;
double scaledTop = e.bbox.y1 * heightScaleFactor;
// double scaledRight = e.words.last.bbox.x2 * widthScaleFactor;
final double lineHeight =
convertToLogicalPixels(context, (e.bbox.y2 - e.bbox.y1));
return Positioned(
height: 20.h,
top: scaledTop,
left: scaledLeft,
width: (e.bbox.x2.toDouble() - e.bbox.x1.toDouble()) /
(width / (794.r)),
child: Align(
alignment: Alignment.centerRight,
child: MySelectableAdapter(
id: ",${e.id}",
child: Container(
color: e.isSelected
? Colors.amber.withOpacity(0.5)
: Colors.transparent,
),
),
),
);
}),
],
),
);
},
);
Dart
Within each Positioned widget, apply TextAlign.right to the MySelectableAdapter child:
Dart
Since the selection direction is right-to-left, the starting point (scaledLeft) needs to be calculated based on the rightmost x-coordinate:
Dart
This approach adjusts the stacking order and text alignment within each Positioned widget. The
TextDirection.rtlsets the overall direction, andTextAlign.rightensures text and other content align to the right within the container. Finally, adjusting scaledLeft ensures the selection starts from the right based on the rightmost x-coordinate.