diff --git a/lib/pages/PackagePages/package_add_screen.dart b/lib/pages/PackagePages/package_add_screen.dart index 240ab75..0b45afe 100755 --- a/lib/pages/PackagePages/package_add_screen.dart +++ b/lib/pages/PackagePages/package_add_screen.dart @@ -236,8 +236,6 @@ class _PackageAddScreenState extends State { initialItemValue: packageProvider .initialItemValue, index: index, - // filteredItems: - // packageProvider.filteredItems!, hasRemoveButton: packageProvider .itemValues.length > 1 diff --git a/lib/providers/packages.dart b/lib/providers/packages.dart index d64a090..0351b6e 100755 --- a/lib/providers/packages.dart +++ b/lib/providers/packages.dart @@ -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) { diff --git a/lib/widgets/PackageScreens/Add/add_item_box.dart b/lib/widgets/PackageScreens/Add/add_item_box.dart index ac40510..db376a9 100755 --- a/lib/widgets/PackageScreens/Add/add_item_box.dart +++ b/lib/widgets/PackageScreens/Add/add_item_box.dart @@ -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( - 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( + 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( - 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( + 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( + 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( + 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( + enabled: isEnabled, + value: val, + child: Container( + child: Text( + val ?? "", + style: TextStyle( + fontSize: 4 * _deviceBlockSize, + ), ), ), - ), - ); - }).toList(), - onChanged: (val) { - Provider.of(context, - listen: false) - .changeItemVal(val!, index); - }, - ), + ); + }).toList(), + onChanged: (val) async { + await packageProvider.reSetClear(); + await Provider.of(context, + listen: false) + .changeItemVal(val.toString()!, index); + }, + ); + }), ), Spacer(), InkWell(