number_keyboard.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. part of cool_ui;
  2. class NumberKeyboard extends StatelessWidget{
  3. static const CKTextInputType inputType = const CKTextInputType(name:'CKNumberKeyboard');
  4. static double getHeight(BuildContext ctx){
  5. MediaQueryData mediaQuery = MediaQuery.of(ctx);
  6. return mediaQuery.size.width / 3 / 2 * 4;
  7. }
  8. final KeyboardController controller ;
  9. const NumberKeyboard({this.controller});
  10. static register(){
  11. CoolKeyboard.addKeyboard(NumberKeyboard.inputType,KeyboardConfig(builder: (context,controller){
  12. return NumberKeyboard(controller: controller);
  13. },getHeight: NumberKeyboard.getHeight));
  14. }
  15. @override
  16. Widget build(BuildContext context) {
  17. MediaQueryData mediaQuery = MediaQuery.of(context);
  18. return Material(
  19. child: DefaultTextStyle(style: TextStyle(fontWeight: FontWeight.w500,color: Colors.black,fontSize: 23.0), child: Container(
  20. height:getHeight(context),
  21. width: mediaQuery.size.width,
  22. decoration: BoxDecoration(
  23. color: Color(0xffafafaf),
  24. ),
  25. child: GridView.count(
  26. childAspectRatio: 2/1,
  27. mainAxisSpacing:0.5,
  28. crossAxisSpacing:0.5,
  29. padding: EdgeInsets.all(0.0),
  30. crossAxisCount: 3,
  31. children: <Widget>[
  32. buildButton('1'),
  33. buildButton('2'),
  34. buildButton('3'),
  35. buildButton('4'),
  36. buildButton('5'),
  37. buildButton('6'),
  38. buildButton('7'),
  39. buildButton('8'),
  40. buildButton('9'),
  41. Container(
  42. color: Color(0xFFd3d6dd),
  43. child: GestureDetector(
  44. behavior: HitTestBehavior.translucent,
  45. child: Center(child: Icon(Icons.expand_more),),
  46. onTap: (){
  47. controller.doneAction();
  48. },
  49. ),
  50. ),
  51. buildButton('0'),
  52. Container(
  53. color: Color(0xFFd3d6dd),
  54. child: GestureDetector(
  55. behavior: HitTestBehavior.translucent,
  56. child: Center(child: Text('X'),),
  57. onTap: (){
  58. controller.deleteOne();
  59. },
  60. ),
  61. ),
  62. ]),
  63. )),
  64. );
  65. }
  66. Widget buildButton(String title,{String value}){
  67. if(value == null){
  68. value = title;
  69. }
  70. return Container(
  71. color: Colors.white,
  72. child: GestureDetector(
  73. behavior: HitTestBehavior.translucent,
  74. child: Center(child: Text(title),),
  75. onTap: (){
  76. controller.addText(value);
  77. },
  78. ),
  79. );
  80. }
  81. }