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.

149 lines
4.7KB

  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.animateTo(widget.initialIndex);
  31. tabbarController.addListener(() {
  32. homeTabSelected.changeTab(tabbarController.index);
  33. });
  34. }
  35. @override
  36. void dispose() {
  37. super.dispose();
  38. tabbarController.dispose();
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return Container(
  43. color: Colors.white,
  44. padding: EdgeInsets.only(top: 4, bottom: 4),
  45. child: DefaultTabController(
  46. length: 4,
  47. child: Scaffold(
  48. backgroundColor: Colors.white,
  49. appBar: PreferredSize(
  50. preferredSize: Size.fromHeight(40),
  51. child: Align(
  52. alignment: Alignment.centerLeft,
  53. child: GetBuilder<HomeTabbarSelected>(builder: (selectedTab) {
  54. return TabBar(
  55. controller: tabbarController,
  56. isScrollable: false,
  57. indicatorColor: AppColors.DEFAULT,
  58. onTap: (index) {
  59. homeTabSelected.changeTab(index);
  60. },
  61. tabs: [
  62. Container(
  63. padding: EdgeInsets.only(top: 8, bottom: 8),
  64. child: Text(
  65. 'Chỉ số',
  66. style: TextStyle(
  67. color: selectedTab.index == 0
  68. ? AppColors.DEFAULT
  69. : Colors.black,
  70. fontSize: 12),
  71. ),
  72. ),
  73. Container(
  74. padding: EdgeInsets.only(top: 8, bottom: 8),
  75. child: Text('Thông tin',
  76. style: TextStyle(
  77. color: selectedTab.index == 1
  78. ? AppColors.DEFAULT
  79. : Colors.black,
  80. fontSize: 12)),
  81. ),
  82. Container(
  83. padding: EdgeInsets.only(top: 8, bottom: 8),
  84. child: Text('Canh tác',
  85. style: TextStyle(
  86. color: selectedTab.index == 2
  87. ? AppColors.DEFAULT
  88. : Colors.black,
  89. fontSize: 12)),
  90. ),
  91. Container(
  92. padding: EdgeInsets.only(top: 8, bottom: 8),
  93. child: Text('Lịch sử',
  94. style: TextStyle(
  95. color: selectedTab.index == 3
  96. ? AppColors.DEFAULT
  97. : Colors.black,
  98. fontSize: 12)),
  99. )
  100. ],
  101. );
  102. }),
  103. ),
  104. ),
  105. body: TabBarView(
  106. controller: tabbarController,
  107. children: [
  108. PlotParameterScreen(
  109. cropId: widget.cropId,
  110. ),
  111. PlotInformationScreen(
  112. cropId: widget.cropId,
  113. ),
  114. PlotActionScreen(
  115. cropId: widget.cropId,
  116. cropCode: widget.cropCode,
  117. cropType: widget.cropType,
  118. ),
  119. PlotHistoryScreen(
  120. cropId: widget.cropId,
  121. cropCode: widget.cropCode,
  122. cropType: widget.cropType,
  123. ),
  124. ],
  125. ),
  126. ),
  127. ),
  128. );
  129. }
  130. }
  131. class HomeTabbarSelected extends GetxController {
  132. int index;
  133. void init() {
  134. index = 0;
  135. update();
  136. }
  137. void changeTab(int changeIndex) {
  138. index = changeIndex;
  139. update();
  140. }
  141. }