Pen Settings

JavaScript

Babel includes JSX processing.

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

Flutter

              
                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;
              });
            },
          ),
        ),
      ],
    );
  }
}

              
            
!
999px

Console