欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

flutter實(shí)現(xiàn)點(diǎn)擊事件

 更新時(shí)間:2020年08月26日 16:47:51   作者:WongKyunban  
這篇文章主要為大家詳細(xì)介紹了flutter實(shí)現(xiàn)點(diǎn)擊事件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了flutter實(shí)現(xiàn)點(diǎn)擊事件的具體代碼,供大家參考,具體內(nèi)容如下

在Android中,您可以通過調(diào)用方法setOnClickListener將OnClick綁定到按鈕等view上。

在Flutter中,有兩種方法:

1.如果Widget支持事件監(jiān)聽,則可以將一個(gè)函數(shù)傳遞給它并進(jìn)行處理。例如,RaisedButton有一個(gè)onPressed參數(shù)

@override
Widget build(BuildContext context) {
 return new RaisedButton(
  onPressed: () {
  print("click");
  },
  child: new Text("Button"));
}

2.如果Widget不支持事件監(jiān)聽,則可以將該Widget包裝到GestureDetector中,并將處理函數(shù)傳遞給onTap參數(shù)

class SampleApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return new Scaffold(
  body: new Center(
  child: new GestureDetector(
  child: new FlutterLogo(
   size: 200.0,
  ),
  onTap: () {
   print("tap");
  },
  ),
 ));
 }
}

2.1.使用GestureDetector,可以監(jiān)聽多種手勢(shì)

(1)Tap

onTapDown
onTapUp
onTap
onTapCancel

(2)Double tap

onDoubleTap 用戶快速連續(xù)兩次在同一位置輕敲屏幕

(3)長(zhǎng)按

onLongPress

(4)垂直拖動(dòng)

onVerticalDragStart
onVerticalDragUpdate
onVerticalDragEnd

(5)水平拖拽

onHorizontalDragStart
onHorizontalDragUpdate
onHorizontalDragEnd

2.2.示例:監(jiān)聽FlutterLogo的雙擊事件,雙擊時(shí)使其旋轉(zhuǎn)。

void main() => runApp(DemoApp());

class DemoApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return new MaterialApp(
  title: '導(dǎo)航演示1',
  home: new MyAppHome(),
 );
 }
}

class MyAppHome extends StatefulWidget{
 @override
 _MyAppHomeState createState() => _MyAppHomeState();

}
class _MyAppHomeState extends State<MyAppHome> with TickerProviderStateMixin{
 AnimationController controller;
 CurvedAnimation curve;

 @override
 void initState() {
 super.initState();
 controller = new AnimationController(
  duration: const Duration(milliseconds: 2000), vsync: this);
 curve = new CurvedAnimation(parent: controller, curve: Curves.easeIn);
 }

 @override
 Widget build(BuildContext context) {
 return new Scaffold(
  body: new Center(
  child: new GestureDetector(
  child: new RotationTransition(
   turns: curve,
   child: new FlutterLogo(
    size: 200.0,
   )),
  onDoubleTap: () {
   if (controller.isCompleted) {
   controller.reverse();
   } else {
   controller.forward();
   }
  },
  ),
 ));
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android打開相機(jī)和相冊(cè)實(shí)例代碼

    Android打開相機(jī)和相冊(cè)實(shí)例代碼

    這篇文章主要為大家詳細(xì)介紹了Android打開相機(jī)和相冊(cè)實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • android仿愛奇藝加載動(dòng)畫實(shí)例

    android仿愛奇藝加載動(dòng)畫實(shí)例

    這篇文章主要介紹了android仿愛奇藝加載動(dòng)畫實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。
    2016-10-10
  • Android實(shí)現(xiàn)數(shù)據(jù)按照時(shí)間排序

    Android實(shí)現(xiàn)數(shù)據(jù)按照時(shí)間排序

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)數(shù)據(jù)按照時(shí)間排序的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • 基于Android?Kotlin高頻面試題解析

    基于Android?Kotlin高頻面試題解析

    這篇文章主要為大家介紹了基于Android?Kotlin高頻面試題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • 房卡麻將分析系列

    房卡麻將分析系列 "牌局回放" 之 數(shù)據(jù)設(shè)計(jì)詳解及實(shí)例

    這篇文章主要介紹了房卡麻將分析系列 "牌局回放" 之 數(shù)據(jù)設(shè)計(jì)詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android編程實(shí)現(xiàn)自定義分享列表ACTION_SEND功能的方法

    Android編程實(shí)現(xiàn)自定義分享列表ACTION_SEND功能的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)自定義分享列表ACTION_SEND功能的方法,結(jié)合實(shí)例形式詳細(xì)分析了自定義分享列表功能的步驟與具體操作技巧,需要的朋友可以參考下
    2017-02-02
  • Kotlin面向?qū)ο笾R(shí)點(diǎn)講解

    Kotlin面向?qū)ο笾R(shí)點(diǎn)講解

    面向?qū)ο缶幊掏ㄟ^對(duì)事物的抽象,大大的簡(jiǎn)化了程序的開發(fā)難度。我們常用的編程語言:Java、C++、Python都屬于面向?qū)ο缶幊獭otlin與java類似,也是一種面向?qū)ο缶幊陶Z言。本文從面向?qū)ο笕齻€(gè)基本特征:封裝、繼承、多態(tài),來闡述一下Kotlin中的面向?qū)ο缶幊?/div> 2022-12-12
  • Android關(guān)鍵字persistent詳細(xì)分析

    Android關(guān)鍵字persistent詳細(xì)分析

    這篇文章主要介紹了Android關(guān)鍵字persistent的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-04-04
  • Android中AlarmManager基本用法分析

    Android中AlarmManager基本用法分析

    這篇文章主要介紹了Android中AlarmManager基本用法,結(jié)合實(shí)例形式簡(jiǎn)單分析了AlarmManager的基本類型、方法及簡(jiǎn)單使用示例,需要的朋友可以參考下
    2016-08-08
  • Android熱修復(fù)Tinker接入及源碼解讀

    Android熱修復(fù)Tinker接入及源碼解讀

    熱修復(fù)這項(xiàng)技術(shù),基本上已經(jīng)成為項(xiàng)目比較重要的模塊了。主要因?yàn)轫?xiàng)目在上線之后,都難免會(huì)有各種問題本文講述了Android熱修復(fù)Tinker接入及源碼解讀
    2018-09-09

最新評(píng)論