Set clear icon of add package box

This commit is contained in:
fhkhd
2024-05-01 20:52:08 +04:30
parent cb1ef41c79
commit d1b153b9c2
3 changed files with 148 additions and 64 deletions
@@ -236,8 +236,6 @@ class _PackageAddScreenState extends State<PackageAddScreen> {
initialItemValue: packageProvider
.initialItemValue,
index: index,
// filteredItems:
// packageProvider.filteredItems!,
hasRemoveButton: packageProvider
.itemValues.length >
1
+13
View File
@@ -45,6 +45,19 @@ class PackageProvider extends ChangeNotifier {
notifyListeners();
}
bool isClear = false;
setClear(int index) {
isClear = true;
itemValues[index].clear();
notifyListeners();
}
reSetClear() {
isClear = false;
notifyListeners();
}
changeItemVal(String value, int index) {
for (var item in filteredItems!) {
if (item.udi_name == value) {
+135 -62
View File
@@ -99,72 +99,145 @@ class AddItemBox extends StatelessWidget {
width: MediaQuery.of(context).size.width -
(40 * _deviceBlockSize),
// height: 30,
child: DropdownButtonFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
left: _deviceBlockSize,
),
border: InputBorder.none,
),
iconSize: 7 * _deviceBlockSize,
icon: Icon(
FontAwesomeIcons.angleDown,
color: Colors.black,
),
isExpanded: true,
hint: Container(
// width: 100,
height: 70,
padding:
const EdgeInsets.symmetric(horizontal: 0),
child: Consumer<PackageProvider>(
builder: (context, packageProvider, _) {
return TextFormField(
controller:
packageProvider.itemValues[index],
validator: (val) {
if (val!.isEmpty) {
return 'Item required!';
}
return null;
},
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
bottom: 12,
child: Consumer<PackageProvider>(
builder: (context, packageProvider, _) {
return DropdownButtonFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
left: _deviceBlockSize,
),
border: InputBorder.none,
suffixIcon: Padding(
padding: EdgeInsets.all(8),
child: InkWell(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: iconColor,
),
child: Icon(
Icons.clear,
color: Colors.white,
),
),
isDense: true,
),
style: TextStyle(
fontWeight: FontWeight.w700,
color: Colors.black,
fontSize: 4 * _deviceBlockSize,
),
);
},
onTap: () async {
packageProvider.setClear(index);
// _key.currentState?.reset();
},
)),
),
),
isDense: true,
// selectedItemBuilder: packageProvider.itemValues[index].value,
items: vals.map((val) {
return new DropdownMenuItem<String>(
enabled: isEnabled,
value: val,
child: Container(
child: Text(
val,
style: TextStyle(
fontSize: 4 * _deviceBlockSize,
iconSize: 7 * _deviceBlockSize,
icon: Icon(
FontAwesomeIcons.angleDown,
color: Colors.black,
),
isExpanded: true,
selectedItemBuilder: (context) =>
vals.map((val) {
return packageProvider.isClear
? Container(
height: 70,
padding: const EdgeInsets.symmetric(
horizontal: 0),
child: Consumer<PackageProvider>(
builder: (context,
packageProvider, _) {
return TextFormField(
controller: packageProvider
.itemValues[index],
validator: (val) {
if (val!.isEmpty) {
return 'Item required!';
}
return null;
},
decoration: InputDecoration(
contentPadding:
EdgeInsets.only(
bottom: 12,
),
isDense: true,
),
style: TextStyle(
fontWeight: FontWeight.w700,
color: Colors.black,
fontSize:
4 * _deviceBlockSize,
),
);
},
),
)
: new DropdownMenuItem<String>(
enabled: isEnabled,
value: val,
child: Container(
child: Text(
packageProvider.isClear
? ""
: val ?? "",
style: TextStyle(
fontSize:
4 * _deviceBlockSize,
),
),
),
);
}).toList(),
hint: Container(
// width: 100,
height: 70,
padding: const EdgeInsets.symmetric(
horizontal: 0),
child: Consumer<PackageProvider>(
builder: (context, packageProvider, _) {
return TextFormField(
controller:
packageProvider.itemValues[index],
validator: (val) {
if (val!.isEmpty) {
return 'Item required!';
}
return null;
},
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
bottom: 12,
),
isDense: true,
),
style: TextStyle(
fontWeight: FontWeight.w700,
color: Colors.black,
fontSize: 4 * _deviceBlockSize,
),
);
},
),
),
isDense: true,
items: vals.map((val) {
return new DropdownMenuItem<String>(
enabled: isEnabled,
value: val,
child: Container(
child: Text(
val ?? "",
style: TextStyle(
fontSize: 4 * _deviceBlockSize,
),
),
),
),
);
}).toList(),
onChanged: (val) {
Provider.of<PackageProvider>(context,
listen: false)
.changeItemVal(val!, index);
},
),
);
}).toList(),
onChanged: (val) async {
await packageProvider.reSetClear();
await Provider.of<PackageProvider>(context,
listen: false)
.changeItemVal(val.toString()!, index);
},
);
}),
),
Spacer(),
InkWell(