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.

125 lines
4.1KB

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