Skip to content

flutter multi touch gestures #10

@jindada

Description

@jindada
// 先贴上代码 后续补上文章
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';

//Main function. The entry point for your Flutter app.
void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: DemoApp(),
      ),
    ),
  );
}

class DemoApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RawGestureDetector(
      gestures: <Type, GestureRecognizerFactory>{
        MultiTapGestureRecognizer: GestureRecognizerFactoryWithHandlers<MultiTapGestureRecognizer>(
              () => MultiTapGestureRecognizer(debugOwner: this),
              (MultiTapGestureRecognizer instance) {
            instance
              ..onTapDown = (int pointer, TapDownDetails details) { print('点击'); }
              ..onTapUp = (int pointer, TapUpDetails details) { print('抬起'); }
              ..onTapCancel = (int pointer) { print('取消'); };
          },
        ),
        ScaleGestureRecognizer: GestureRecognizerFactoryWithHandlers<ScaleGestureRecognizer>(
              () => ScaleGestureRecognizer(debugOwner: this),
              (ScaleGestureRecognizer instance) {
            instance
              ..onStart = (details) { print('缩放开始'); }
              ..onUpdate = (details) { print('缩放中'); }
              ..onEnd = (details) { print('缩放结束'); };
          }
        ),
      },
      child: Center(
          child: Text('多点触控 + 缩放 其他功能可以自己扩展')
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions