I'm giving my users the option to sent in an email. Once they enter their email address, I would like to simply add the text "Email has been sent to user#email.com".
I'm not quite sure on how to do this, and was hoping someone can point me in the right direction. Thanks in advance!
For this, to work you need to have a boolean value that triggers your Text widget using Visibility. Suppose the boolean variable is isEmailSent and set its initial value to be false.
bool isEmailSent = false;
Now the user has entered his/her email address and then on onTap you must change the state of the boolean value like this:
onTap:(){
setState((){
isEmailSent = true;
});
}
When the state has been changed then with the help of Visibility and Text widgets you could do something like this:
Visibility(
visible: isEmailSent,
child: Text(
"Email has been sent to user#email.com"
)
)
Now, whenever the isEmailSent is true your text will be visible else not.
EDIT
How would I change the user#email.com to the input?
Again you also need to have a String variable for this to work. This time the name of the variable will be emailId. Initially set its value as an empty string like this:
String emailId = "";
Then change the state of the variable using setState, like this:
setState((){
emailId = _textController.text; //where _textController is the controller of your input
});
Now inside your Text do something like this:
Text(
"Email has been sent to "+emailId
)
create onTap() as the user enters the email address. in onTap define AlertDialog that will give an popup dialog showing text "Email has been sent to user#email.com "
Related
I have 6 textfields in my signup page for entering Username, Institution Id, Email, Mobile, Country, City. Currently, the validation mode is given as,
AutovalidateMode.onUserInteraction
So, I want to change this mode, such that, when i complete the Username and move to the Institution Id field, validation should be active for Username. And this should happen for every other textfields. So, can anybody help me with a proper solution for this.
Add focusnode and listener for each textField. Validatation can be done onFocus of the textField. For example
FocusNode userFocusNode = FocusNode();
void initState() {
super.initState();
userFocusNode.addListener(() {
if (userFocusNode.hasFocus) {
//write your validate function
}
});
}
In your textField mention the focusNode
TextField(
focusNode: userFocusNode,
I have a checkbox that I would like to disable a field when it is unchecked. How would I do that? This it the current checkbox code I have so far...
child: CheckboxListTile(
title: Text("Auto Calculate Big Blind"),
value: _autoCalcBigBlind,
onChanged: (bool value) {
setState(() {
if (value == false) { //focus on the big blind text field
_bigBlindFocusNode.requestFocus();
} else {
//first check small blind is not null
if (_textEditControllerSmallBlind.text == null || _textEditControllerSmallBlind.text == '0'){
//if the field is null/0, can't double it, so focus on it
_smallBlindFocusNode.requestFocus();
}else{ //the big blind value = double the current small blind value. we know small blind field is not null
_textEditControllerBigBlind.text = (int.tryParse(_textEditControllerSmallBlind.text) * 2).toString();
**//at this point, i want a specific text input field disabled. how to do that?**
}
}
You need to toggle the value of the enabled property of TextFormField or TextField. If the enabled is false it would disable the TextFormField or TextField.
Create bool member such as bool _isTextFieldEnabled = false; in the State class of a StatefulWidget & set _isTextFieldEnabled to true when you want to disable the TextField by calling setState.
Checkout this DartPad sample I created to demonstrate this: DartPad
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.
I am trying to select contact from phone and showing it on the text field., but the text field is not showing the changed value even though the variable is changing in the log. I am using contact picker package.
Here is the variable declaration:
the code for the contact button is
Can you try this
_contactPicker.selectContact().then(
setState((){
_contact = contact;
});
);
Instead of
Contact contact = await _contactPicker.selectContact();
setState((){
_contact = contact;
});
And I am not sure about your ReusableEditText. You might need a TextEditingController if you didn't use that.
Im trying to do a register page and everything is working but the logic for the onpressed property. This is my code:
onPressed: _usernameController.text == "" || _emailController.text == "" || _passwordController.text == "" || _passController.text == "" ? null : () {
setState(() {
_isLoading = true;
});
register(_usernameController.text, _emailController.text, _passwordController.text, _passController.text);
}
the button stays null even if you fill all the required fields as if the condition remained true. I know the code is right because I have a similar logic in my login page, and also whenever I refresh with the fields already full it magically lights up the button and everything works. What could be the problem?
You can use Form widget. Form widget has onChange property also you can listen to all states. Form widget has other property, the key is validated and control your form state. Don't forget must be declared validator property.
Same example:
Full code: Form Validattor
Please make one method like below..
void _registration(){
//add register code here instead of write at onPressed event
}
and call this method in onPressed event like this...
onPressed: _registration