text_field_item.dart
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:Parlando/res/resources.dart';
import 'package:Parlando/util/input_formatter/number_text_input_formatter.dart';
/// 封装输入框
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),
Gaps.hGap16,
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
),
),
),
),
Gaps.hGap16
],
);
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;
}
}