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.

153 lines
6.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. @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. Validators.stringNotNullOrEmpty(data?.currentData?.name)
  49. ? Text(
  50. widget.hint ?? '',
  51. style: TextStyle(
  52. color: Validators.stringNotNullOrEmpty(
  53. widget.invalidMessage)
  54. ? Colors.red
  55. : Colors.black54,
  56. fontSize: 13.0),
  57. )
  58. : Text(
  59. '',
  60. style: TextStyle(
  61. color: Validators.stringNotNullOrEmpty(
  62. widget.invalidMessage)
  63. ? Colors.red
  64. : Colors.black54,
  65. fontSize: 13.0),
  66. ),
  67. SizedBox(
  68. width: double.infinity,
  69. height: 44,
  70. child: FlatButton(
  71. padding: EdgeInsets.only(
  72. top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
  73. onPressed: () {
  74. Navigator.of(context)
  75. .push(MaterialPageRoute(
  76. builder: (_) => CommonDataHelperScreen(
  77. titleName: widget.titleName ?? '',
  78. tbSupply: widget.tbSupply ?? '',
  79. condition: widget.condition ?? '',
  80. selectedId: data?.selectedId ?? -1,
  81. currentItems: [],
  82. currentEditId: -1),
  83. fullscreenDialog: false))
  84. .then((value) {
  85. if (value != null) {
  86. var result = value as CommonData;
  87. controller?.change(result);
  88. widget.onPressed(result);
  89. }
  90. });
  91. },
  92. child: Column(
  93. crossAxisAlignment: CrossAxisAlignment.start,
  94. children: [
  95. Container(
  96. padding: EdgeInsets.only(
  97. top: 0.0,
  98. right: 0.0,
  99. bottom: 10.5,
  100. left: 0.0),
  101. decoration: BoxDecoration(
  102. border: Border(
  103. bottom: BorderSide(
  104. width: 0.5,
  105. color: Validators.stringNotNullOrEmpty(
  106. widget.invalidMessage)
  107. ? Colors.red
  108. : Colors.black54)),
  109. ),
  110. child: Row(
  111. children: [
  112. Expanded(
  113. child: Validators.stringNotNullOrEmpty(
  114. data?.currentData?.name)
  115. ? Text(data?.currentData?.name,
  116. style: TextStyle(
  117. fontSize: 16.0,
  118. color: Colors.black))
  119. : Text(widget.hint,
  120. style: TextStyle(
  121. fontSize: 16.0,
  122. color: Colors.black54)),
  123. ),
  124. Icon(
  125. Icons.arrow_drop_down,
  126. color: Colors.grey,
  127. ),
  128. ],
  129. ))
  130. ],
  131. )),
  132. ),
  133. Validators.stringNotNullOrEmpty(widget.invalidMessage)
  134. ? Text(
  135. widget.invalidMessage ?? '',
  136. style: TextStyle(
  137. fontSize: 12.0,
  138. color: Colors.red,
  139. fontWeight: FontWeight.normal),
  140. textAlign: TextAlign.left,
  141. )
  142. : SizedBox(),
  143. ],
  144. ),
  145. );
  146. });
  147. }
  148. }