How can I code a editable textfield in a CustomPainter in Flutter - flutter

I have a CustomPainter extending class. Until now, I paint only rectangles with some static text in it. Now I want to improve this a little bit and want that the user of my Flutter-App can edit this text.
I added a TextEditingController to my Object-Class and tried this:
TextField textField = TextField(
controller: object.textController,
);
textField.createRenderObject(context).paint;
textFieldPainter.paint(canvas, Offset.zero);
}
Unfortunaly, there is nothing like a textField.createRenderObject-Function in Flutter. So I look for a idea how I can get my a "controlled Text" working.
I also played around with TextSpan(). But I can't set the Controller to this.

The following steps are not the best solution , but you can try this solution.
Steps:
create an OverlayEntry, put a (hidden) TextField into it with a FocusNode and TextEditController.
after added the overlay entry, request focus on the focusNode, so the keyboard will open.
Add an onChanged to the TextField, and notify the painter somehow (e.g. valueNotifier) on text change.
In the TextPainer use the TextEditController.text value

For me, the following solution fit:
I built a function that checks if a click was done within the dimensions of the rectangle. If yes, a "properties dialog" opens (currently only the text) and here the text can now also be changed.
I know, this is only a workaround and not a real solution to my question, but maybe the approach helps one or the other.

Related

TextFormField or TextField with more buttons , multibuttons flutter

I'm new to flutter and I don't know how to do it, please tell me how to do it or a working option. because I've been trying for a very long time
https://sun9-east.userapi.com/sun9-18/s/v1/ig2/NhRxi0YKSHPdqxIaG37XCWUcygL--5igPancpM8aVbjVuZazevntosns_TcgcXzYaIZN37dpzHlCa7o9Hr41pz67.jpg?size=2142x482&quality=95&type=album
https://sun9-west.userapi.com/sun9-63/s/v1/ig2/IVIkAOvJzFSbBD5VsqgncEuhvZAq8D3EkMKSnzK8wXffnPiB2SvLE2Q2sUkNjvvJp9-fLYzh2Wp3PUv8mD6zBLVe.jpg?size=1550x949&quality=95&type=album
https://sun9-west.userapi.com/sun9-50/s/v1/ig2/WdrgTVpnxrH7mBUe1L3a3SvAepAIB4zxvl_CQKJim1O0JxddGe-qQN5JLiN-WfIcgecwXdwGGZ7UNHScnpP3TtN1.jpg?size=1578x239&quality=95&type=album
https://sun9-north.userapi.com/sun9-81/s/v1/ig2/ZQZqB1bibWQUseKiajkYuHETzNeTGSV1dc1D5IEHXiUlwuYS-Cebt9uT5VknD3xWBsXjLNkMiAk_siV287kUE0JG.jpg?size=2142x482&quality=95&type=album
TextFormField(
decoration: InputDecoration())
There's no possible option in the TextField or any equivalent widget for user input.
You can easily replicate those interfaces with layout widgets like Column and Row. If there's a case where you want to overlay other widgets on the TextField then you can stack them using Stack.
Else, if you need more advanced editor-like features, you can refer to packages like this.

Custom widget dropdown

If I do not click:
When I press the button in the red circle:
Hello, I want to ask. What widget can I use to get a design like this? When the red circle is pressed, another menu will appear and can be pressed to go to another menu. I tried using the dropdown button but it doesn't work as I want. I have also used ListTileTheme and ExpansionTile but it still doesn't work as I want. Anyone can share an opinion.
Flutter's core dropdown widget works almost exactly like your example, and there is a widget that extends it even further. You should then be able to nest further menus if that's what you need it to do. Flutter DropdownButton2

Flutter Progress Text Button

Looking for a widget similar to the answer by NiklasPor in this question here. The whole idea fits my needs - have a button that changes border drawn based on how long the button is held. The problem is that the CircularProgressIndicator is used here. I need on hold feature and border drawing to be compatible with the TextButton widget, for example. Basically, I want a TextButton to execute a function if it is held long enough. Any ideas how to start with this? I am thinking of also using the GestureDetector widget.
Have you tried this package: square_percent_indicator

setState blocks editing of TextEditingController

I am using a TextFormField as a widget and TextEditingController inside TextFormField for a phone number, and I am trying to validate a number while typing with the flutter_libphonenumber library, which provides an async function for validation.
I am trying to change the colour of the text depending upon validation status while entering it.
Current state:
Implemented TextFormField and providing it TextEditingController as a controller with valid initial text.
Implemented onFieldSubmitted and it works fine on tap of Done button of the keyboard.
Added listener to this controller for validation and set _isValid bool there.
I have used this bool to set colour of text inside the controller while building it.
So the current issue is, when I am entering text I get proper validated status inside the listener, but the colour of text is not changing accordingly.
I understand this is happening due to not calling setState after validation, so it will rebuild the widget and change the colour according to _isValid.
Error: When I try to setState inside the listener, it just doesn't allow editing.
Note: I have tried the same approach using onChanged method and it also does same, cannot enter or delete anything inside textField if there is pre-populated text (initialText).
Can anyone help me to solve this issue, or guide the correct path?
Thank you!
You can use the Form widget's autovalidate field by doing
Form(
autovalidate: true

How do you hide widgets when you are using/tapped into a TextFormField in flutter?

I would like to hide a Text widget when a user is currently tapped into a TextFormField to type. And when they aren't using it, I would like for it to be visible again. Only problem is I don't see a way to accomplish this. Any help is appreciated!
The easiest way is to check whether the user is using TextField or not is by detecting whether the keyboard is visible or not. For that follow this stack-overflow post. Once you know whether keyboard is visible or not, you can simply update the state(setState()) and decide whether to hide the widget or not. Follow this stack-overflow post as a reference to hide and un-hide widgets in flutter.