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.

136 lines
4.5KB

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