'why in DropdownButtonFormField item my CupertinoSwitch value doesn't change in flutter
i'm using provider package for my states i have CupertinoSwitch in my DropdownMenuItem when switch CupertinoSwitch and data change when close DropdownMenuItem data changed but when DropdownMenuItem is open no changes in CupertinoSwitch value this is my widget for select
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../providers/store.dart';
class FILTER_SELECT extends StatelessWidget {
@override
Widget build(BuildContext context) {
final storeFunc = Provider.of<Barbers>(context);
return Directionality(
textDirection: TextDirection.ltr,
child: Container(
child: Column(
children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
Center(
child: Container(
width: MediaQuery.of(context).size.width > 600
? 290
: MediaQuery.of(context).size.width / 2.1,
child: Column(
children: [
Text(
"برند",
style: TextStyle(fontSize: 12),
),
SizedBox(
height: 10,
),
DropdownButtonFormField<dynamic>(
focusColor: Colors.white,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
isExpanded: true,
hint: Text(
"برند",
style: TextStyle(fontSize: 12, fontFamily: "Shabnam"),
),
icon: const Icon(
Icons.arrow_drop_down,
color: Colors.black45,
),
iconSize: 20,
items: storeFunc.selectedBrandArray
.map((item) => DropdownMenuItem<dynamic>(
value: item,
child: Directionality(
textDirection: TextDirection.rtl,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: MediaQuery.of(context)
.size
.width >
400
? Text(
"${item["english"]}",
overflow:
TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 10,
fontFamily: "Shabnam",
color: Colors.grey),
)
: SizedBox(
width: 1,
)),
Expanded(
child: Text(
" ${item["brandName"]}",
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 12,
fontFamily: "Shabnam"),
),
),
Expanded(
child: Transform.scale(
scale: 0.6,
child: CupertinoSwitch(
value: item["selected"],
onChanged: (_) {
"here is function to change selected item to true of false "
},
),
),
),
],
),
)))
.toList(),
onChanged: (select) {
print(select);
// storeFunc.changeBrand(select);
},
value: storeFunc.selectedBrandArray[0],
),
],
),
),
),
])
],
),
),
);
}
}
and this is my state
List<dynamic> _selectedBrandArray = [
{"brandName": "الارو", "english": "Elaro", "selected": false},
{"brandName": "اسنس", "english": "Essence", "selected": true},
{"brandName": "آردن", "english": "Ardene", "selected": false},
{"brandName": "این لی", "english": "Inlay", "selected": false},
]
again data will change but not when DropdownMenuItem is open and value of CupertinoSwitch doesn't change in ui
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|