You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
5.3KB

  1. import 'package:farm_tpf/custom_model/action_form/CommonData.dart';
  2. import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_dropdown_controller.dart';
  3. import 'package:farm_tpf/presentation/screens/resources/sc_common_data_helper.dart';
  4. import 'package:farm_tpf/utils/validators.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:get/get.dart';
  7. class DropdownSupplyWidget extends StatefulWidget {
  8. final String? titleName;
  9. final String condition;
  10. final String hint;
  11. final String? value;
  12. final Function(CommonData) onPressed;
  13. final String? invalidMessage;
  14. final String tag;
  15. final String tbSupply;
  16. DropdownSupplyWidget({
  17. this.titleName,
  18. required this.hint,
  19. required this.tag,
  20. this.value,
  21. required this.condition,
  22. required this.onPressed,
  23. this.invalidMessage,
  24. required this.tbSupply,
  25. });
  26. @override
  27. _DropdownSupplyWidgetState createState() => _DropdownSupplyWidgetState();
  28. }
  29. class _DropdownSupplyWidgetState extends State<DropdownSupplyWidget> {
  30. ChangeDropdownController? controller;
  31. @override
  32. void initState() {
  33. super.initState();
  34. controller = Get.put(ChangeDropdownController(), tag: widget.tag);
  35. }
  36. @override
  37. Widget build(BuildContext context) {
  38. return GetBuilder<ChangeDropdownController>(
  39. init: controller,
  40. tag: widget.tag,
  41. builder: (data) {
  42. return SizedBox(
  43. width: double.infinity,
  44. height: Validators.stringNotNullOrEmpty(widget.invalidMessage ?? '') ? 85 : 65,
  45. child: Column(
  46. crossAxisAlignment: CrossAxisAlignment.start,
  47. children: [
  48. Validators.stringNotNullOrEmpty(data?.currentData?.name ?? '')
  49. ? Text(
  50. widget.hint ?? '',
  51. style: TextStyle(
  52. color: Validators.stringNotNullOrEmpty(widget.invalidMessage ?? '') ? Colors.red : Colors.black54, fontSize: 13.0),
  53. )
  54. : Text(
  55. '',
  56. style: TextStyle(
  57. color: Validators.stringNotNullOrEmpty(widget.invalidMessage ?? '') ? Colors.red : Colors.black54, fontSize: 13.0),
  58. ),
  59. SizedBox(
  60. width: double.infinity,
  61. height: 44,
  62. child: TextButton(
  63. onPressed: () {
  64. Navigator.of(context)
  65. .push(MaterialPageRoute(
  66. builder: (_) => CommonDataHelperScreen(
  67. titleName: widget.titleName ?? '',
  68. tbSupply: widget.tbSupply ?? '',
  69. condition: widget.condition ?? '',
  70. selectedId: data?.selectedId ?? -1,
  71. currentItems: [],
  72. currentEditId: -1),
  73. fullscreenDialog: false))
  74. .then((value) {
  75. if (value != null) {
  76. var result = value as CommonData;
  77. controller?.change(result);
  78. widget.onPressed(result);
  79. }
  80. });
  81. },
  82. child: Column(
  83. crossAxisAlignment: CrossAxisAlignment.start,
  84. children: [
  85. Container(
  86. padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0, left: 0.0),
  87. decoration: BoxDecoration(
  88. border: Border(
  89. bottom: BorderSide(
  90. width: 0.5,
  91. color: Validators.stringNotNullOrEmpty(widget.invalidMessage ?? '') ? Colors.red : Colors.black54)),
  92. ),
  93. child: Row(
  94. children: [
  95. Expanded(
  96. child: Validators.stringNotNullOrEmpty(data?.currentData?.name ?? '')
  97. ? Text(data?.currentData?.name ?? '', style: TextStyle(fontSize: 16.0, color: Colors.black))
  98. : Text(widget.hint, style: TextStyle(fontSize: 16.0, color: Colors.black54)),
  99. ),
  100. Icon(
  101. Icons.arrow_drop_down,
  102. color: Colors.grey,
  103. ),
  104. ],
  105. ))
  106. ],
  107. )),
  108. ),
  109. Validators.stringNotNullOrEmpty(widget.invalidMessage ?? '')
  110. ? Text(
  111. widget.invalidMessage ?? '',
  112. style: TextStyle(fontSize: 12.0, color: Colors.red, fontWeight: FontWeight.normal),
  113. textAlign: TextAlign.left,
  114. )
  115. : SizedBox(),
  116. ],
  117. ),
  118. );
  119. });
  120. }
  121. }