Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reset the matrix #15

Open
meDerekD17 opened this issue Apr 17, 2020 · 1 comment
Open

How to reset the matrix #15

meDerekD17 opened this issue Apr 17, 2020 · 1 comment

Comments

@meDerekD17
Copy link

Using info from Resetting the Matrix#8, I got the matrix to reset correcting when using CustomPaint (basically the same code as the example with CustomPaint). But I have no idea why it is working. I seem to have replaced notifier.value = m, with notifier.value = matrix; when normal zoom, offset and rotation.

It seems to work, but I do not understand. Is it possible my code will give memory leaks or anything? Is it the best way for CustomPaint?

My Code:
class _CustomPainterDemoState extends State {
Matrix4 matrix = Matrix4.identity();
ValueNotifier notifier;
bool resetMatrix = false;

@OverRide
void initState() {
super.initState();
notifier = ValueNotifier(matrix);
.....
in the build
body: MatrixGestureDetector(
onMatrixUpdate: (m, tm, sm, rm) {
if(resetMatrix) {
matrix = MatrixGestureDetector.compose(matrix, tm, sm, rm);
//above appears to reset all matrices
}
notifier.value = matrix; //original code had notifier.value = m
},

I then have child: CustomPaint, exactly like the example
At the bottom, I have a floating Action Button to reset the screen
floatingActionButton: FloatingActionButton(
onPressed:(){
setState(() {
matrix = Matrix4.identity();
notifier = ValueNotifier(matrix);
resetMatrix = true;
});
}
),

@JoseGeorges8
Copy link

This works for me:

onMatrixUpdate: (Matrix4 m, Matrix4 tm, Matrix4 sm, Matrix4 rm) {
    setState(() {
        matrix = MatrixGestureDetector.compose(matrix, tm, sm, rm);
    });
},

And arround MatrixGestureDetector I've got a gesture detector like so:

GestureDetector(
    onDoubleTap: (){
        setState(() {
            matrix = Matrix4.identity();
         });
     },
     child: MatrixGestureDetector(...),
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants