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.

140 lines
4.3KB

  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. ),
  70. ),
  71. Container(
  72. padding: EdgeInsets.only(top: 8, bottom: 8),
  73. child: Text('Thông tin',
  74. style: TextStyle(
  75. color: selectedTab.index == 1
  76. ? AppColors.DEFAULT
  77. : Colors.black)),
  78. ),
  79. Container(
  80. padding: EdgeInsets.only(top: 8, bottom: 8),
  81. child: Text('Canh tác',
  82. style: TextStyle(
  83. color: selectedTab.index == 2
  84. ? AppColors.DEFAULT
  85. : Colors.black)),
  86. ),
  87. Container(
  88. padding: EdgeInsets.only(top: 8, bottom: 8),
  89. child: Text('Lịch sử',
  90. style: TextStyle(
  91. color: selectedTab.index == 3
  92. ? AppColors.DEFAULT
  93. : Colors.black)),
  94. )
  95. ],
  96. );
  97. }),
  98. ),
  99. ),
  100. body: TabBarView(
  101. controller: tabbarController,
  102. children: [
  103. PlotParameterScreen(
  104. cropId: widget.cropId,
  105. ),
  106. PlotInformationScreen(
  107. cropId: widget.cropId,
  108. ),
  109. PlotActionScreen(
  110. cropId: widget.cropId,
  111. cropCode: widget.cropCode,
  112. cropType: widget.cropType,
  113. ),
  114. PlotHistoryScreen(),
  115. ],
  116. ),
  117. ),
  118. ),
  119. );
  120. }
  121. }
  122. class HomeTabbarSelected extends GetxController {
  123. int index;
  124. void init() {
  125. index = 0;
  126. update();
  127. }
  128. void changeTab(int changeIndex) {
  129. index = changeIndex;
  130. update();
  131. }
  132. }