import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:ftrecruiter/comm/utils/number_text_input_formatter.dart'; // ignore: slash_for_doc_comments /** 封装输入框 左边名字 右边输入框的布局 常用于一些表单的提交 模板: TextFieldItem( focusNode: _nodeText3, keyboardType: TextInputType.phone, title: '联系电话', hintText: '填写店主联系电话' ), */ class TextFieldItem extends StatelessWidget { const TextFieldItem({ Key? key, this.controller, required this.title, this.keyboardType = TextInputType.text, this.hintText = '', this.focusNode, }): super(key: key); final TextEditingController? controller; final String title; final String hintText; final TextInputType keyboardType; final FocusNode? focusNode; @override Widget build(BuildContext context) { final Row child = Row( children: [ Text(title), SizedBox(width: 16), Expanded( child: Semantics( label: hintText.isEmpty ? '请输入$title' : hintText, child: TextField( focusNode: focusNode, keyboardType: keyboardType, inputFormatters: _getInputFormatters(), controller: controller, //style: TextStyles.textDark14, decoration: InputDecoration( hintText: hintText, border: InputBorder.none, //去掉下划线 //hintStyle: TextStyles.textGrayC14 ), ), ), ), SizedBox(width: 16), ], ); return Container( height: 50.0, margin: const EdgeInsets.only(left: 16.0), width: double.infinity, decoration: BoxDecoration( border: Border( bottom: Divider.createBorderSide(context, width: 0.6), ), ), child: child, ); } List? _getInputFormatters() { if (keyboardType == const TextInputType.numberWithOptions(decimal: true)) { return [UsNumberTextInputFormatter()]; } if (keyboardType == TextInputType.number || keyboardType == TextInputType.phone) { return [FilteringTextInputFormatter.digitsOnly]; } return null; } }