Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created February 16, 2020 14:01
Embed
What would you like to do?
按下处理
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