本文介绍了颤动网页:无法在鼠标按下时滚动(拖动)(颤动2.5+)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[更新]
我可以确认这个问题发生在2.5以上的颤动中。使用2.2.3就可以了。问题变成了为什么在2.5版中删除了这一功能?以及如何在Ffltter 2.5中启用它?
[来源问题]
我正在通过桌面浏览器在Ffltter 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
推荐答案
颤动更改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');
}
),
);
这篇关于颤动网页:无法在鼠标按下时滚动(拖动)(颤动2.5+)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!