import 'package:flutter/material.dart'; import 'package:huixiang/view_widget/keyboard/custom_keyboard_button.dart'; import 'package:huixiang/view_widget/keyboard/pay_password.dart'; /// 自定义密码 键盘 class MyKeyboard extends StatefulWidget { final callback; MyKeyboard(this.callback); @override State createState() { return MyKeyboardStat(); } } class MyKeyboardStat extends State { final GlobalKey _scaffoldKey = GlobalKey(); /// 定义 确定 按钮 接口 暴露给调用方 ///回调函数执行体 var backMethod; void onCommitChange() { widget.callback(KeyEvent("commit")); } void onOneChange(BuildContext cont) { widget.callback(KeyEvent("1")); } void onTwoChange(BuildContext cont) { widget.callback(KeyEvent("2")); } void onThreeChange(BuildContext cont) { widget.callback(KeyEvent("3")); } void onFourChange(BuildContext cont) { widget.callback(KeyEvent("4")); } void onFiveChange(BuildContext cont) { widget.callback(KeyEvent("5")); } void onSixChange(BuildContext cont) { widget.callback(KeyEvent("6")); } void onSevenChange(BuildContext cont) { widget.callback(KeyEvent("7")); } void onEightChange(BuildContext cont) { widget.callback(KeyEvent("8")); } void onNineChange(BuildContext cont) { widget.callback(KeyEvent("9")); } void onZeroChange(BuildContext cont) { widget.callback(KeyEvent("0")); } /// 点击删除 void onDeleteChange() { widget.callback(KeyEvent("del")); } @override Widget build(BuildContext context) { return Container( key: _scaffoldKey, width: double.infinity, height: 250.0, padding: EdgeInsets.all(3), child: Column( children: [ Row( children: [ CustomKbBtn(text: '1', callback: (val) => onOneChange(context)), CustomKbBtn(text: '2', callback: (val) => onTwoChange(context)), CustomKbBtn(text: '3', callback: (val) => onThreeChange(context)), ], ), Row( children: [ CustomKbBtn(text: '4', callback: (val) => onFourChange(context)), CustomKbBtn(text: '5', callback: (val) => onFiveChange(context)), CustomKbBtn(text: '6', callback: (val) => onSixChange(context)), ], ), Row( children: [ CustomKbBtn(text: '7', callback: (val) => onSevenChange(context)), CustomKbBtn(text: '8', callback: (val) => onEightChange(context)), CustomKbBtn(text: '9', callback: (val) => onNineChange(context)), ], ), Row( children: [ Visibility(child: CustomKbBtn(text: '确定', callback: (val) => onCommitChange()), visible: false, maintainAnimation: false, replacement: CustomKbBtn(text: ''), maintainState: false, maintainInteractivity: false, ), CustomKbBtn(text: '0', callback: (val) => onZeroChange(context)), CustomKbBtn(text: '删除', callback: (val) => onDeleteChange()), ], ), ], ), ); } }