5

I am zoom a image inside interactive viewer , interactive viewer is a child of container ,set some height to container,after zoom a image, particular position in viewport ,i cant scroll and zoom a image


 class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: Zoom(),
      ),
    );
  }
}
class Zoom extends StatefulWidget
{
  @override
  MyStatelessWidget createState()=> MyStatelessWidget();
}
/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends State<Zoom> {


  @override
  Widget build(BuildContext context) {
    return Center(
child:Container(height: 300,
      child: InteractiveViewer(

       scaleEnabled: true,maxScale: 4.0,
        child: Center(
         child:Container( child:Image.asset('Assets/Java-001.jpg',fit: BoxFit.cover,alignment: Alignment.center,)),
      ),
    )));
  }
}


How can i resolve this problem?

Allwin Vinosh
  • 95
  • 1
  • 7

2 Answers2

13

Try adding these arguments to the InteractiveViewer widget:

minScale: 0.1,
maxScale: 4.0,
boundaryMargin: const EdgeInsets.all(double.infinity),
constrained: false,
Roslan Amir
  • 1,141
  • 8
  • 16
2

If your widget is greater than the viewport, you'll need to set constrained to false.

constrained: If set to false, then the child will be given infinite constraints. This is often useful when a child should be bigger than the InteractiveViewer.

InteractiveViewer(
  constrained: false, // Set it to false.
  child: YourContainer(...),
)
iDecode
  • 22,623
  • 19
  • 99
  • 186