Repository: flutter
Issue: InteractiveViewer doesn't re-scroll child into view when child shrinks
Labels: framework,f: material design,has reproducible steps,found in release: 2.2,found in release: 2.3,team-design,triaged-design

If the child of an InteractiveViewer becomes smaller, it should change the scroll position(s), if necessary, so that the child is visible.  It doesn't.

To reproduce with the attached code:
   Size window to something smaller than 1000x1000 (e.g. on desktop)
   Check checkbox (making child big)
   Scroll child so lower-right corner is visible
   Uncheck checkbox
Now the child is completely invisible, and can't be scrolled back into view.

This behavior was observed on the MacOS runtime.

<details> 
<summary>flutter doctor</summary> 
	
```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.1, on macOS 11.2.3 20D91 darwin-arm, locale
    en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for
      more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] IntelliJ IDEA Community Edition (version 2021.1)
[✓] Connected device (2 available)
```

</details>


/// Flutter code sample for InteractiveViewer

// This example shows a simple Container that can be panned
// container size set via checkbox

<details> 
<summary>minimal code sample</summary> 

```dart
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

/// This is the main application widget.
class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool big = false;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: MyApp._title,
      home: Scaffold(
        appBar: AppBar(
            leading: Checkbox(
                value: big,
                onChanged: (_) => setState(() {
                      big = !big;
                    })),
            title: const Text(MyApp._title)),
        body: MyStatelessWidget(big: big),
      ),
    );
  }
}

/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
  final double size;
  const MyStatelessWidget({Key? key, required bool big}) :
      size = big ? 1050 : 50,
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: InteractiveViewer(
        boundaryMargin: const EdgeInsets.all(20.0),
        constrained: false,
        scaleEnabled: false,
        panEnabled: true,
        child: Container(
          constraints: BoxConstraints.tight(Size(size, size)),
          decoration: const BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: <Color>[Colors.orange, Colors.red],
              stops: <double>[0.0, 1.0],
            ),
          ),
        ),
      ),
    );
  }
}
``` 

</details>