At my app’s top screen I have this:
This is my code:
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final center = Offset(size.width / 2, size.height / 2);
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
RichText(
text: TextSpan(
children: <InlineSpan>[
WidgetSpan(
child: ConstrainedBox(
constraints: const BoxConstraints(minWidth: 32),
child: const IntrinsicWidth(
child: TextField(
keyboardType: TextInputType.number,
maxLines: null,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(0))),
))),
const WidgetSpan(child: Text("xu00B3 + ")),
WidgetSpan(
child: ConstrainedBox(
constraints: const BoxConstraints(minWidth: 32),
child: const IntrinsicWidth(
child: TextField(
keyboardType: TextInputType.number,
maxLines: null,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(0))),
))),
const WidgetSpan(child: Text("xu00B2 + ")),
WidgetSpan(
child: ConstrainedBox(
constraints: const BoxConstraints(minWidth: 32),
child: const IntrinsicWidth(
child: TextField(
keyboardType: TextInputType.number,
maxLines: null,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(0))),
))),
const WidgetSpan(child: Text("x + ")),
WidgetSpan(
child: ConstrainedBox(
constraints: const BoxConstraints(minWidth: 32),
child: IntrinsicWidth(
child: TextField(
keyboardType: TextInputType.number,
controller: controller,
maxLines: null,
decoration: const InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(0))),
))),
],
),
),
CustomPaint(
foregroundPainter: LinePainter(_offsetStart, _offsetEnd),
child: Container(
padding: const EdgeInsets.all(0.0),
height: 30.0,
child: IconButton(
color: Colors.green,
onPressed: () {
setState(() {
_offsetStart = const Offset(10, 10);
_offsetEnd =
Offset(size.width, size.height);
});
},
icon: const Icon(Icons.done_outline_rounded),
splashColor: Colors.green,
tooltip: "Save equation"),
),
),
]);}
And LinePainter class:
class LinePainter extends CustomPainter {
Paint _paint = Paint();
Offset _offsetStart = const Offset(0, 0);
Offset _offsetEnd = const Offset(60, 60);
LinePainter(Offset offsetStart, Offset offsetEnd) {
_offsetStart = offsetStart;
_offsetEnd = offsetEnd;
_paint = Paint()
..color = Colors.amber
..strokeWidth = 8.0;
}
@override
void paint(Canvas canvas, Size size) {
canvas.drawLine(_offsetStart, _offsetEnd, _paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
(I was somewhat relying on this answer)
The problem is that when I draw a line it seems to start from the top of the container, but I need to draw a line starting from center of the entire phone screen.
Could somebody please help me achieve this? Thanks in advance.
8