Animating Text widget content based on change of variable - flutter

How can I animate the change from a Text widget with a particular String to a new String which is dynamic, i.e., I don't know what it'll be beforehand ?
For example, let the widget be Text('a'). Later I want it to animate to Text('b'), maybe a after a button being clicked by a user.

Store the user input in a variable and display it in the Text widget. For example,
var input = value;
inside the widget you can use Text('$input') or directly Text(input) to display it

Related

I want string to be a widget in flutter

I mean that I want to get scores code from api:
Well their is a widget called Text()
provide the String as it text then it will accept it
body: Text("any text")
Use Text widget with string text
body: Text(text),
If this is for learning purposes and you want to know how to use a widget as a parameter you can do the following:
Text text = Text("Something"); // This way you specify exactly the type `Text`
or
Widget text = Text("Somethig"); // This way you can associate any widget to text
or
var text = Text("Something"); // var can be used with any type
Then you can use whenever you want in your code as long as it require a Widget as a child whitout any need for casting.
For you to create a widget that you can associate values to it you can go for something like this:
Widget myText({String value}) => Text(value);
There are many approaches depending on your need, and I strongly advice you to follow some tutorials for beginners first like Angela Yu bootcamp or any others and also use Flutter documentation.
Try the following code:
body: Text(text),
String is not and will not be a widget. What you are probably looking for is the widget to display a string in your UI: Text.
In your exemple, you can correct it like this :
return Scaffold(
body: Text("Hello World")
);
See exemple on DartPad

How can I disable individual buttons on a flutter togglebutton widget?

So... I have a togglebutton widget [1|2|3|4], but if another widget is checked, I need to disable some of those buttons (eg, if I'm connecting to a Tile instead of a Frob, I need to disable 2 & 4).
you can play with Visibility to hide or not the widgets you want
I found that the best way is to have the a function that returns ToggleButtons widget based on certain input parameters. So the function returns ToggleButton widgets whatever number of toggle buttons you want. In case you want 3 buttons, you would pass in a list of 3 bools, take that list and build the ToggleButtons widget with only 3 buttons...and so on. And/Or you can have a condition that builds different ToggleButtons widget based on a certain parameter:
ToggleButtons toggleButtons(
{required StateSetter setState,
required List<bool> isSelected,
required String nameOfButtons}) {
if (nameOfButtons == "shortList") {
// return ToggleButtons widget that only has 3 Toggle Buttons
return ToggleButtons(...);
} else {
// return ToggleButtons widget that only has 2 Toggle Buttons
return ToggleButtons(...);
}});
Visibility will simply hide the content of the toggle button but still allow a user to press that button. Also if you have an outline on your toggle buttons, the inside will just be blank but.

Flutter: How to add bullets points in a TextField?

How to add bullets points in a TextField widget similar to the Notes app in IOS?
You can use Unicode code to achieve this. Add the following Unicode ( \u25EF ) to your TextField using TextEditingController. You may also need to change the position of the cursor when adding text to your TextEditingController. This depends on your requirement and you will understand when you test this.
TextEditingController _textController = new TextEditingController();
_textController.text = " \u25EF ";
Yes. of course you need a custom button or something to trigger this event like in the note of IOS.
You can create a custom keyboard with an extra button to add bullets or a floating deck with a button like the Note app. Or simply give a button on the screen.
You need to create a checkbox (or similar button) manually when user select it and add to left of textfield. You can define variable on a Row and initialize to Container. Something like that:
Widget widget = Container();
[...]
Row(
children: [
widget,
Expanded(child: TextField(...))
],
);
[...]
//this activate bullet point
void functionCheckBox(){
setState({
widget = Checkbox(value: value, onChanged: onChanged);
});
}
I dont know if it's the best solution or if exists a plugin that does something like that.

How to get the height of the FloatingSearchBar widget?

Please, I want to get the height of the bar of FloatingSearchBar widget so I can adjust the top padding of the next widget to not go under the FloatingSearchBar!
for exemple this next image from my app :
Image from my APP
The form widget is after the FloatingSearchBar and not under it because I use a padding with a fixed chosen value!
I used this code
final fsb = FloatingSearchBar.of(context);
print(fsb);
But when I print "fsb" I get "null" value !!
Thanks in advance!

How to retrieve text data from Text Widget in flutter

I am a beginner in flutter, how do i get or retrieve data from text widget. I have done some practice for example
Text("18:00"),
var data=Text("18:00");
print(data);
At the end instead of getting "18:00" i am getting "Text("17:05")" at the output.
define this
var data = "18:00";
Text("18:00"),
print(data);
To retrieve data fom a Text widget,
var data=Text("18:00");
print(data.data);
This will give you the output "18:00" as per your requirement.
what do you want to do? if you want to get an input from user you should use text field or forms by setting controller to it and get data from controller.
final myController = TextEditingController();
TextField(controller: myController),
var data=mycontroller.getText();
or if you want just get the text of text widget just set that text to a variable then pass it to widget.
String data="18:00"
Text(data);