adding record from one List to another List - list

In List One, I am getting some items. Each time those items are changing. Sometimes, I can get more than one record in the List.
In a second List, I would like to store all the data of List One. So, I can then display all the items of List Two.
To make it more clear.
List One = "/temp/file1.jpeg"
List Two = "/temp/file1.jpeg"
List One = "/temp/file2.jpeg"
List Two = "/temp/file1.jpeg,/temp/file2.jpeg"
I have tried this
void _openDocumentFileExplorer({fileType: FileType.custom}) async {
setState(() => _loadingPath = true);
try{
_paths = (await FilePicker.platform.pickFiles(
type: fileType,
allowMultiple: true,//_multiPick,
allowedExtensions: ['pdf']))?.files;
} on PlatformException catch (e) {
print("Unsupported operation" + e.toString());
} catch (ex) {
print('$ex');
}
if (!mounted) return;
setState(() {
_loadingPath = false;
_fileName = _paths != null ?
_paths!.map((e) => e.name).toString() : '...';
});
}
ListView.separated(
itemCount:
_paths != null && _paths!.isNotEmpty
? _paths!.length
: 1,
itemBuilder:
(BuildContext context, int index) {
final bool isMultiPath =
_paths != null && _paths!.isNotEmpty;
final String name = _paths!
.map((e) => e.name)
.toList()[index];
//filesGB store the full path + the file name
final filesGB = _paths!
.map((e) => e.path)
.toList()[index]
.toString();
print (filesGB);
_paths?.addAll(allFiles!.map((e) ));
allFiles.addAll(filesGB.toList());
allFiles.addAll(filesGB);
// allFilesV2.addAll(filesGB);
but it does not work. I am getting this error message.
"The argument type 'String' can't be assigned to the parameter type 'Iterable'"
Please, do you have any suggestion?

I think you can use SPREAD OPERATOR (...) using a triple dot for merging one array into another.
For example:
List list1= ["/temp/file1.jpeg"];
List list2 = [];
after some time
list1 = ["/temp/file2.jpeg"];
so whenever your list one change do
list2 = [...list2,...list1];
print(list2);
output: ["/temp/file1.jpeg","/temp/file2.jpeg"]
I think it would help.

Related

how could I add the elements of a List <dynamic> to a List <Object> using flutter

dart code where i try to add element in messages to finalList (Don't work)
List<Message> finalList = List(); //list where data should go
if (tmp != null) {
List<dynamic> messages = tmp["messages"]; //list where data come from
for (var element in messages) {
try {
Message eltMsg = Message.fromMap(element);
finalList.add(eltMsg);
} catch (e) {
print(e);
}
}
finalList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
}
I assume the fromMap method accepts a Map<String, dynamic>, so if you are sure that the content of tmp["messages"] actually is a map, you can do the following:
final messages = List<Map<String, dynamic>>.from(tmp["messages"] as List<dynamic>);
List<Message> finalList = messages.map((m) => Message.fromMap(m)).toList();
finalList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
As long as your implementation of Message.fromMap is correct, this should get you a list of messages.

trying to remove an item from List

I have a code working good, but i am trying to do an enhancement
https://trycf.com/gist/5fdbccd52121856991e6fe3f82307d34/lucee5?theme=monokai
in the above, i am trying if the deleted item in list is IN, it should also delete the other item starting with I letter
The code is looping for the list elements and doing a match to detect and delete the element
Source
<cfscript>
i = 'AS,AK,SK,SB,IN,IP';
Y = 'IN';
local.X = [];
listEach(I, function(value, index) {
if (!listFindNoCase(Y, value)) {
arrayAppend(X, value);
}
});
dump(x);
</cfscript>
You can do that by checking before if the list contains your element using listFindNoCase, then using listFilter to filter the items you do not want in your new list, something like this:
<cfscript>
originalList = 'AS,AK,SK,SB,IN,IP';
needle = 'IN,AS';
newList = originalList;
listEach(needle, function(needle) {
if (listFindNoCase(newList, needle)) {
newList = listFilter(newList, function(value) {
return lcase(left(value, 1)) != lcase(left(needle, 1));
});
}
});
dump(newList);
</cfscript>

Flutter: Selected value doesn't display in the dropdown

I'm populating cities name from SQLite database and trying to display as a drop down list. I make it work by following a tutorial, but having a small issue. The selected value is not displayed in dropdown, it keep displaying default hint value. However, I was able to assign and retrieve correct selected value.
Here is my code:
cities.dart
class Cities {
int id;
String name;
Cities(this.id, this.name);
Cities.fromMap(Map<String, dynamic> json) {
this.id = json["id"];
this.name = json["name"];
}
Map<String, dynamic> toMap() => {
'id': null,
'name': name,
};
}
Function that retrieve and returns value from db:
Future<List<Cities>> getCitiesList() async {
Database db = await instance.database;
final citiesData = await db.query('cities');
if (citiesData.length == 0) return null;
List<Cities> citiesList = citiesData.map((item) {
return Cities.fromMap(item);
}).toList();
return citiesList;
}
The code which builds drop down, inside Widget build:
//these are defined above in the code
Cities _city;
final databaseHelper = DatabaseHelper.instance;
FutureBuilder<List<Cities>>(
future: databaseHelper.getCitiesList(),
builder: (BuildContext context, AsyncSnapshot<List<Cities>> snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();
return DropdownButton<Cities>(
items: snapshot.data
.map((city) => DropdownMenuItem<Cities>(
child: Text(city.name),
value: city,
))
.toList(),
onChanged: (Cities value) {
setState(() {
_city = value;
});
},
isExpanded: true,
// value: _city, //uncommenting this line breaks the layout
hint: Text('Select City'),
);
},
),
Error in the console:
'package:flutter/src/material/dropdown.dart': Failed assertion: line 620 pos 15: 'items == null || items.isEmpty || value == null || items.where((DropdownMenuItem<T> item) => item.value == value).length == 1': is not true.
Un-commenting this value: _city, add same error in display (displays error 8 times, instead of dropdown list).
Questions:
How can I fix this issue?
How can I set default value from the list? (which will be selected by default)
You can do it in simple way, just create a simple list of strings and pass that list to dropdown menu.
Here's how:
Update your getCitiesList() function:
Future<List<String>> getCitiesList() async {
Database db = await instance.database;
final citiesData = await db.query(tblCities);
if (citiesData.length == 0) return null;
return citiesData.map((Map<String, dynamic> row) {
return row["name"] as String;
}).toList();
}
Add this inside your form page:
//initialize these at top
List<String> _citiesList = <String>[];
String _city;
void _getCitiesList() async {
final List<String> _list = await databaseHelper.getCitiesList();
setState(() {
_citiesList = _list;
});
}
Call _getCitiesList(); inside initState().
Add this inside your build method:
DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: _city,
items: _citiesList.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String newValue) {
setState(() {
_city = newValue;
});
},
)),

Refetch queries with any combination of parameters

I have faced with a problem when refetching queries after mutation. If query has no parameters thats ok, but if query has several parameters, and different pages uses different of them. For example, GET_ITEMS query accepts parameters: userId, companyId, categoryId. How can I say to Apollo to refetch all this queries with any combination of parameters?
It seem there is no way I can make it now with Apollo Client. So I had to save the parameters of all GET_ITEMS calls from all pages, and then transfer the saved parameters to the refetchQueries mutation method. The code turned out like this:
ItemsContext.js
const ItemsContext = React.createContext({
cachedQueryVars: [],
});
ItemsList.js
...
render() {
...
return <ItemsContext.Consumer>{({cachedQueryVars}) => {
cachedQueryVars.push(variables);
return <Query query={GET_ITEMS} variables={variables} >
...
ItemEdit.js
...
render() {
...
return <ItemsContext.Consumer>{({cachedQueryVars}) =>
<Mutation mutation={UPDATE_ITEM_MUTATION}
refetchQueries={({data}) => this.handleRefetchQueries(data.updateItem, cachedQueryVars)}
...
}
handleRefetchQueries(newItem, cachedItemsQueryVars) {
let result = [];
let filtered = null;
if(this.state.oldCategoryId != newItem.category.id) {
filtered = cachedItemsQueryVars.filter(v => v.categoryId == this.state.oldCategoryId);
result = this.concatItemQueryVars(result, filtered);
filtered = cachedItemsQueryVars.filter(v => v.categoryId == newItem.category.id);
result = this.concatItemQueryVars(result, filtered);
}
if(this.state.oldCompanyId != newItem.company.id) {
filtered = cachedItemsQueryVars.filter(v => v.companyId == this.state.oldCompanyId);
result = this.concatItemQueryVars(result, filtered);
filtered = cachedItemsQueryVars.filter(v => v.companyId == newItem.company.id);
result = this.concatItemQueryVars(result, filtered);
}
...
return result;
}
concatItemQueryVars(result, filtered) {
return result.concat(filtered.map(v => ({
query: GET_ITEMS,
variables: v
})));
}

How to add dynamic values to field injections list with custom trigger to camunda properties panel?

I have two questions here
Is it possible to add dynamic lists values to field injection list input ?
Can I create a trigger for this so this can be initiated from any other input selection say a class selection will populate all fields
I was just looking into FieldInjection.js whether that can be extented for the same
Can someone please provide a hint or direction for this ?
Thanks.
For anyone interested in the answer, I was able to achieve the above goal by changing the set function of the Java Class select input as folllowing
few imports
var extensionElementsHelper = require('../../../../helper/ExtensionElementsHelper'),
elementHelper = require('../../../../helper/ElementHelper')
var CAMUNDA_FIELD_EXTENSION_ELEMENT = 'camunda:Field';
function getExtensionFields(bo) {
return bo && extensionElementsHelper.getExtensionElements(bo, CAMUNDA_FIELD_EXTENSION_ELEMENT) || [];
}
then changing the set function to create extension element and push the field values as :
set: function(element, values, node) {
var bo = getBusinessObject(element);
var type = getImplementationType(element);
var attr = getAttribute(type);
var prop = {}
var commands = [];
prop[attr] = values.delegate || '';
var extensionElements = getExtensionFields(bo);
//remove any extension elements existing before
extensionElements.forEach(function(ele){
commands.push(extensionElementsHelper.removeEntry(getBusinessObject(element), element, ele));
});
if(prop[attr] !== ""){
var extensionElements = elementHelper.createElement('bpmn:ExtensionElements', { values: [] }, bo, bpmnFactory);
commands.push(cmdHelper.updateBusinessObject(element, bo, { extensionElements: extensionElements }));
var arrProperties = ["private org.camunda.bpm.engine.delegate.Expression com.cfe.extensions.SampleJavaDelegate.varOne","private org.camunda.bpm.engine.delegate.Expression com.cfe.extensions.SampleJavaDelegate.varTwo"]
var newFieldElem = "";
arrProperties.forEach(function(prop){
var eachProp = {
name:"",
string:"",
expression:""
}
var type = prop.split(" ")[1].split(".").reverse()[0];
var val = prop.split(" ")[2].split(".").reverse()[0];
eachProp.name = val;
if( type == "String"){
eachProp.string = "${" + val +" }"
}else if( type == "Expression"){
eachProp.expression = "${" + val +" }"
}
newFieldElem = elementHelper.createElement(CAMUNDA_FIELD_EXTENSION_ELEMENT, eachProp, extensionElements, bpmnFactory);
commands.push(cmdHelper.addElementsTolist(element, extensionElements, 'values', [ newFieldElem ]));
});
}
commands.push(cmdHelper.updateBusinessObject(element, bo, prop));
return commands;
}
Cheers !.