I try to add a PageView
which doesn't fill the whole screen.
To do that I putted the PageView inside a Column
:
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(),
body: new Column(
children: <Widget>[
new SizedBox(height: 100.0, child: new Center(child: new Text("sticky header"))),
new Expanded(
child: new PageView(
children: <Widget>[
new Container(
color: Colors.red,
child: new Padding(
padding: const EdgeInsets.all(50.0),
child: new _Painter(),
),
),
new Container(
color: Colors.green,
child: new Padding(
padding: const EdgeInsets.all(50.0),
child: new _Painter(),
),
),
],
),
),
],
),
);
}
}
This works so far.
Each PageView
has a _Painter
which has a RenderBox
to paint something.
And here comes my problem: I use the handleEvent
method to detect drag events but the y
position is wrong. You can see that the drawn line is not where I touched the screen (the transparent bubble).
How can I fix this? Do I have to calculate the correct y
position myself?
You can find the full source here.
Update
globalToLocal
fixed the problem halfway but I still have to include the padding in the calculation. Is there a way to get the padding of a widget?
void _handleDragUpdate(DragUpdateDetails details) {
final pos = globalToLocal(details.globalPosition);
_currentPath?.lineTo(pos.dx + 50.0, pos.dy + 50.0);
markNeedsPaint();
}
Bonus Points
When I drag the PageView
left and right my _PainterRenderBox
forgets the drawn lines. Where is the best place to remember this lines? Store them in the _Painter
or in the _MyHomePageState
?