Skip to content

Commit

Permalink
Fix expand for TextField and Dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed May 31, 2022
1 parent ec6a12a commit 08859fc
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 94 deletions.
84 changes: 44 additions & 40 deletions client/lib/controls/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,52 @@ class _DropdownControlState extends State<DropdownControl> {
var suffixControls = itemsView.children
.where((c) => c.name == "suffix" && c.isVisible);

return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
Widget dropDown = DropdownButtonFormField<String>(
autofocus: autofocus,
focusNode: _focusNode,
value: _value,
decoration: buildInputDecoration(
widget.control,
prefixControls.isNotEmpty ? prefixControls.first : null,
suffixControls.isNotEmpty ? suffixControls.first : null,
null),
onChanged: (String? value) {
debugPrint("Dropdown selected value: $value");
setState(() {
_value = value!;
});
List<Map<String, String>> props = [
{"i": widget.control.id, "value": value!}
];
itemsView.dispatch(UpdateControlPropsAction(
UpdateControlPropsPayload(props: props)));
ws.updateControlProps(props: props);
ws.pageEventFromWeb(
eventTarget: widget.control.id,
eventName: "change",
eventData: value);
},
items: items,
);

if (constraints.maxWidth == double.infinity &&
widget.control.attrDouble("width") == null) {
dropDown = ConstrainedBox(
constraints: const BoxConstraints.tightFor(width: 300),
child: dropDown,
);
}

return constrainedControl(
dropDown, widget.parent, widget.control);
Widget dropDown = DropdownButtonFormField<String>(
autofocus: autofocus,
focusNode: _focusNode,
value: _value,
decoration: buildInputDecoration(
widget.control,
prefixControls.isNotEmpty ? prefixControls.first : null,
suffixControls.isNotEmpty ? suffixControls.first : null,
null),
onChanged: (String? value) {
debugPrint("Dropdown selected value: $value");
setState(() {
_value = value!;
});
List<Map<String, String>> props = [
{"i": widget.control.id, "value": value!}
];
itemsView.dispatch(UpdateControlPropsAction(
UpdateControlPropsPayload(props: props)));
ws.updateControlProps(props: props);
ws.pageEventFromWeb(
eventTarget: widget.control.id,
eventName: "change",
eventData: value);
},
items: items,
);

if (widget.control.attrInt("expand", 0)! > 0) {
return constrainedControl(dropDown, widget.parent, widget.control);
} else {
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.maxWidth == double.infinity &&
widget.control.attrDouble("width") == null) {
dropDown = ConstrainedBox(
constraints: const BoxConstraints.tightFor(width: 300),
child: dropDown,
);
}

return constrainedControl(
dropDown, widget.parent, widget.control);
},
);
}
});
}
}
112 changes: 58 additions & 54 deletions client/lib/controls/textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,63 +138,67 @@ class _TextFieldControlState extends State<TextFieldControl> {
orElse: () => TextAlign.start,
);

return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
Widget textField = TextFormField(
autofocus: autofocus,
enabled: !disabled,
onFieldSubmitted: !multiline
? (_) {
ws.pageEventFromWeb(
eventTarget: widget.control.id,
eventName: "submit",
eventData: "");
}
: null,
decoration: buildInputDecoration(
widget.control,
prefixControls.isNotEmpty ? prefixControls.first : null,
suffixControls.isNotEmpty ? suffixControls.first : null,
revealPasswordIcon),
keyboardType: keyboardType,
textAlign: textAlign,
minLines: minLines,
maxLines: maxLines,
readOnly: readOnly,
obscureText: password && !_revealPassword,
controller: _controller,
focusNode: shiftEnter ? _shiftEnterfocusNode : _focusNode,
onChanged: (String value) {
//debugPrint(value);
setState(() {
_value = value;
});
List<Map<String, String>> props = [
{"i": widget.control.id, "value": value}
];
dispatch(UpdateControlPropsAction(
UpdateControlPropsPayload(props: props)));
ws.updateControlProps(props: props);
if (onChange) {
Widget textField = TextFormField(
autofocus: autofocus,
enabled: !disabled,
onFieldSubmitted: !multiline
? (_) {
ws.pageEventFromWeb(
eventTarget: widget.control.id,
eventName: "change",
eventData: value);
eventName: "submit",
eventData: "");
}
});

if (constraints.maxWidth == double.infinity &&
widget.control.attrDouble("width") == null) {
textField = ConstrainedBox(
constraints: const BoxConstraints.tightFor(width: 300),
child: textField,
);
}

return constrainedControl(
textField, widget.parent, widget.control);
},
);
: null,
decoration: buildInputDecoration(
widget.control,
prefixControls.isNotEmpty ? prefixControls.first : null,
suffixControls.isNotEmpty ? suffixControls.first : null,
revealPasswordIcon),
keyboardType: keyboardType,
textAlign: textAlign,
minLines: minLines,
maxLines: maxLines,
readOnly: readOnly,
obscureText: password && !_revealPassword,
controller: _controller,
focusNode: shiftEnter ? _shiftEnterfocusNode : _focusNode,
onChanged: (String value) {
//debugPrint(value);
setState(() {
_value = value;
});
List<Map<String, String>> props = [
{"i": widget.control.id, "value": value}
];
dispatch(UpdateControlPropsAction(
UpdateControlPropsPayload(props: props)));
ws.updateControlProps(props: props);
if (onChange) {
ws.pageEventFromWeb(
eventTarget: widget.control.id,
eventName: "change",
eventData: value);
}
});

if (widget.control.attrInt("expand", 0)! > 0) {
return constrainedControl(textField, widget.parent, widget.control);
} else {
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
if (constraints.maxWidth == double.infinity &&
widget.control.attrDouble("width") == null) {
textField = ConstrainedBox(
constraints: const BoxConstraints.tightFor(width: 300),
child: textField,
);
}

return constrainedControl(
textField, widget.parent, widget.control);
},
);
}
});
}
}
14 changes: 14 additions & 0 deletions sdk/python/playground/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import flet
from flet import Dropdown, Page, Row, Text, TextField


def main(page: Page):
page.add(Row(
[Dropdown(
#expand=True,
autofocus=True,
)]
))


flet.app(target=main, view=flet.WEB_BROWSER)

0 comments on commit 08859fc

Please sign in to comment.