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.

148 lines
4.6KB

  1. import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_history.dart';
  2. import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_parameter.dart';
  3. import 'package:farm_tpf/utils/const_color.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get/get.dart';
  6. import 'sc_plot_action.dart';
  7. import 'sc_plot_information.dart';
  8. class HomeTabbarWidget extends StatefulWidget {
  9. int cropId;
  10. String cropCode;
  11. int cropType;
  12. int initialIndex;
  13. HomeTabbarWidget(
  14. {this.cropId,
  15. this.initialIndex = 0,
  16. this.cropCode,
  17. @required this.cropType});
  18. @override
  19. _HomeTabbarWidgetState createState() => _HomeTabbarWidgetState();
  20. }
  21. class _HomeTabbarWidgetState extends State<HomeTabbarWidget>
  22. with TickerProviderStateMixin {
  23. TabController tabbarController;
  24. final homeTabSelected = Get.put(HomeTabbarSelected());
  25. @override
  26. void initState() {
  27. super.initState();
  28. homeTabSelected.init();
  29. tabbarController = TabController(vsync: this, length: 4);
  30. tabbarController.addListener(() {
  31. homeTabSelected.changeTab(tabbarController.index);
  32. });
  33. }
  34. @override
  35. void dispose() {
  36. super.dispose();
  37. tabbarController.dispose();
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. return Container(
  42. color: Colors.white,
  43. padding: EdgeInsets.only(top: 4, bottom: 4),
  44. child: DefaultTabController(
  45. length: 4,
  46. child: Scaffold(
  47. backgroundColor: Colors.white,
  48. appBar: PreferredSize(
  49. preferredSize: Size.fromHeight(40),
  50. child: Align(
  51. alignment: Alignment.centerLeft,
  52. child: GetBuilder<HomeTabbarSelected>(builder: (selectedTab) {
  53. return TabBar(
  54. controller: tabbarController,
  55. isScrollable: false,
  56. indicatorColor: AppColors.DEFAULT,
  57. onTap: (index) {
  58. homeTabSelected.changeTab(index);
  59. },
  60. tabs: [
  61. Container(
  62. padding: EdgeInsets.only(top: 8, bottom: 8),
  63. child: Text(
  64. 'Chỉ số',
  65. style: TextStyle(
  66. color: selectedTab.index == 0
  67. ? AppColors.DEFAULT
  68. : Colors.black,
  69. fontSize: 12),
  70. ),
  71. ),
  72. Container(
  73. padding: EdgeInsets.only(top: 8, bottom: 8),
  74. child: Text('Thông tin',
  75. style: TextStyle(
  76. color: selectedTab.index == 1
  77. ? AppColors.DEFAULT
  78. : Colors.black,
  79. fontSize: 12)),
  80. ),
  81. Container(
  82. padding: EdgeInsets.only(top: 8, bottom: 8),
  83. child: Text('Canh tác',
  84. style: TextStyle(
  85. color: selectedTab.index == 2
  86. ? AppColors.DEFAULT
  87. : Colors.black,
  88. fontSize: 12)),
  89. ),
  90. Container(
  91. padding: EdgeInsets.only(top: 8, bottom: 8),
  92. child: Text('Lịch sử',
  93. style: TextStyle(
  94. color: selectedTab.index == 3
  95. ? AppColors.DEFAULT
  96. : Colors.black,
  97. fontSize: 12)),
  98. )
  99. ],
  100. );
  101. }),
  102. ),
  103. ),
  104. body: TabBarView(
  105. controller: tabbarController,
  106. children: [
  107. PlotParameterScreen(
  108. cropId: widget.cropId,
  109. ),
  110. PlotInformationScreen(
  111. cropId: widget.cropId,
  112. ),
  113. PlotActionScreen(
  114. cropId: widget.cropId,
  115. cropCode: widget.cropCode,
  116. cropType: widget.cropType,
  117. ),
  118. PlotHistoryScreen(
  119. cropId: widget.cropId,
  120. cropCode: widget.cropCode,
  121. cropType: widget.cropType,
  122. ),
  123. ],
  124. ),
  125. ),
  126. ),
  127. );
  128. }
  129. }
  130. class HomeTabbarSelected extends GetxController {
  131. int index;
  132. void init() {
  133. index = 0;
  134. update();
  135. }
  136. void changeTab(int changeIndex) {
  137. index = changeIndex;
  138. update();
  139. }
  140. }