input_text_page.dart
2.09 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
74
75
76
77
78
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:one_poem/routers/fluro_navigator.dart';
import 'package:one_poem/widgets/my_app_bar.dart';
/// design/7店铺-店铺配置/index.html#artboard13
class InputTextPage extends StatefulWidget {
const InputTextPage({
Key? key,
required this.title,
this.content,
this.hintText,
this.keyboardType = TextInputType.text,
}) : super(key : key);
final String title;
final String? content;
final String? hintText;
final TextInputType? keyboardType;
@override
_InputTextPageState createState() => _InputTextPageState();
}
class _InputTextPageState extends State<InputTextPage> {
final TextEditingController _controller = TextEditingController();
List<TextInputFormatter>? _inputFormatters;
late int _maxLength;
@override
void initState() {
super.initState();
_controller.text = widget.content ?? '';
_maxLength = widget.keyboardType == TextInputType.phone ? 11 : 30;
_inputFormatters = widget.keyboardType == TextInputType.phone ? [FilteringTextInputFormatter.allow(RegExp('[0-9]'))] : null;
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(
title: widget.title,
actionName: '完成',
onPressed: () {
NavigatorUtils.goBackWithParams(context, _controller.text);
},
),
body: Padding(
padding: const EdgeInsets.only(top: 21.0, left: 16.0, right: 16.0, bottom: 16.0),
child: Semantics(
multiline: true,
maxValueLength: _maxLength,
child: TextField(
maxLength: _maxLength,
maxLines: 5,
autofocus: true,
controller: _controller,
keyboardType: widget.keyboardType,
inputFormatters: _inputFormatters,
decoration: InputDecoration(
hintText: widget.hintText,
border: InputBorder.none,
),
),
),
),
);
}
}