gpt4 book ai didi

flutter 网络 : Cannot scroll with mouse down (drag) (Flutter 2. 5+)

转载 作者:行者123 更新时间:2023-12-04 14:43:36 24 4
gpt4 key购买 nike

[更新]
我可以确认这个问题发生在 2.5 以上的 flutter 中。使用 2.2.3 没问题。问题变成了为什么在 2.5 中删除了此功能?以及如何在 flutter 2.5 中启用它?
[起源问题]
我在带有桌面浏览器的 flutter web 上使用 SingleChildScrollView。滚动仅适用于鼠标滚轮,而不适用于鼠标单击(拖动)。如何将鼠标单击映射到像移动设备一样触摸和滚动?

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SingleChildScrollView(
child: Column(
children: List<Widget>.generate(50, (i) => Text(i.toString())).toList(),
),
),
);
}
}
flutter doctor -v
[✓] Flutter (Channel master, 2.6.0-6.0.pre.6, on Ubuntu 20.04.3 LTS 5.11.0-34-generic, locale en_US.UTF-8)
• Flutter version 2.6.0-6.0.pre.6 at /home/XXX
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 0c5431d99c (12 days ago), 2021-09-05 22:31:02 -0400
• Engine revision b9c633900e
• Dart version 2.15.0 (build 2.15.0-82.0.dev)

[✓] Chrome - develop for the web
• Chrome at google-chrome

[✓] Connected device (2 available)
• Linux (desktop) • linux • linux-x64 • Ubuntu 20.04.3 LTS 5.11.0-34-generic
• Chrome (web) • chrome • web-javascript • Google Chrome 93.0.4577.82

最佳答案

Flutter 在 2.5 之后更改鼠标滚动行为。见 this详情。

class MyCustomScrollBehavior extends MaterialScrollBehavior {
// Override behavior methods and getters like dragDevices
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
// etc.
};
}

// ScrollBehavior can be set for a specific widget.
final ScrollController controller = ScrollController();
ScrollConfiguration(
behavior: MyCustomScrollBehavior(),
child: ListView.builder(
controller: controller,
itemBuilder: (BuildContext context, int index) {
return Text('Item $index');
}
),
);

关于 flutter 网络 : Cannot scroll with mouse down (drag) (Flutter 2. 5+),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69232764/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com