Flutter Web 应用程序捏合缩放不起作用

问题描述 投票:0回答:1

我正在使用 Flutter 开发网站。 Flutter 网站不支持捏合缩放。

笔记本电脑触控板捏合缩放功能不起作用。 Android 或 IOS 应用程序触摸放大也不起作用。

我想做的是通过 CTRL+ 和触控板捏合手势和触摸屏 2 指手势来缩放网站。 CTRL+ 工作正常。 但触控板捏合和触摸屏手势不起作用。

默认代码也会出现此问题。

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyCustomScrollBehavior extends MaterialScrollBehavior {
  const MyCustomScrollBehavior();

  @override
  Set<PointerDeviceKind> get dragDevices => {
        PointerDeviceKind.mouse,
      }..addAll(super.dragDevices);
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      scrollBehavior: const MyCustomScrollBehavior(),
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

有什么解决办法吗? 预先感谢。

flutter web zoom-sdk pinch
1个回答
1
投票

您可以使用

InteractiveViewer
小部件来允许捏合缩放:

InteractiveViewer(
        transformationController: _transformationController,
        onInteractionEnd: _updateScale,
        minScale: _minScale,
        maxScale: _maxScale,
        clipBehavior: Clip.none,
        child: child,
      )

文档:https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html

© www.soinside.com 2019 - 2024. All rights reserved.