CHB61 / multi_select_flutter

A flexible multi select package for Flutter. Make multi select widgets the way you want.
https://pub.dev/packages/multi_select_flutter
BSD 2-Clause "Simplified" License
238 stars 223 forks source link

Unable to set initial value through api. Please provide me solution for this... #165

Open abhi22211 opened 1 year ago

abhi22211 commented 1 year ago

Here is my code.

List aList2=[]; List aList4 = []; _showAssignedArList() async { try { var response = await http.get(Uri.parse("${AppConstant.BASE_URL}vechicallist")); var data = VehicleResponse.fromJson(json.decode(response.body)); print("this is data${data}"); setState(() { aList2 = data.data!; print("This is vehicle list${aList2}"); }); } catch (error) { throw(error); } }

var _items = aList2.map((ar) => MultiSelectItem(ar, ar.vechicalNo.toString())).toList();

@override void initState() { _showAssignedArList(); super.initState(); }

Container( decoration: BoxDecoration( color: Theme.of(context).primaryColor.withOpacity(.4), border: Border.all( color: Theme.of(context).primaryColor, width: 2, ), ), child: Column( children: [ MultiSelectBottomSheetField( isDismissible: false, initialValue: aList4, initialChildSize: 0.4, listType: MultiSelectListType.CHIP, searchable: true, buttonText: Text("Vehicle Number"), title: Text("Vehicle Number"), items: _items, onConfirm: ( values) { _assignVehicle = values; }, chipDisplay: MultiSelectChipDisplay( onTap: (value) { setState(() { _assignVehicle.remove(value); }); }, ), ), _assignVehicle == null || _assignVehicle.isEmpty ? Container( padding: EdgeInsets.all(10), alignment: Alignment.centerLeft, child: Text( " ", style: TextStyle(color: Colors.black54), )) : Container(), ], ), ), This plugin is not very good for use. In plugin example it is showing to assign onChange{ value in List but it is not assigning}. From three days I'm stuck in from this issue.