do like this term : just do a trinary statement to the items array like this
DropdownButtonFormField<String>(
dropdownColor: Colors.black,
style: TextStyle(
color:
Colors.white), // Text color
decoration: InputDecoration(
labelStyle:
TextStyle(color: Colors.white),
labelText: "اختر ",
border: OutlineInputBorder(),
),
//van or sedan pickup_truck coupe mini_van cross_over city_car
items: useOtherCar == true
? [
DropdownMenuItem<String>(
value: DriversCarCubit.get(
context)
.CarTypeController
.text,
child: Text(
DriversCarCubit.get(
context)
.CarTypeController
.text,
style: TextStyle(
color: Colors.white),
),
)
]
: [
'van',
'sedan',
'pickup_truck',
'coupe',
'mini_van',
'cross_over',
'city_car'
].map((String value) {
return DropdownMenuItem<
String>(
value: value,
child: Text(
value,
style: TextStyle(
color: Colors.white),
),
);
}).toList(),
value: DriversCarCubit.get(context)
.CarTypeController
.text ??
'sedan',
onChanged: (newValue) {
setState(() {
DriversCarCubit.get(context)
.CarTypeController
.text = newValue.toString();
});
},
),