How to put variable text and custom text together in flutter - flutter

If there is an inherited variable called id, I would like to display widget.index and ": problem number" together on one line on the screen.
ex)
problem(text) 1(list variable)
problem(text) 2(list variable)
Is there a way to get a variable in a list like the one above and display it on the screen along with text?

You can use $ in a string
String someString = 'problem id: ${problem(text)} and widget index :${widget.index}';

Related

How can I get text value of TMPro Text without markup tags in Unity?

I am trying to get text value in TMPro Text component without markup tags but haven't found any solutions.
Say, <b><color=red>Hello </color><b> world is the value in TMPro Text, and I just want Hello world in c# script.
Bear in mind that tag <b> and color will change, so I would love to remove tags dynamically, meaning I would like not to replacing each tag by text.replace("<b>", "") kind of things.
Does anyone know how to do it?
I dont know about the option of using HTML on tmp but you can attach the text to your script by create a new variable like that:
[SerializeField] TMP_Text textVar;
then you can drag you tmp game object to the component that include this script
and the you can change the text like that:
textVar.text = "what ever";
or get text like that:
string textString = textVar.text;
for the color you can use
Color color = textVar.color;
You can use TMP_Text.GetParsedText () to get the text after it has been parsed and rich text tags removed.
Alternatively you can also use regular expressions to search a string for rich text tags, and remove them while preserving the rest of the string.
using System.Text.RegularExpressions;
public static string GetString (string str)
{
Regex rich = new Regex (#"<[^>]*>");
if (rich.IsMatch (str))
{
str = rich.Replace (str, string.Empty);
}
return str;
}

Unreal Engine 4.27.2 C++ | SetText not updating UserWidget’s TextBlock from a WidgetComponent in a BP

I have an Actor BP, inside this BP I have a UWidgetComponent with a Widget Class already selected in the Details, and that Widget Class has a TextBlock. Now, inside this BP I also have a C++ USceneComponent, this component is in charge of showing a random text, in the TextBlock mentioned above, each time the user presses a button.
This is in my USceneComponent's header file (.h)
class UWidgetComponent* QuestionWidget;
class UQuestionProjectionText* QuestionText;
class UTextBlock* QuestionTextBlock;
Then in the ".cpp" file, in the constructor
QuestionWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("CodeQuestionWidget"));
QuestionTextBlock = CreateDefaultSubobject<UTextBlock>(TEXT("CodeTextBlock"));
Then in the BeginPlay()
//Gets the WidgetComponent from the BP
QuestionWidget = Cast<UWidgetComponent>(GetOwner()->GetComponentByClass(UWidgetComponent::StaticClass()));
if (QuestionWidget)
{
QuestionWidget->InitWidget();
//Gets an instance of the UMyUserWidget class, from the UWidgetComponent in the BP
QuestionText = Cast<UMyUserWidget>(QuestionWidget->GetUserWidgetObject());
this->QuestionTextBlock = QuestionText->QuestionTextBlock;
//Sets the text to an empty String
QuestionTextBlock->SetText(FText::FromString(""));
}
else
{
UE_LOG(LogTemp, Error, TEXT("QuestionWidget was not found"));
return;
}
Then in the TickComponent(), when the user presses the button, I use a something that looks like this
QuestionTextBlock->SetText(FText::FromString(QuestionStringsArray[9]));
The problem is that when I press the button, the text does not change in the Widget, but if I print the text that I'm passing, it does print the string, so I'm not passing an empty value to the "SetText()".
Another weird thing, is that the line in the BeginPlay that sets the text, that one works, I have changed it to a random string, instead of an empty one, and it does display it.
I don't know if when I do the "QuestionWidget->InitWidget();" I'm creating a new one separate from the one in the BP, or if I'm just missing something. If I eliminate the "QuestionWidget->InitWidget()" the widget gets initialized on time sometimes, and sometimes it doesn't.
I have some error handling in my code, but eliminated it here so that it didn't look too messy. But also, none of the Errors popup, everything goes on smoothly, only that the Widget doesn't show the updated Text.

I want to validate "Text" in flutter not (TextFormField or Textfield)

I want to validate "Text" in flutter not (TextFormField or Textfield), I want to check if the text is empty and if the text is empty then I want it to navigate to new page automatically.
So basically there's a Text widget where I am displaying data from Api using get method so what I want is, if the text widgets are empty, I want it to navigate to login page.
You need to store the string content of the concerned Text widget in a variable. Then you need to call a conditional operation on it to move to the new page.
Example:
String check = ""; (check == "") ? Navigator.pushNamed((context), "/desired-routeName") : Text(check),
simply you can check by == "";
for example:
String myText = ""
bool isEmpty(String text) => text == "";
isEmpty(myText); //returns true
//now set some value
myText = "some value"
isEmpty(myText); //returns false
then you can navigate based on condition like:
if (isEmpty(myText))
{ //navigation logic goes here
} else {
}
Method 1.
You can declare a variable and pass it to the Text widget. Put your condition on that variable.
Method 2.
Save your Text Widget into a variable and use the data: String? property to access the text inside Text widget.
final textWidget = const Text("Hello World");
if(textWidget.data?.isEmpty()) {
//...
}
else {
//...
}
You can put the condition in didChangeDipendencies() or initState() if you wanna to navigate to new page without any click event.
If you get data from api, i would recommend you to validate your string data with regular expressions. To check empty strings you can se the follow regex.
RegExp regExp = new RegExp(r"^$",caseSensitive: false, multiLine: false,);
if(regExp.allMatches(yourValue)){
Navigator.push(context,MaterialPageRoute(builder: (context) => const SecondRoute()),);
}

Accordion dropdown filtering through ion search bar

Hi I just created the ionic accordion dropdowns by following a tutorial blog link which used widgets for creating an accordion dropdowns, Below is the link of that blog.
http://masteringionic.com/blog/2019-01-27-creating-a-simple-accordion-widget-in-ionic-4/
updated: here is the my project demo link https://stackblitz.com/github/dSaif/search-accordion
Everything is working perfect, but i want to add Ion-searchbar at the top of the accordions sothat the dropdowns gets filter by inputing text.
please assist me how can i do that. Thank you.
You are going to have to create a variable in your homepage to store your filtered results. Then you need to have a filter function that will take the input from the search bar and filter your master list. Keep in mind you should not set the new variable to the master list, this could cause issues due to object referencing.
So you should have something like
in your html
<ion-searchbar placeholder="Search a name." [(ngModel)]="searchValue" (ionChange)="filterList()"></ion-searchbar>
In your ts file
searchValue: string = '';
filteredList: Array<{ name: string, description: string, image: string }> = this.technologies;
// function called in the html whenever you change the ion searchbar value
private filterList(){
//Make a variable so as to avoid any flashing on the screen if you set it to an empty array
const localFilteredList = []
this.technologies.forEach(currentItem => {
//here goes your search criteria, in the if statement
if(currentItem.name && currentItem.name.toLowerCase().includes(this.searchValue.toLowerCase())) {
localFilteredList.push(currentItem);
}
});
//finally set the global filter list to your newly filtered list
this.filteredList = localFilteredList;
}
You also need to make sure to reference the filterList variable instead of the current one you are referencing.

How to pass the value of textview?

Can any one tell me how to pass the value of textview (if there are five value in textview and we pass only one) from one screen to its next screen. Consider the case: I'm having two screens, first screen with one textview and the second activity have one textview and button.
If I click the first value then it has to move to second activity textview.
In order to pass state information between screens, you need to first define your Intent which you will pass to startActivity(), then use the putExtra() method on the Intent to add extra information to it.
Intent i = new Intent();
i.setClassName("com.example", "com.example.newscreen");
i.putExtra("string1", "some string");
i.putExtra("string2", "some other string");
startActivity(i);
Now to get the values on the next screen, you'd do something like this:
Intent i = getIntent();
Bundle b = i.getExtras();
String string1 = b.getString("string1");
String string2 = b.getString("string2");