Skip to content

Commit

Permalink
enhance edittext
Browse files Browse the repository at this point in the history
  • Loading branch information
moovida committed Nov 11, 2024
1 parent c587d8c commit 255739d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions lib/com/hydrologis/flutterlibs/ui/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,19 @@ class EditableTextField extends StatefulWidget {
final Function onSave;
final Function? validationFunction;
final TextInputType? keyboardType;
final Color? textColor;
final Color? buttonColor;
final bool withLabel;

EditableTextField(this.label, this.value, this.onSave,
{this.validationFunction,
this.isPassword = false,
this.doBold = false,
this.hintText,
this.keyboardType = TextInputType.text,
this.withLabel = false,
this.textColor,
this.buttonColor,
Key? key})
: super(key: key);

Expand Down Expand Up @@ -359,6 +365,8 @@ class _EditableTextFieldState extends State<EditableTextField> {

@override
Widget build(BuildContext context) {
Color textColor = widget.textColor ?? SmashColors.mainTextColor;
Color buttonColor = widget.buttonColor ?? SmashColors.mainDecorationsDarker;
if (editMode) {
if (_currentValue != widget.hintText && _currentValue.isNotEmpty) {
_controller.text = _currentValue;
Expand All @@ -368,8 +376,13 @@ class _EditableTextFieldState extends State<EditableTextField> {
_controller.text = "";
}
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (widget.withLabel)
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: SmashUI.normalText(widget.label),
),
Expanded(
child: TextFormField(
autofocus: true,
Expand All @@ -396,7 +409,7 @@ class _EditableTextFieldState extends State<EditableTextField> {
icon: Icon(
MdiIcons.contentSave,
size: SmashUI.MEDIUM_ICON_SIZE,
color: SmashColors.mainDecorationsDarker,
color: buttonColor,
),
onPressed: () {
if (_canSave) {
Expand All @@ -414,14 +427,19 @@ class _EditableTextFieldState extends State<EditableTextField> {
_controller2.text = _currentValue;
return Row(
children: [
if (widget.withLabel)
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: SmashUI.normalText(widget.label),
),
Expanded(
child: TextFormField(
controller: _controller2,
obscureText: widget.isPassword,
keyboardType: widget.keyboardType,
readOnly: true,
style: TextStyle(
color: SmashColors.mainTextColor,
color: textColor,
fontWeight: FontWeight.bold,
fontSize: SmashUI.NORMAL_SIZE,
),
Expand All @@ -435,7 +453,7 @@ class _EditableTextFieldState extends State<EditableTextField> {
IconButton(
icon: Icon(
MdiIcons.pencil,
color: SmashColors.mainDecorationsDarker,
color: buttonColor,
),
onPressed: () {
setState(() {
Expand Down

0 comments on commit 255739d

Please sign in to comment.