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.

138 lines
5.4KB

  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. @override
  26. _DropdownSupplyWidgetState createState() => _DropdownSupplyWidgetState();
  27. }
  28. class _DropdownSupplyWidgetState extends State<DropdownSupplyWidget> {
  29. ChangeDropdownController controller;
  30. @override
  31. void initState() {
  32. super.initState();
  33. controller = Get.put(ChangeDropdownController(), tag: widget.tag);
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return GetBuilder<ChangeDropdownController>(
  38. tag: widget.tag,
  39. builder: (data) {
  40. return SizedBox(
  41. width: double.infinity,
  42. height: Validators.stringNotNullOrEmpty(widget.invalidMessage)
  43. ? 85
  44. : 65,
  45. child: Column(
  46. crossAxisAlignment: CrossAxisAlignment.start,
  47. children: [
  48. Text(
  49. widget.hint ?? '',
  50. style: TextStyle(
  51. color:
  52. Validators.stringNotNullOrEmpty(widget.invalidMessage)
  53. ? Colors.red
  54. : Colors.black54,
  55. fontSize: 13.0),
  56. ),
  57. SizedBox(
  58. width: double.infinity,
  59. height: 44,
  60. child: FlatButton(
  61. padding: EdgeInsets.only(
  62. top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
  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(
  87. top: 0.0,
  88. right: 0.0,
  89. bottom: 10.5,
  90. left: 0.0),
  91. decoration: BoxDecoration(
  92. border: Border(
  93. bottom: BorderSide(
  94. width: 0.5,
  95. color: Validators.stringNotNullOrEmpty(
  96. widget.invalidMessage)
  97. ? Colors.red
  98. : Colors.black54)),
  99. ),
  100. child: Row(
  101. children: [
  102. Expanded(
  103. child: Text(
  104. data?.currentData?.name ??
  105. widget.hint,
  106. style: TextStyle(
  107. fontSize: 16.0,
  108. color: Colors.black))),
  109. Icon(
  110. Icons.arrow_drop_down,
  111. color: Colors.grey,
  112. ),
  113. ],
  114. ))
  115. ],
  116. )),
  117. ),
  118. Validators.stringNotNullOrEmpty(widget.invalidMessage)
  119. ? Text(
  120. widget.invalidMessage ?? '',
  121. style: TextStyle(
  122. fontSize: 12.0,
  123. color: Colors.red,
  124. fontWeight: FontWeight.normal),
  125. textAlign: TextAlign.left,
  126. )
  127. : SizedBox(),
  128. ],
  129. ),
  130. );
  131. });
  132. }
  133. }