Skip to content

Commit e8b09f4

Browse files
committed
Multiline textboxes done right
1 parent ef697ef commit e8b09f4

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

client/lib/controls/form_field.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ TextInputType parseTextInputType(String type) {
3232
case "visiblepassword":
3333
return TextInputType.visiblePassword;
3434
}
35-
return TextInputType.none;
35+
return TextInputType.text;
3636
}
3737

3838
InputDecoration buildInputDecoration(

client/lib/controls/page.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,19 @@ class PageControl extends StatelessWidget {
7575
colorScheme: lightColorScheme,
7676
brightness: Brightness.light,
7777
useMaterial3: true,
78+
// fontFamily: kIsWeb && window.navigator.userAgent.contains('OS 15_')
79+
// ? '-apple-system'
80+
// : null,
7881
visualDensity: VisualDensity.adaptivePlatformDensity);
7982

8083
var darkTheme = parseTheme(control, "darkTheme") ??
8184
ThemeData(
82-
//colorSchemeSeed: const Color.fromARGB(255, 104, 192, 233),
8385
colorScheme: darkColorScheme,
8486
brightness: Brightness.dark,
8587
useMaterial3: true,
88+
// fontFamily: kIsWeb && window.navigator.userAgent.contains('OS 15_')
89+
// ? '-apple-system'
90+
// : null,
8691
visualDensity: VisualDensity.adaptivePlatformDensity);
8792

8893
var themeMode = ThemeMode.values.firstWhere(

client/lib/controls/textfield.dart

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,15 @@ class _TextFieldControlState extends State<TextFieldControl> {
9696
var prefixControls = widget.children.where((c) => c.name == "prefix");
9797
var suffixControls = widget.children.where((c) => c.name == "suffix");
9898

99-
int? minLines = widget.control.attrInt("minLines");
100-
int? maxLines = widget.control.attrInt("maxLines");
99+
bool shiftEnter = widget.control.attrBool("shiftEnter", false)!;
100+
bool multiline =
101+
widget.control.attrBool("multiline", false)! || shiftEnter;
102+
int minLines = widget.control.attrInt("minLines", 1)!;
103+
int? maxLines =
104+
widget.control.attrInt("maxLines", multiline ? null : 1);
101105

102106
bool readOnly = widget.control.attrBool("readOnly", false)!;
103107
bool password = widget.control.attrBool("password", false)!;
104-
bool shiftEnter = widget.control.attrBool("shiftEnter", false)!;
105108
bool canRevealPassword =
106109
widget.control.attrBool("canRevealPassword", false)!;
107110
bool onChange = widget.control.attrBool("onChange", false)!;
@@ -122,9 +125,7 @@ class _TextFieldControlState extends State<TextFieldControl> {
122125
TextInputType keyboardType = parseTextInputType(
123126
widget.control.attrString("keyboardType", "")!);
124127

125-
if (keyboardType == TextInputType.none &&
126-
minLines != null &&
127-
minLines > 0) {
128+
if (multiline) {
128129
keyboardType = TextInputType.multiline;
129130
}
130131

@@ -138,12 +139,14 @@ class _TextFieldControlState extends State<TextFieldControl> {
138139
var textField = TextFormField(
139140
autofocus: autofocus,
140141
enabled: !disabled,
141-
onFieldSubmitted: (_) {
142-
ws.pageEventFromWeb(
143-
eventTarget: widget.control.id,
144-
eventName: "submit",
145-
eventData: "");
146-
},
142+
onFieldSubmitted: !multiline
143+
? (_) {
144+
ws.pageEventFromWeb(
145+
eventTarget: widget.control.id,
146+
eventName: "submit",
147+
eventData: "");
148+
}
149+
: null,
147150
decoration: buildInputDecoration(
148151
widget.control,
149152
prefixControls.isNotEmpty ? prefixControls.first : null,
@@ -152,13 +155,11 @@ class _TextFieldControlState extends State<TextFieldControl> {
152155
keyboardType: keyboardType,
153156
textAlign: textAlign,
154157
minLines: minLines,
155-
maxLines: password ? 1 : maxLines,
158+
maxLines: maxLines,
156159
readOnly: readOnly,
157160
obscureText: password && !_revealPassword,
158161
controller: _controller,
159-
focusNode: keyboardType == TextInputType.multiline && shiftEnter
160-
? _shiftEnterfocusNode
161-
: _focusNode,
162+
focusNode: shiftEnter ? _shiftEnterfocusNode : _focusNode,
162163
onChanged: (String value) {
163164
//debugPrint(value);
164165
setState(() {

docs/roadmap.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ Properties:
878878

879879
- value
880880
- keyboardType
881+
- multiline
881882
- minLines
882883
- maxLines
883884
- password

sdk/python/flet/textfield.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
#
6363
value: str = None,
6464
keyboard_type: TextInputType = None,
65+
multiline: bool = None,
6566
min_lines: int = None,
6667
max_lines: int = None,
6768
password: bool = None,
@@ -108,6 +109,7 @@ def __init__(
108109
self.value = value
109110
self.keyboard_type = keyboard_type
110111
self.text_align = text_align
112+
self.multiline = multiline
111113
self.min_lines = min_lines
112114
self.max_lines = max_lines
113115
self.read_only = read_only
@@ -152,6 +154,16 @@ def text_align(self):
152154
def text_align(self, value: TextAlign):
153155
self._set_attr("textAlign", value)
154156

157+
# multiline
158+
@property
159+
def multiline(self):
160+
return self._get_attr("multiline", data_type="bool", def_value=False)
161+
162+
@multiline.setter
163+
@beartype
164+
def multiline(self, value: Optional[bool]):
165+
self._set_attr("multiline", value)
166+
155167
# min_lines
156168
@property
157169
def min_lines(self):

sdk/python/playground/textfield-test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ def chat_submit(e):
5555

5656
chat_input = TextField(
5757
hint_text="Say something...",
58-
min_lines=1,
5958
shift_enter=True,
59+
min_lines=1,
6060
on_submit=chat_submit,
61+
max_lines=5,
6162
)
6263

6364
form = Column(
@@ -83,7 +84,7 @@ def chat_submit(e):
8384
helper_text="Tell something about us",
8485
border="underline",
8586
filled=True,
86-
min_lines=1,
87+
multiline=True,
8788
),
8889
Text(
8990
"New line - Shift + Enter and submit on Enter",

0 commit comments

Comments
 (0)