Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created February 16, 2020 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlid/611345f082298c4abd91da9e45a94a82 to your computer and use it in GitHub Desktop.
Save ryanlid/611345f082298c4abd91da9e45a94a82 to your computer and use it in GitHub Desktop.
按下处理
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: "按下处理",
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("按下处理"),
),
body: Center(
child: MyButton(),
),
);
}
}
class MyButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
final snackBar = SnackBar(
content: Text("你已按下啦"),
);
Scaffold.of(context).showSnackBar(snackBar);
},
child: Container(
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: Theme.of(context).buttonColor,
borderRadius: BorderRadius.circular(10.0),
),
child: Text("测试按钮"),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment