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: packageProvider
.initialItemValue, .initialItemValue,
index: index, index: index,
// filteredItems:
// packageProvider.filteredItems!,
hasRemoveButton: packageProvider hasRemoveButton: packageProvider
.itemValues.length > .itemValues.length >
1 1
+13
View File
@@ -45,6 +45,19 @@ class PackageProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
bool isClear = false;
setClear(int index) {
isClear = true;
itemValues[index].clear();
notifyListeners();
}
reSetClear() {
isClear = false;
notifyListeners();
}
changeItemVal(String value, int index) { changeItemVal(String value, int index) {
for (var item in filteredItems!) { for (var item in filteredItems!) {
if (item.udi_name == value) { if (item.udi_name == value) {
+135 -62
View File
@@ -99,72 +99,145 @@ class AddItemBox extends StatelessWidget {
width: MediaQuery.of(context).size.width - width: MediaQuery.of(context).size.width -
(40 * _deviceBlockSize), (40 * _deviceBlockSize),
// height: 30, // height: 30,
child: DropdownButtonFormField( child: Consumer<PackageProvider>(
decoration: InputDecoration( builder: (context, packageProvider, _) {
contentPadding: EdgeInsets.only( return DropdownButtonFormField(
left: _deviceBlockSize, decoration: InputDecoration(
), contentPadding: EdgeInsets.only(
border: InputBorder.none, left: _deviceBlockSize,
), ),
iconSize: 7 * _deviceBlockSize, border: InputBorder.none,
icon: Icon( suffixIcon: Padding(
FontAwesomeIcons.angleDown, padding: EdgeInsets.all(8),
color: Colors.black, child: InkWell(
), child: Container(
isExpanded: true, decoration: BoxDecoration(
hint: Container( shape: BoxShape.circle,
// width: 100, color: iconColor,
height: 70, ),
padding: child: Icon(
const EdgeInsets.symmetric(horizontal: 0), Icons.clear,
child: Consumer<PackageProvider>( color: Colors.white,
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, onTap: () async {
), packageProvider.setClear(index);
style: TextStyle( // _key.currentState?.reset();
fontWeight: FontWeight.w700, },
color: Colors.black, )),
fontSize: 4 * _deviceBlockSize,
),
);
},
), ),
), iconSize: 7 * _deviceBlockSize,
isDense: true, icon: Icon(
// selectedItemBuilder: packageProvider.itemValues[index].value, FontAwesomeIcons.angleDown,
items: vals.map((val) { color: Colors.black,
return new DropdownMenuItem<String>( ),
enabled: isEnabled, isExpanded: true,
value: val, selectedItemBuilder: (context) =>
child: Container( vals.map((val) {
child: Text( return packageProvider.isClear
val, ? Container(
style: TextStyle( height: 70,
fontSize: 4 * _deviceBlockSize, 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(),
}).toList(), onChanged: (val) async {
onChanged: (val) { await packageProvider.reSetClear();
Provider.of<PackageProvider>(context, await Provider.of<PackageProvider>(context,
listen: false) listen: false)
.changeItemVal(val!, index); .changeItemVal(val.toString()!, index);
}, },
), );
}),
), ),
Spacer(), Spacer(),
InkWell( InkWell(