Cloud Stack Ninja

I Have a MatrixGestureDetector to pinch zoom, drag and rotate images around, but users can access other page to add more images, so when they return to the previous page where all the images are in already change position, the rotation or resize of the images once gets lost. It is fine setting them as initial state but once onMatrixGestureDetector start to work, the image goes back to their original state, that means the Matrix start from 0 as if it were the first time moving it. I want to know if there is a way to set the previous state as rotation and zoom and the MatrixUpdate start from there? Here is a snippet of the code

void initState() {
    super.initState();
    readingGarments();
    first=1;
}

@override
Widget build(BuildContext context) {
return new Scaffold(
    appBar: new AppBar(
    title: new Text("New"), 
    body:  new Container(
    child:displayGarments();
    )
}

Widget displayGarments(){
    Widget item;
    try {      
        item = Stack(
            children: getList(),
            );
    } catch(err){
   
    }
    return item;
}

void readingGarments() async{
try {
    _isLoading=true;
    var fullList = await getGarmentsList();
  
    if(fullList==null){
        setState(() {
        _isLoading = false;
        _hasMore = false;
        });
    }

    if(fullList.isEmpty ){
    setState(() {
        _isLoading = false;
        _hasMore = false;
      });
    } else {
 
    setState(() {

    notifList=new List();
      
        int start=0;
        List<ValueNotifier> _tempList = widget.valNotif;
        if(_tempList!=null) {
            start = _tempList.length;
        for(int i=0;i<_tempList.length;i++) {
          ValueNotifier<Matrix4> notifier= _tempList[i];
          notifList.add(notifier);
        } 
        }
        for(int i=start;i<fullList.length;i++) {
            ValueNotifier<Matrix4> notifier= ValueNotifier(Matrix4.identity());
            notifList.add(notifier);
        } 
        for(int i=0; i<fullList.length;i++){
            ValueNotifier<Matrix4> notifier=ValueNotifier(Matrix4.identity());
            if(fullList[i].shape==1){
            notifier.value=Matrix4.rotationY(math.pi);
            } 
            flipList.add(notifier);
        }

        _isLoading = false;
        if(garmentsList==null)
            garmentsList = fullList;
        else
            garmentsList.addAll(fullList);         
      
        });
    }
} catch(err){
    print("ERROR: "+err.toString());
}

}

List<Widget> getList(){

double imgHeigh;
List<Widget> listWidget=[];
for(int i=0;i<garmentsList.length;i++) {
  
    final ValueNotifier<Matrix4> notifier1= notifList[i];
    final ValueNotifier<Matrix4> flipNotif= flipList[i];
    DisplayGarment _garments = garmentsList[i];

    listWidget.add( 
    MatrixGestureDetector(     
    onMatrixUpdate: (m, tm, sm, rm) { 
        setState(() {
            if(first==1){
                notifier1.value=MatrixGestureDetector.compose(notifier1.value, tm, sm, rm);
                first=0;
            } else
                notifier1.value = m;

        });
    },
    child: AnimatedBuilder(
        animation: notifier1,
        builder: (ctx, child) {
            return Transform(
            transform:  notifier1.value,
            child: Stack(
                children: <Widget>[
                Container(          
                    padding: EdgeInsets.all(4),
                    alignment: Alignment(0, -0.5),
                child: 
                  InkWell(
                   
                  child: Transform(
                    alignment: Alignment.center,
                    transform: flipNotif.value,      
                    child:        
                    _selectedIndex==i ?
                    Container(    
                      padding: EdgeInsets.all(0),  
                      height: imgHeigh,
                      width: imgWidth-50,
                      child: DottedBorder(
                          padding: EdgeInsets.all(0),
                          color:  Colors.green,
                          strokeWidth: 1,
                          child: Center(
                            child: CachedNetworkImage(
                              imageUrl: url,
                              height: imgHeigh,
                              width: imgWidth,
                              
                            )
                          )
                      ),
                    )
                    :

                    Container(    
                        padding: EdgeInsets.all(0),  
                        height: imgHeigh,
                        width: imgWidth-50,
                        child: DottedBorder(
                        
                        padding: EdgeInsets.all(0),
                            color:  Colors.transparent,
                            strokeWidth: 0,
                            child: Center(
                                
                            child: CachedNetworkImage(
                                imageUrl: url,
                                height: imgHeigh,
                                width: imgWidth,
                            ))),
                    ))
                ,))
            ],),);
      },),)
);}
listWidget.add(textContainer);

return listWidget;
}

}

Any ideas how can be solved? Thanks a lot

The first is the starting point, second how they move around and transform, and the last once the bag is start to drag around it goes back to their initial position, that is after coming coming back from another page



Read more here: https://stackoverflow.com/questions/64417304/flutter-set-initial-state-for-matrixgesturedetector-start-update

Content Attribution

This content was originally published by Gina Benavides at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: