This is my code:
CheckboxListTile (
value: agree,
title: Text (AppLocalizations.of(context).translate('Do you accept the terms and conditions?'),
style: TextStyle(fontSize: 18)),
onChanged: (bool value) {
setState(() {
this.agree = value;
});
},
),
The error is:
a non null string must be provided to a text widget
Try adding a fallback text in the Text widget
Text(AppLocalizations.of(context).translate('Do you accept the terms and conditions?' ?? 'Do you accept the terms and conditions?');
If you want it to be translated, you have to check your folder: assets > lang
You will see all the translations that are in your project, I have put the following in the English one:
"DoYouAcceptTheTermsAndConditions?": "Do you accept the terms and conditions?",
And in Spanish:
"DoYouAcceptTheTermsAndConditions?": "¿Aceptas los términos y condiciones?",
If you have any questions, you can ask me questions: D
EDIT: My code now it looks like this:
CheckboxListTile (
title: Text(AppLocalizations.of(context).translate('DoYouAcceptTheTermsAndConditions?'),
style: TextStyle(fontSize: 18)),
value: agree,
onChanged: (bool value) {
setState(() {
this.agree = value;
});
},
),
Related
The Question sounds dumb,
but I cant figure out how to change the style of the selected Items
in the Multiselect dependency.
My Widget looks like this:
DropDownMultiSelect(
hintStyle: const TextStyle(color: Colors.black),
selectedValues: gewaehlteArten,
whenEmpty: "",
options: arten,
onChanged: (List<String> specificArten) {
setArten(arten: specificArten);
});
What can I do?
Here an additional picture:
I want to change the color to any other except of white ;)
DropDownMultiSelect has prop called menuItembuilder and use that and you can change style based on currently selected values
DropDownMultiSelect(
hintStyle: const TextStyle(color: Colors.black),
selectedValues: gewaehlteArten,
whenEmpty: "",
options: arten,
menuItembuilder: (option){
if(gewaehlteArten.contains(option) return YOUR_SELECTED_WIDGET;
return NORMAL_WIDGET;
},
onChanged: (List<String> specificArten) {
setArten(arten: specificArten);
});
You can also use childBuilder to make menu completely custom.
This question already has answers here:
Flutter: obscureText, how to stop showing typed characters
(2 answers)
Closed last year.
I was searching a lot on the internet about how to hide password in TextFormField, the entirely one. Because obscureText doesn't hide all of it, they give a slightly every character you typed
screenshot
Is there any solution for this? Thx in advance
You need it on Android and iOs, right? Because on other platforms seems to be implemented by default like you want it.
In any case, try this:
class ObscuringTextEditingController extends TextEditingController {
ObscuringTextEditingController(String text) : super(text: text);
#override
TextSpan buildTextSpan({required BuildContext context, TextStyle? style, required bool withComposing}) {
var displayValue = '•' * value.text.length;
if (!value.composing.isValid || !withComposing) {
return TextSpan(style: style, text: displayValue);
}
final TextStyle composingStyle = style?.merge(
const TextStyle(decoration: TextDecoration.underline),
) ??
const TextStyle(decoration: TextDecoration.underline);
return TextSpan(
style: style,
children: <TextSpan>[
TextSpan(text: value.composing.textBefore(displayValue)),
TextSpan(
style: composingStyle,
text: value.composing.textInside(displayValue),
),
TextSpan(text: value.composing.textAfter(displayValue)),
],
);
}
}
Updated the original code from here
I have been trying to make an external UI that a user can use to make certain changes to a database(dynamodb) in the cloud. When I select a new value, I want it to show the change that the user wants to make, without actually changing the database. The changes are saved only when I press a button on the appbar. Also when I use setState to rebuild the button, the value doesn't change on the cloud and it also changes the value for all of the buttons in the column(works fine without a setState). The code that I have provided changes the database when I press the save icon, but the drop-down button value stays the same unless I refresh the page. I apologize if I haven't explained my issue clearly enough, this is my first time posting on Stackoverflow, and I'm still learning about how to work with flutter and aws amplify.
body: InteractiveViewer(
constrained: false,
child: DataTable(
columns: [
DataColumn(label: Text('Apt #')),
DataColumn(label: Text('Type')),
DataColumn(label: Text('Availability')),
DataColumn(label: Text('Price')),
DataColumn(label: Text('Area'))
],
rows: aprts.map<DataRow>((element) { //aprts is a list that contains apartment objects.
return DataRow(cells: [
DataCell(Text(element.aptNum.toString())),
DataCell(Text(element.type)),
DataCell(DropdownButton<String>( /// this is the part im having problems wi
value: element.availabily, // gets the value for the availability attribute for the element and stores it into value.
onChanged: (String newValue) {
availValue = newValue; //stores the newValue in a global variable that is used in a function that is used toactually make changes to the database.
tempAvail = element;
},
items: <String>['AVAILABLE', 'SOLD', 'RESERVED']
.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)), // end of problem.
DataCell(TextField(
controller: TextEditingController()
..text = element.price.toString(),
onChanged: (text) {
aptPrice = text;
tempPrice = element;
},
)),
DataCell(TextField(
controller: TextEditingController()..text = element.area,
onChanged: (text) {
aptArea = text;
tempArea = element;
},
)),
]);
}).toList()),
),
What the app looks like. After pressing the button
Use
onChanged: (String newValue) {
setState(() {
availValue = newValue;
tempAvail = element;
}
)
},
because for every change in the UI you must call setState((){})
The method 'validate' was called on null.
Receiver: null
Tried calling: validate()
I don't understand this. I thought maybe the problem was the Form isn't the root element of the class, it's not return Form(child: Column(children: [... So I tried making the Form Widget the root, it stopped the error, but didn't activate the TextFormField validator or save, it just said 'everything fine, move along'.
It's just one field I presently wish to validate. I've looked up other such queries, both the Form widget & the TextFormField have keys, so I'm stuck.
I declare the form key with final _formKeyForDeposit = GlobalKey<FormState>();
And here is the un-cooperative form:
Form(key: _formKeyForDeposit, child:
TextFormField(
controller: _controllerDefaultDeposit,
key: Key('defaultLoanDeposit'),
decoration: InputDecoration(
//icon: Icon(Icons.location_city),
labelText: 'Per item deposit',
hintText: 'Whole numbers',
suffixIcon: IconButton(
icon: Icon(Icons.clear),
onPressed: () {
_controllerDefaultDeposit.clear();
},
),
),
keyboardType: TextInputType.numberWithOptions(decimal: false, signed: false),
onSaved: (String amountStr) {
print("saving deposit");
user.defaultItemDeposit = int.parse(amountStr.trim());
},
validator: (String value) {
print(LOG + "validator called");
if(int.tryParse(value.trim()) == null) {
inputCompletionAlert += "But your default item deposit is not a number, please correct.\n";
return 'Not a £-- whole number monetary amount';
}
if(value == "" || value == "0") {
print(LOG + 'deposit validator called, should launch Dialog from here');
inputCompletionAlert += "Would you like to set a default deposit?";
return "Would you like to set a deposit?";
}
return null;
},
),
),
Have you tried building a custom validator function and then directly calling it from the validator property.
For example :-
Validator (String value) {
print(LOG + "validator called");
if(int.tryParse(value.trim()) == null) {
inputCompletionAlert += "But your default item deposit is not a number, please correct.\n";
return 'Not a £-- whole number monetary amount';
}
}
This was an incomplete question, this array of ExpansionBoxes messes up the validator:
ExpansionPanelList.radio(initialOpenPanelValue: 2,
children: [
bicyclePanel,
carPanel,
floodPanel,
diyPanel,
surplusPanel,
gardeningPanel,
ballSportsPanel,
snowSportsPanel,
waterSportsPanel,
campingPanel,
backpackingPanel,
circusPanel,
]),
I presume that when _formKeyForDeposit.currentState.validate() is called it heads down into the ExpansionPanelList and can't escape to trigger the validator of TextFormFields above it.
Since I only have 1 TextFormField outwidth the ExpansionPanelList, I've used _controllerDefaultDeposit.text to get the Deposit FormField value and manually validate it. It's a hacky solution, but it'll do for now.
When I select a value from my dropdown the hint text does not change:
String fontSizeValue;
new DropdownButton<String>(
items: new List<double>.generate(72, (i) => i + 2.0).map((double value) {
return new DropdownMenuItem<String>(
value: value.toString(),
child: new Text(value.toString()),
);
}).toList(),
onChanged: (String _) {
setState(() {
fontSize = double.parse(_);
fontSizeValue = _;
print(fontSizeValue);
});
},
value: fontSizeValue,
hint: Text('Select'),
)),
],
),
),
);
Any idea how I can get the selected value to show instead of "select"? Thanks
You did not post enough code, but I'll take a wild guess anyway, because there are a lot of questions with this problem:
Your variable String fontSizeValue; is defined locally, probably in the build function.
You have to define it in a wider scope, so it will retain it's value after another call to build that will happen when you call setState. Probably as a class member of your State class.