GetSeletItemsMap function
dynamic
GetSeletItemsMap(
- StreamController stream,
- dynamic Item, {
- dynamic firstItem,
})
Implementation
GetSeletItemsMap(StreamController stream, Item,{firstItem}) async {
if (Item["dataSrc"] != null &&
Item["dataSrc"] == "url" &&
Item["data"]["url"] != null) {
var url = Item["data"]["url"];
printO("test Url $url");
List? value = await Utils.instance.getUrlValue(url: url);
if (value != null) {
printO("test value $value");
// Future.delayed(Duration(milliseconds: 500), () {
var list=[];
if(firstItem!=null)
{
list.add(firstItem);//=<DropdownMenuItem>[firstItem];
list.addAll( value
.map((e) =>{
"value": e[Item['valueProperty']??'value'],
"text":'${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'
}
).toList());
// list.inser(0,firstItem);
stream.add(list);
return list;
}else
{
list.addAll( value
.map((e) =>{
"value": e[Item['valueProperty']??'value'],
"text":'${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'
}
));
stream.add(list);
return list;
}
// });
} else
{
RepsitoryData().getList(url: url).listen((event) {
if (event is Map<String, dynamic>) {
var list=[];
printO("${event}");
if(firstItem!=null)
{
list.add(firstItem);
list.addAll(event["value"]
.map((e) =>{
"value": e[Item['valueProperty']??'value'],
"text":'${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'
}
)
);
//list.insert(0,firstItem);
stream.add(list);
}else
{
list.addAll(event["value"]
.map((e) =>{
"value": e[Item['valueProperty']??'value'],
"text":'${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'
}
)
);
stream.add(list);
}
Utils.instance.setUrlValue(Item["data"]["url"], event["value"]);
// stream.add(DelTasks);
}else if(event is List){
var list=[];
if(firstItem!=null)
list.add(firstItem);
list.addAll( event
.map((e) =>{
"value": e[Item['valueProperty']??'value'],
"text":'${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'
}
));
// if(skipsElem!=null && skipsElem.length>0)
// {
// list.removeWhere((element) => (skipsElem as List).contains(element["value"]));
// }
stream.add(list);
Utils.instance.setUrlValue(Item["data"]["url"], event);
}
else {
printO("ONEvent ${event}");
//tasksStream.addError("Error");
stream.addError(event);
}
}, onDone: (() {
printO("ONDone IS");
//tasksStream.done;
}), onError: (err) {
printO("Error $err");
stream.addError(err);
});
}
} else {
printO("Local_data ${Item["data"]["values"]}");
var list;
// Future.delayed(Duration(milliseconds: 500), () {
if(firstItem!=null)
{
list= Item["data"]["values"]
.map((e) =>{
"value": e[Item['valueProperty']??'value'],
"text":'${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'
}
).toList();
list.insert(0,firstItem);
stream.add(list);
return list;
}else
{
printO("======================== Local_data ${Item["data"]["values"]}");
list=Item["data"]["values"]
.map((e) =>{
"value": e[Item['valueProperty']??'value'],
"text":'${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'
}
)
.toList();
stream.add(list);
printO("======================== Local_data_List ${list}");
return list;
}
//});
}
}