SelectWithOnChange1 function
Widget
SelectWithOnChange1(
- dynamic selectStream,
- dynamic Item,
- Map<String, dynamic> map, {
- dynamic onchange,
- dynamic row = '',
- dynamic width = 400,
- dynamic height,
- dynamic firstItem,
- dynamic enable,
})
Implementation
Widget SelectWithOnChange1(selectStream,Item, Map<String, dynamic> map,
{onchange, row= '', width= 400, height, firstItem,enable}) {
//StreamController selectStream = new StreamController.broadcast();
var listMap=[];
selectStream.stream.listen((data){
if(data !=null)
listMap=data;
});
/// Future.delayed(Duration(seconds: 1)).then((value){
// GetSeletItemsMap(selectStream, Item,firstItem: firstItem);
// },);
printO("Contains ${Item["key"]} ${map.containsKey(Item["key"])}");
return StreamBuilder(
stream: selectStream.stream,
builder: (context, AsyncSnapshot snapshot) {
// if(firstItem!=null && !(snapshot.data as List<DropdownMenuItem>).contains(firstItem))
// (snapshot.data as List<DropdownMenuItem>).insert(0,firstItem);
printO(" ==================== StreamBuilder ${Item["key"]} ${map[Item["key"]]}======== ${snapshot.data}");
return Padding(
padding: const EdgeInsets.only(left: 8, right: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
flex: 1,
fit: FlexFit.loose,
child: Text(Item["label"])),
const SizedBox(height: 5),
StatefulBuilder(
builder: (context,setStateWidget) {
return SearchFieldSelect(
hint:Item['placeholder']??Item["label"] ,//labelText: Item["label"],
suffixIcon: Icon(Icons.arrow_drop_down_circle),
items:snapshot.hasData?(snapshot.data).map<DropItem>((e)=>DropItem(text:e['text'],value: e['value'] )).toList():[],
isMultiple:Item["multiple"]??false,
onChanged: Item["multiple"]==null || Item["multiple"]==false? (value){
setStateWidget(() => map[Item["key"]]=value.value);
}:null,
onChangedMulti: Item["multiple"]!=null && Item["multiple"]==true? (values){
setStateWidget(() => map[Item["key"]]=values.map((e)=>e.value).toList());
print('=============== list select ${map[Item["key"]]}');
}:null,
value: Item["multiple"]==null || Item["multiple"]==false? map[Item["key"]]: null ,
values:Item["multiple"]!=null && Item["multiple"]==true? map[Item["key"]]:null ,
readOnly: enable,
validator: (v){
if (Item['validate'] != null &&
Item['validate']['required'] != null &&
Item['validate']['required'] &&( map[Item["key"]]==null || map[Item["key"]].isEmpty ) )
{ return Item['validate']['customMessage']??'Field is Required';}
return null;
}
);
}
)
// FormBuilderDropdown<Object?>(
// //enabled: true,
// enabled: !enable,
// name: Item["key"],
// initialValue:
// map.containsKey(Item["key"]) ? map[Item["key"]] : null,
// onSaved: (value) {
// if(value!=null)
// map[Item["key"]] = value;
// },
// decoration: InputDecoration(
// fillColor: Color(0xfff0f0f5),
// suffixIcon: InkWell(
// child: Icon(
// Icons.refresh,
// color: ThemeApp.primaryColor,
// ),
// onTap: () {
// GetSeletItemsMap(selectStream, Item);
// },
// ),
// labelText: Item["label"],
// border: OutlineInputBorder(
// borderSide:
// BorderSide(color: Color(0xfff0f0f5), width: .5),
// borderRadius: BorderRadius.all(Radius.circular(12)))),
// items: snapshot.hasData?(snapshot.data)
// .map<DropdownMenuItem<Object?>>((e)=> DropdownMenuItem<Object?>(child: Text('${e['text']}'),value:e['value'] )).toList()
// // [
// // //if(Item)
// // for (DropdownMenuItem<String> list in (snapshot.data as List<DropdownMenuItem<String>>))
// // //for( snapshot.data in item)
// // list,
// // ]
// :listMap!=null?(listMap)
// .map<DropdownMenuItem<Object?>>((e)=> DropdownMenuItem<Object?>(child: Text('${e['text']}'),value:e['value'] )).toList()
// :[
// // DropdownMenuItem(child: Text('tess'),value:1)
// ],
// validator: FormBuilderValidators.compose([
// if (Item['validate'] != null &&
// Item['validate']['required'] != null &&
// Item['validate']['required'])
// FormBuilderValidators.required(errorText: Item['validate']['customMessage']??'Field is Required'),
// ]),
// onChanged: onchange,
// ),
],
),
);
});
}