flutter gesture

 

import 'package:flutter/material.dart';
import 'package:flutter_app/pages/dismissed_page.dart';

class GestureAppPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _GestureAppPageState();
  }
}

class _GestureAppPageState extends State<GestureAppPage> {

  var tapEvent = '';

//  _showSnakeBar(String str) {
//    final snackBar = new SnackBar(content: new Text(str));
//    Scaffold.of(context).showSnackBar(snackBar);
//  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Gesture 学习'),
        centerTitle: true,
      ),
      body: new ListView(
        children: <Widget>[
          new Padding(
            padding: constEdgeInsets.only (left: 10.0, Top: 10.0, right: 10.0 ), 
            Child: new new RaisedButton ( 
                textColor: Colors.black, 
                Child: new new the Text ( 'RaisedButton click' ), 
                onPressed: () { 
                  Final SnackBar = new new SnackBar ( Content: new new Text ( "this is a RaisedButton click event, onPressed process" )); 
                  Scaffold.of (context) .showSnackBar (SnackBar); 
//                   _showSnakeBar ( "this is a RaisedButton click event, onPressed process"); 
                }) , 
          ), 
          new new the padding ( 
            padding: constEdgeInsets.only (left: 10.0, Top: 10.0, right: 10.0 ), 
            Child: new new GestureDetector ( 
              onTap: () { 
                Final SnackBar = new new SnackBar (Content: new new Text ( "This is a GestureDetector listening onTap event" )) ; 
                Scaffold.of (context) .showSnackBar (SnackBar); 
//                 _showSnakeBar ( "this is a GestureDetector listening onTap event"); 
              }, 
              Child: new new BorderButton ( 'GestureDetector onTap button' ), 
            ), 
          ), 
          new new the Padding ( 
            padding: const EdgeInsets.only(left: 10.0, top: 10.0, right: 10.0),
            child:
                new Text(tapEvent, style: Theme.of(context).textTheme.display1),
          ),
          new Padding(
            padding: const EdgeInsets.only(left: 10.0, top: 10.0, right: 10.0),
            child: new GestureDetector(
              onTapDown: (tapDown) {
                setState(() {
                  tapEvent = '这是GestureDetector监听的onTapDown事件';
                });
              },
              onTapUp: (tapUp) {
                setState(() {
                  tapEvent = 'This is GestureDetector listening onTapUp event' ; 
                }); 
              }, 
              onTapCancel: () { 
                the setState (() { 
                  tapEvent = 'What is onTapCancel event GestureDetector listening' ; 
                }); 
              }, 
              onDoubleTap: () { 
                the setState (() { 
                  tapEvent = 'this is GestureDetector listening onDoubleTap event' ; 
                }); 
              }, 
              onLongPress: () { 
                the setState (() { 
                  tapEvent = "this event is GestureDetector listening onLongPress' ;
                }); 
              }, 
              Child: new new BorderButton ( 'GestureDetector onTap in exploded event button' ), 
            ), 
          ), 
          new new the Padding ( 
            padding: const EdgeInsets.only (left: 10.0, Top: 10.0, right: 10.0 ), 
            Child: new new the Text ( 'after the button above GestureDetector by listening to events, the ripple effect is gone, use the following solutions' ), 
          ), 
          new new the padding ( 
              padding: 
                  const EdgeInsets.only (left: 10.0, top: 10.0, right: 10.0 ), 
              Child : new new new new Inkwell (
                borderRadius: BorderRadius.all ( new new Radius.circular (10.0 )), 
                onTap: () { 
                  Final SnackBar = new new SnackBar (Content: new new the Text ( "This is a listening InkWell onTap event" )); 
                  Scaffold.of (context) .showSnackBar (SnackBar); 
//                   _showSnakeBar ( "this is a InkWell listening onTap event"); 
                }, 
                Child: new new BorderButton ( 'InkWell button' ), 
              )), 
          new new the padding ( 
              padding: 
                  const EdgeInsets.only (left: 10.0, Top: 10.0, right: 10.0 ), 
              Child: new new InkWell(
                borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
                onTap: () {
                  Navigator.of(context).push(new MaterialPageRoute(builder: (context)=> new  DismissedPage()));
                  },

                child: new BorderButton('Dismissed 手势'),
              )),
        ],
      ),
    );
  }
}

class BorderButton extends StatelessWidget {
  final String text;

  BorderButton(this.text);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Container(
      alignment: Alignment.center,
      padding: const EdgeInsets.only(
          left: 10.0, top: 10.0, right: 10.0, bottom: 10.0),
      height: 48.0,
      decoration: new BoxDecoration(
        border: new Border.all(
          width: 1.0,
          color: Colors.blue,
        ),
        borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
      ),
//      foregroundDecoration: new BoxDecoration(
//        border: new Border.all(
//          width: 1.0,
//          color: Colors.red,
//        ),
//        borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
//      ),
      child: new Text(text),
    );
  }
}

class GesturePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      body: new GestureAppPage(),
    );
  }
}

 

Guess you like

Origin www.cnblogs.com/loaderman/p/11352384.html