InteractiveViewer image is zoomed in

95
January 23, 2021, at 11:10 PM

My problem should be simple, but i'm stuck: i need to display the image of a map with a marker over it (that's why i'm using a stack) and this image can be zoomed and panned. The only problem is, when i open the app the image is totally zoomed in, and i have to zoom out manually. I tried reading the docs and googling but i only found libraries which don't suit my needs or don't work as expected.

So, the question is simple: how can i see the fully zoomed out image from the beginning?

Here's the code.

    return Container(
      height: 350,
      child: InteractiveViewer(
        // TODO the image is automatically zoomed in!
        minScale: .1,
        maxScale: 1,
        constrained: false,
        child: Stack(children: [
          Image.asset(itinerary.mapImage, fit: BoxFit.fitWidth),
          icon(...),
        ])
      )
    )
Answer 1

You need to use a TransformationController to control InteractiveViewer. Here is the code:

  TransformationController _controller;
  @override
  void initState() {
    _controller = TransformationController();
    _controller.value = Matrix4.identity() * 0.5;
    super.initState();
  }
  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Container(
        height: 350,
        child: InteractiveViewer(
          transformationController: _controller,
          minScale: .1,
          maxScale: 1,
          onInteractionEnd: (s) {
            print(_controller.value);
          },
          constrained: false,
          child: Stack(
            children: [
              Image.asset(
                "assets/Big.Buck.Bunny.-.Landscape.png",
                fit: BoxFit.fitWidth,
              ),
            ],
          ),
        ),
      ),
    );
  }

Please note that you may need to adjust initial scale value(the one multiplying with Matrix4) to get your desired output.

READ ALSO
Accept credit card and debit card payment using paypal in nodejs rest api

Accept credit card and debit card payment using paypal in nodejs rest api

I have used paypal-rest-sdk in my code the payment using paypal login working smoothly but now I want to pay using credit card and debit card without login to paypal

100
How to extract this text from this Website Scraping? BeatifulSoup

How to extract this text from this Website Scraping? BeatifulSoup

I'm trying to extract the string "No disponble" of this product, but im getting "none" or attribute text dont exists:

88
How reorganize a group of div , pure JavaScript

How reorganize a group of div , pure JavaScript

Hello I'm a beginner and I'm trying to manipulate the DOM by moving existing divsHow to make "for" loops on "

61
Rendering multiple tables are same time causes issue on display in data tables(UI)

Rendering multiple tables are same time causes issue on display in data tables(UI)

Have multiple datatables on same page, and every table have different API's for fetching the dataIf one of the API is not returning the data, both the tables data is not displaying in the UI and getting error in console like

97