Flutter GestureDetector示例

import 'package:flutter/material.dart';
void main(){
  runApp(MyApp());
}
class MyButton extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new GestureDetector(
      onTap: (){
        final snackBar = new SnackBar(content: new Text("哈哈"));
        Scaffold.of(context).showSnackBar(snackBar);
      },
      child: Container(
        padding: EdgeInsets.all(20),
        decoration: BoxDecoration(
            color: Theme.of(context).buttonColor,
            borderRadius: BorderRadius.circular(10.0)
        ),
        child: Text("测试按钮"),
      ),
    );
  }
}
class MyApp extends StatelessWidget{

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("dd"),
        ),
        body:Center(
          child: MyButton(),
        )
      ),
    );
  }
}

效果图如下:

Flutter GestureDetector示例_第1张图片

 

你可能感兴趣的:(Flutter)