I have list data and try to change the value in position [0] to be value 5.
List<String> imagesVal = ['1', '2', '3', '4'];
Then I have change function
void changeImage(id, file, mediaID) {
setState(() {
imagesVal[0] = '5';
})
print(imagesVal);
});
The result is: ['5', '2', '3', '4']
Then I have save button
Future _save() async {
print(imagesVal);
});
When tap the button, I got result still old value: ['1', '2', '3', '4']
My question, how to get the latest update value? On above example it should be get the value ['5', '2', '3', '4']
You should have declared the list inside the build method of stateful widget by mistake. Please move it outside the build method.
Related
Flutter Map
in this value of i is changing
mapList.addAll({
'item_name[]':shopping_item_name[i],
'item_description[]':shopping_quantity[i],
'item_price[]':shopping_unitPrice[i],
});
Looking for output like this
{'item_name[]': 'Arpit', 'item_name[]': 'Rnjeet', 'item_name[]': 'Prabhat', 'item_name[]': 'Rohan',
'item_description[]': '2', 'item_description[]': '3', 'item_description[]': '10', 'item_description[]': '3',
'item_price[]': '1', 'item_price[]': '1', 'item_price[]': '1', 'item_price[]': '1',}
instead of trying to set same keys in the same Map, think about making it a Map<String, List<String>> where you will hold all values with the same key on a List<String>, like this:
void main() {
final myMap = <String, List<int>>{};
addValue(myMap, 'key1', 1);
addValueToMap(myMap, 'key1', 24);
addValueToMap(myMap, 'key2', 35);
addValueToMap(myMap, 'key1', 12);
addValueToMap(myMap, 'key2', 112);
print(myMap); // {key1: [1, 24, 12], key2: [35, 112],}
}
void addValue<K, V>(Map<K, List<V>> map, K key, V value) =>
map.update(key, (list) => list..add(value), ifAbsent: () => [value]
);
I would like to convert Arabic numbers into english or force the user to enter english numbers only, so how to do so?
i.e 123 = ١٢٣ and so on.
For converting numbers you can simply write a function like this:
Map persianNumberMap = {
'۰': '0',
'۱': '1',
'۲': '2',
'۳': '3',
'۴': '4',
'۵': '5',
'۶': '6',
'۷': '7',
'۸': '8',
'۹': '9'
};
String convertPersianNumberToEnglish(String number) {
String converted = number;
persianNumberMap.forEach((key, value) => converted.replaceAll(key, value));
return converted;
}
But you can also use FilteringTextInputFormatter to restrict inputs of a TextField:
TextField(inputFormatters: [
FilteringTextInputFormatter.allow(RegExp("[0-9]")),
])
This TextField will only accept English number characters.
I can target almost all the header cells with headerCellRenderer, however when in a group the ones with red arrows are ignored:
I've tried these but nothing works:
headerGroupRenderer: () => '0',
headerGroupCellRenderer: () => '1',
groupHeaderCellRenderer: () => '2',
groupHeaderRenderer: () => '3',
What's the correct property to target those cells?
headerGroupComponent ...perhaps?
My function takes a table of the form dictionary and returns the table after applying the query which the person asked. I have several other methods but I am having trouble with the equal condition method . This is what I've tried.
class Table():
def where_con(self,table,conditions):
for condition in conditions:
if ('='in condition):
print(table.get_dict())
print(condition)
self = table.equal_condition(table,condition)
return(self)
elif('>'in condition):
new_table = table.greater_condition(table, condition)
return(self)
def equal_condition(self,table,condition):
'''(Table, string) -> Table
This Function takes in a table and a condition and applies the
condition and returns a new table with the condition applied
REQ: Table must have the contents of the condition
REQ: The condition must have proper syntax
REQ: The condition must contain the equal sign in string form
'''
number_rows = table.num_rows()
print(number_rows)
dictionary = table.get_dict()
print(dictionary)
condition = condition.split('=')
print(condition)
#new_table = Table()
# Adding Coloums Name in Self
for col in dictionary:
self.add_column({col: []})
# If the Second part is a string
if ("'" in condition[1]):
condition[1] = condition[1].strip("'")
i=0
while(i<number_rows):
print(i)
i=i+1
if (dictionary[condition[0]][i] == condition[1]):
for key in self.get_dict():
self = self.update_column(key,dictionary[key][i])
#i=i+1
else:
i=0
while(i<number_rows):
print(i)
if (dictionary[condition[0]][i] == dictionary[condition[1]][i]):
for key in self.get_dict():
self.update_column(key,dictionary[key][i])
i=i+1
return self
So when I give an input as
>>>a = Table()
>>>a.set_dict({'w.critic_rating': ['5', '5', '5', '5'], 'o.for': ['Directing', 'Acting', 'Directing', 'Acting'], 'w.title': ['Titanic', 'Titanic', 'Avatar', 'Avatar'], 'o.title': ['Avatar', 'Titanic', 'Avatar', 'Titanic'], 'w w.your_rating': ['4.5', '4.5', '5', '5'], 'w.average_rating': ['4.75', '4.75', '5', '5']})
>>>d = Table()
>>>f = where_con(a,"w.title=o.title")
4
{'o.for': ['Directing', 'Acting', 'Directing', 'Acting'], 'o.title': ['Avatar', 'Titanic', 'Avatar', 'Titanic'], 'w.critic_rating': ['5', '5', '5', '5'], 'w.your_rating': ['4.5', '4.5', '5', '5'], 'w.average_rating': ['4.75', '4.75', '5', '5'], 'w.title': ['Titanic', 'Titanic', 'Avatar', 'Avatar']}
['w.title', 'o.title']
0
Traceback (most recent call last):
Python Shell, prompt 2, line 1
File "C:\Users\Abhinav\Desktop\MAde_answer\database.py", line 205, in <module>
if (dictionary[condition[0]][i] == dictionary[condition[1]][i]):
builtins.IndexError: list index out of range
Why is this happening and how can I fix it . Any help is appreciated.
I like to use DateTime.UtcNow.ToString("yyyyMMddHHmmss") as a unique-enough salt for padding instead of a random string or GUID in tests for easier debugging and sorting. However I can't use it where validation only allows alpha character strings, e.g. a name (where 'Falsehoods Programmers Believe About Names' is ignored).
Is there a standard or a convention to encode a timestamp as a [A-Z]+ string? Preferably something more efficient than roman numerals but still human readable, i.e. not a base64-like lookup-table-based variant but a logic-based one.
Not that I know of, but if you treat A as 0 and J as 9 you can simply replace all numbers from the yyyyMMddHHmmss string.
I ended up with a lookup using a mix of leet speak and calculator spelling forgoing sorting in lieu of readability.
http://www.wikihow.com/Sample/1337-Cheat-Sheet
http://www.wikihow.com/Sample/Calculator-Letter-List
http://www.inversoft.com/blog/2013/08/28/profanity-filtering-101-character-replacements-leet-speak/
var map = new Dictionary<char, char>
{
{ '0', 'O' },
{ '1', 'I' },
{ '2', 'Z' },
{ '3', 'E' },
{ '4', 'A' },
{ '5', 'S' },
{ '6', 'G' },
{ '7', 'T' },
{ '8', 'B' },
{ '9', 'P' }
};
return string.Concat(value.Select(c => map[c]));