颤动交互式查看器。避免平移调整大小

时间:2021-04-02 00:12:24

标签: flutter

我正在尝试创建图像查看器,但在调整视口大小时遇到​​问题。

重现问题:

将代码粘贴到 dartpad 并使用鼠标中滚轮放大图像...专注于图像中的特定内容(例如键盘上的“G”键)

现在调整浏览器窗口的大小。随着图像的升起,图像会消失,您必须平移回焦点。

我怎样才能避免这种情况?当我调整大小时,我希望图像不平移


/// Flutter code sample for InteractiveViewer
// This example shows a simple Container that can be panned and zoomed.

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

/// This is the main application widget.
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  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: const MyStatelessWidget(),
      ),
    );
  }
}

/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
  const MyStatelessWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: InteractiveViewer(
        boundaryMargin: const EdgeInsets.all(20.0),
        minScale: 0.1,
        maxScale: 50,
        child: Image.network('https://picsum.photos/2500?image=9'),
      ),
    );
  }
}

0 个答案:

没有答案