title: How to change image view in flutter?
body: <p>I trying to change view from grid to list view.
  I used <code>StaggeredGridView</code> for first view but after click change view button it should change into vertical list view .just like instagram  gallery view.</p>
  <p>Piece of code:</p>
  <p>view changing button:</p>
  <pre><code> InkWell(
        child:view
         ?Image.asset('assets/icons/view_by1.png') 
         :Image.asset('assets/icons/view_by3.png'), 
          onTap: (){
             setState(() {
               view = !view;
             });
           }
         )
  </code></pre>
  <p>widget for changing view:</p>
  <pre><code>
  Widget sliverGridWidget(BuildContext context, List&lt;Photos&gt; listPhotoDetail){
      return StaggeredGridView.countBuilder(
          padding: const EdgeInsets.all(8.0),
          crossAxisCount: view?2:6, //if view true make it vertical view otherwise grid view
          itemCount: listPhotoDetail.length,
          itemBuilder: (context, index){
            
            return InkWell(
              onLongPress: (){
                setState(() {
                  enable = true;
                });
              },
             
                child: Container(
               
                decoration: BoxDecoration(
                  color:Colors.grey[100],
  
                  image: DecorationImage(
                    image: NetworkImage(listPhotoDetail[index].photoDetail.image.fileUrl),
                    fit: BoxFit.cover
                  )
                ),
                child:enable? Stack(
                  children: &lt;Widget&gt;[
                    Positioned(
                      bottom: 5,
                      right: 3,
                      child: InkWell(
                       child:  listPhotoDetail[index].isSelected
                        ?Image.asset('assets/icons/selected.png') 
                        
                        :Image.asset('assets/icons/select_on_image.png'),
                        onTap: (){
                           setState(() {
                              listPhotoDetail[index].isSelected = !listPhotoDetail[index].isSelected;
                                count= listPhotoDetail[index].isSelected ?count+1:count-1;
                                 if(listPhotoDetail[index].isSelected){
                                    selectedPhotostList.add(
                                      Photos(
                                        photoDetail:listPhotoDetail[index].photoDetail ,
                                        //  contact:contactList[index].contact ,
                                        isSelected:listPhotoDetail[index].isSelected) 
                                      
                                      );
                                   }  else{
                                    selectedPhotostList.removeAt(index);
                                   } 
                             
                              // listPhotoDetail[index].isSelected = ! listPhotoDetail[index].isSelected;
                              // count =  listPhotoDetail[index].isSelected ?count+1:count-1;
                           });
                        }, 
                      )
                    )
                  ],
                )
                :Container()
              ),
            );
          },
           staggeredTileBuilder: (index) 
           =&gt; StaggeredTile.count(2, 2), //Make size as you want.
           mainAxisSpacing: 8.0,
           crossAxisSpacing:8.0,
        );
    }
  }
  </code></pre>
  <p>this does not give me satisfied view
  means i have total14 images
  and  gridview looks perfect and shows all 14 images but when pressed changing view button, it
  shows only 3 to 4 images as listview.</p>
  <p>see :</p>
  <p><a href="https://i.stack.imgur.com/UcHGS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UcHGS.jpg" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/RJcGm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RJcGm.jpg" alt="enter image description here" /></a></p>
  <p><a href="https://imgur.com/OHJ7axD" rel="nofollow noreferrer">Here short video</a></p>