LoginSignup
0
0

More than 3 years have passed since last update.

Flutter で iOS の touchDown 、Android の onTouch を実装する方法

Posted at

想定する読者の方

・iOS でいうと touchDown 、Android でいうと onTouch を、Flutter でどう実現するか分からない方
・GestureDetector class を触ったことがない方
・GestureDetector class は分かるんだけど、書き方を忘れてしまった方

実装方法

GestureDetector class を利用すれば、各種タップやドラッグなどを実装できます。
https://api.flutter.dev/flutter/widgets/GestureDetector-class.html

色々な Callback(イベント)がありますが、今回は onTapDown を利用します。

サンプルコード抜粋

GestureDetector(
        // Widget をタップした瞬間にイベントが発火する
        onTapDown: (TapDownDetails details){
          //画面の座標を取得する(全画面の左上が0,0)
          print(details.globalPosition.toString());
          //child の座標を取得する(child の左上が0,0)
          print(details.localPosition.toString());
        },
      child: Container(width: 100, height: 100, color: Colors.blue),
    );

サンプルコードのプロジェクト(Github)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0