JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('GestureDetector 手势识别(拖曳)- 手势竞争'),
),
body: GestureCompetePage(),
),
);
}
}
// 手势竞争
// 在手势识别中 可以监听多个手势事件,但最终只有一个手势能够得到本次事件的处理权
class GestureCompetePage extends StatefulWidget {
@override
_GestureCompetePageState createState() => _GestureCompetePageState();
}
class _GestureCompetePageState extends State<GestureCompetePage> {
double _top = 0.0;
double _left = 0.0;
@override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned(
top: _top,
left: _left,
child: GestureDetector(
child: CircleAvatar(
minRadius: 40,
child: Text(
"手势竞争",
style: TextStyle(fontSize: 16),
),
),
// 垂直方向拖曳更新
onVerticalDragUpdate: (detail) {
setState(() {
_top += detail.delta.dy;
});
},
// 水平方向拖曳更新
onHorizontalDragUpdate: (detail) {
setState(() {
_left += detail.delta.dx;
});
},
),
),
],
);
}
}
Also see: Tab Triggers