1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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: <Widget>[
- 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<TextInputFormatter>? _getInputFormatters() {
- if (keyboardType == const TextInputType.numberWithOptions(decimal: true)) {
- return <TextInputFormatter>[UsNumberTextInputFormatter()];
- }
- if (keyboardType == TextInputType.number || keyboardType == TextInputType.phone) {
- return <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly];
- }
- return null;
- }
- }
|