CoolDropdown constructor

CoolDropdown({
  1. required List dropdownList,
  2. required Function onChange,
  3. dynamic resultIcon,
  4. dynamic placeholderTS,
  5. bool dropdownItemReverse = false,
  6. bool resultReverse = false,
  7. bool resultIconRotation = true,
  8. bool isTriangle = true,
  9. bool isResultLabel = true,
  10. String placeholder = '',
  11. double resultWidth = 220,
  12. double resultHeight = 50,
  13. double dropdownWidth = 200,
  14. double dropdownHeight = 300,
  15. double dropdownItemHeight = 50,
  16. Alignment resultAlign = Alignment.centerLeft,
  17. String dropdownAlign = 'center',
  18. String triangleAlign = 'center',
  19. Alignment dropdownItemAlign = Alignment.centerLeft,
  20. MainAxisAlignment dropdownItemMainAxis = MainAxisAlignment.spaceBetween,
  21. MainAxisAlignment resultMainAxis = MainAxisAlignment.spaceBetween,
  22. EdgeInsets resultPadding = const EdgeInsets.only(left: 10, right: 10),
  23. EdgeInsets dropdownItemPadding = const EdgeInsets.only(left: 10, right: 10),
  24. EdgeInsets dropdownPadding = const EdgeInsets.only(left: 10, right: 10),
  25. EdgeInsets selectedItemPadding = const EdgeInsets.only(left: 10, right: 10),
  26. dynamic resultBD,
  27. dynamic dropdownBD,
  28. dynamic selectedItemBD,
  29. dynamic selectedItemTS,
  30. dynamic unselectedItemTS,
  31. dynamic resultTS,
  32. double labelIconGap = 10,
  33. double dropdownItemGap = 5,
  34. double dropdownItemTopGap = 10,
  35. double dropdownItemBottomGap = 10,
  36. double resultIconLeftGap = 10,
  37. double gap = 30,
  38. double triangleWidth = 20,
  39. double triangleHeight = 20,
  40. double triangleLeft = 0,
  41. bool isAnimation = true,
  42. bool isResultIconLabel = true,
  43. double resultIconRotationValue = 0.5,
  44. bool isDropdownLabel = true,
  45. dynamic defaultValue,
  46. required Key key,
})

Implementation

CoolDropdown({
  required this.dropdownList,
  required this.onChange,
  resultIcon,
  placeholderTS,
  this.dropdownItemReverse = false,
  this.resultReverse = false,
  this.resultIconRotation = true,
  this.isTriangle = true,
  this.isResultLabel = true,
  this.placeholder = '',
  this.resultWidth = 220,
  this.resultHeight = 50,
  this.dropdownWidth = 200,
  this.dropdownHeight = 300,
  this.dropdownItemHeight = 50,
  this.resultAlign = Alignment.centerLeft,
  this.dropdownAlign = 'center',
  this.triangleAlign = 'center',
  this.dropdownItemAlign = Alignment.centerLeft,
  this.dropdownItemMainAxis = MainAxisAlignment.spaceBetween,
  this.resultMainAxis = MainAxisAlignment.spaceBetween,
  this.resultPadding = const EdgeInsets.only(left: 10, right: 10),
  this.dropdownItemPadding = const EdgeInsets.only(left: 10, right: 10),
  this.dropdownPadding = const EdgeInsets.only(left: 10, right: 10),
  this.selectedItemPadding = const EdgeInsets.only(left: 10, right: 10),
  resultBD,
  dropdownBD,
  selectedItemBD,
  selectedItemTS,
  unselectedItemTS,
  resultTS,
  this.labelIconGap = 10,
  this.dropdownItemGap = 5,
  this.dropdownItemTopGap = 10,
  this.dropdownItemBottomGap = 10,
  this.resultIconLeftGap = 10,
  this.gap = 30,
  this.triangleWidth = 20,
  this.triangleHeight = 20,
  this.triangleLeft = 0,
  this.isAnimation = true,
  this.isResultIconLabel = true,
  this.resultIconRotationValue = 0.5,
  this.isDropdownLabel = true,
  defaultValue,
  required this.key,
}) {
  // 기본값 셋팅
  if (defaultValue != null) {
    this.defaultValue = defaultValue;
  } else {
    this.defaultValue = {};
  }
  // label unique 체크
  for (var i = 0; i < dropdownList.length; i++) {
    if (dropdownList[i]['label'] == null) {
      throw '"label" must be initialized.';
    }
    for (var j = 0; j < dropdownList.length; j++) {
      if (i != j) {
        if (dropdownList[i]['label'] == dropdownList[j]['label']) {
          throw 'label is duplicated. Labels have to be unique.';
        }
      }
    }
  }
  // box decoration 셋팅
  this.resultBD = resultBD ??
      BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withOpacity(0.1),
            spreadRadius: 1,
            blurRadius: 10,
            offset: Offset(0, 1), // changes position of shadow
          ),
        ],
      );
  this.dropdownBD = dropdownBD ??
      BoxDecoration(
        borderRadius: BorderRadius.circular(10),
        color: Colors.white,
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withOpacity(0.1),
            spreadRadius: 1,
            blurRadius: 10,
            offset: Offset(0, 1),
          ),
        ],
      );
  this.selectedItemBD = selectedItemBD ??
      BoxDecoration(
        color: Color(0XFFEFFAF0),
        borderRadius: BorderRadius.circular(10),
      );
  // text style 셋팅
  this.selectedItemTS =
      selectedItemTS ?? TextStyle(color: Color(0xFF6FCC76), fontSize: 20);
  this.unselectedItemTS = unselectedItemTS != null
      ? unselectedItemTS
      : TextStyle(
          fontSize: 20,
          color: Colors.black,
        );
  this.resultTS = resultTS ??
      TextStyle(
        fontSize: 20,
        color: Colors.black,
      );
  this.placeholderTS = placeholderTS ??
      TextStyle(color: Colors.grey.withOpacity(0.7), fontSize: 20);
  // Icon Container 셋팅
  this.resultIcon = resultIcon ?? Container();
}