代码如下:
import 'package:flutter/material.dart';
class QXButton extends StatelessWidget {
QXButton({required this.gestureDetector});
final Widget gestureDetector;
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Container(
padding: EdgeInsets.all(8.0),
height: 40,
width: 120,
decoration: BoxDecoration(
color: Colors.blue, borderRadius: new BorderRadius.circular(5.0)),
child: this.gestureDetector,
);
}
}
外部调用代码如下:
import 'package:flutter/material.dart';
import 'QXButton.dart';
class MyHome extends StatelessWidget {
final initTitle = "初始化";
final margin = new Container(
height: 30,
);
final textStyle = const TextStyle(color: Colors.white, fontSize: 14.0);
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
body: new Center(
child: new Container(
padding: EdgeInsets.all(100),
child: new Column(
children: [
new QXButton(
gestureDetector: new GestureDetector(
onTap: () => {print("初始化")},
child: new Center(child: new Text(initTitle)),
),
),
],
),
)),
);
}
}
网友评论