Skip to content

InteractiveViewer doesn't re-scroll child into view when child shrinks #83628

@zathras

Description

@zathras

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.

flutter doctor
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)

/// Flutter code sample for InteractiveViewer

// This example shows a simple Container that can be panned
// container size set via checkbox

minimal code sample
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],
            ),
          ),
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: material designflutter/packages/flutter/material repository.found in release: 2.2Found to occur in 2.2found in release: 2.3Found to occur in 2.3frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions