import 'package:flutter/material.dart'; /// 自定义 键盘 按钮 class CustomKbBtn extends StatefulWidget { String text; CustomKbBtn({Key key, this.text, this.callback}) : super(key: key); final callback; @override State createState() { return ButtonState(); } } class ButtonState extends State { ///回调函数执行体 var backMethod; void back() { widget.callback('$backMethod'); } @override Widget build(BuildContext context) { MediaQueryData mediaQuery = MediaQuery.of(context); var _screenWidth = mediaQuery.size.width; Widget button = MaterialButton( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(5.0), side: BorderSide.none), elevation: 1, color: Color(0xFFFCFCFE), child: Text( widget.text, style: TextStyle(color: Color(0xff333333), fontSize: 20.0), ), onPressed: back, ); if (widget.text == "") { button = Container(); } else if (widget.text == "删除") { button = MaterialButton( onPressed: back, child: Center( child: Image.asset( "assets/image/icon_del.png", width: 24, height: 18, fit: BoxFit.contain, ), ), ); } return Container( height: 46.0, margin: EdgeInsets.all(3), width: (_screenWidth - 24) / 3, child: button, ); } }