GetSeletItems function

dynamic GetSeletItems(
  1. dynamic stream,
  2. dynamic Item, {
  3. dynamic firstItem,
})

Implementation

GetSeletItems(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=<DropdownMenuItem>[];
        if(firstItem!=null)
        {

           list.add(firstItem);//=<DropdownMenuItem>[firstItem];

          list.addAll( value
              .map<DropdownMenuItem>((e) => DropdownMenuItem(
            value: e[Item['valueProperty']??Item['value']],
            child:
            Text('${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'),
          )));
         // list.inser(0,firstItem);
          stream.add(list);

          return list;

        }else
        {

            list.addAll( value
                .map<DropdownMenuItem>((e) => DropdownMenuItem(
              value: e[Item['valueProperty']??Item['value']],
              child:
                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=<DropdownMenuItem>[];
          printO("${event}");
          if(firstItem!=null)
            {
               list.add(firstItem);
              list.addAll(event["value"]
                  .map<DropdownMenuItem>((e) => DropdownMenuItem(
               value: e[Item['valueProperty']??Item['value']],
               child:
               Text('${Item['template']!=null?e[getNamepropertyFromTemp(Item['template'])]:e['label']}'),
             )));
             //list.insert(0,firstItem);
             stream.add(list);


            }else
          {

                list.addAll(event["value"]
                  .map<DropdownMenuItem>((e) => DropdownMenuItem(
                    value: e[Item['valueProperty']??Item['value']],
                    child:
                    Text('${e[getNamepropertyFromTemp(Item['template'])]}'),
                  )));
                stream.add(list);


              }
          Utils.instance.setUrlValue(Item["data"]["url"], event["value"]);
          //  stream.add(DelTasks);
        }else if(event is List){

          var list=<DropdownMenuItem>[];
            if(firstItem!=null)
             list.add(firstItem);

            list.addAll( event
                .map<DropdownMenuItem>((e) => DropdownMenuItem(
                    value: e[Item['valueProperty']??Item['value']],
                    child:
                    Text('${e[getNamepropertyFromTemp(Item['template'])]}'),
                  ))
            );

            //  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<DropdownMenuItem>((e) => DropdownMenuItem(
          value: Item['valueProperty']??'value',
          child: Text('${Item['template']!=null? e[getNamepropertyFromTemp(Item['template'])]:e['label']}'),
        )).toList();
        list.insert(0,firstItem);
        stream.add(list);
        return list;

      }else
      {
        list=Item["data"]["values"]
          .map<DropdownMenuItem>((e) => DropdownMenuItem(
                value: Item['valueProperty']??'value',
                child: Text('${Item['template']!=null? e[getNamepropertyFromTemp(Item['template'])]:e['label']}'),
                  ))
              .toList();
            stream.add(list);

            return list;

     }
    //});
  }
}