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.

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