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.

150 lines
5.7KB

  1. import 'package:farm_tpf/presentation/screens/account/sc_account.dart';
  2. import 'package:farm_tpf/presentation/screens/control_device/sc_control_device.dart';
  3. import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart';
  4. import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart';
  5. import 'package:farm_tpf/utils/const_color.dart';
  6. import 'package:farm_tpf/utils/const_icons.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_svg/flutter_svg.dart';
  9. import 'package:get/get.dart';
  10. class TabbarScreen extends StatefulWidget {
  11. static Route route() {
  12. return MaterialPageRoute<void>(builder: (_) => TabbarScreen());
  13. }
  14. @override
  15. _TabbarScreenState createState() => _TabbarScreenState();
  16. }
  17. class _TabbarScreenState extends State<TabbarScreen> {
  18. final changeTabbar = Get.put(TabbarSelected());
  19. List<TabbarItem> itemsTabbar = [
  20. TabbarItem(
  21. icon: AppIcons.icPlot, title: 'Lô trồng', index: TabBarIndex.plot),
  22. TabbarItem(
  23. icon: AppIcons.icDevice, title: 'Thiết bị', index: TabBarIndex.device),
  24. TabbarItem(icon: AppIcons.icQr, title: 'Quét QR', index: TabBarIndex.qr),
  25. TabbarItem(
  26. icon: AppIcons.icNotification,
  27. title: 'Thông báo',
  28. index: TabBarIndex.notification),
  29. TabbarItem(
  30. icon: AppIcons.icPerson, title: 'Cá nhân', index: TabBarIndex.account)
  31. ];
  32. @override
  33. void initState() {
  34. super.initState();
  35. changeTabbar.initValue();
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Container(
  40. color: Colors.white,
  41. child: SafeArea(
  42. top: false,
  43. bottom: true,
  44. child: Scaffold(
  45. body: GetBuilder<TabbarSelected>(builder: (tabbarSelected) {
  46. switch (tabbarSelected.index) {
  47. case TabBarIndex.plot:
  48. return PlotListScreen();
  49. break;
  50. case TabBarIndex.device:
  51. return ControlDeviceScreen();
  52. break;
  53. case TabBarIndex.qr:
  54. // scan(context);
  55. return PlotListScreen();
  56. break;
  57. case TabBarIndex.notification:
  58. return NotificationScreen();
  59. break;
  60. case TabBarIndex.account:
  61. return AccountScreen();
  62. break;
  63. default:
  64. return PlotListScreen();
  65. }
  66. }),
  67. bottomNavigationBar: Container(
  68. padding: EdgeInsets.all(4),
  69. height: 70,
  70. decoration: BoxDecoration(
  71. color: Colors.white,
  72. border: Border(
  73. top: BorderSide(color: Colors.grey, width: 0.35))),
  74. child: GetBuilder<TabbarSelected>(builder: (tabbarSelected) {
  75. return Center(
  76. child: ListView.builder(
  77. scrollDirection: Axis.horizontal,
  78. shrinkWrap: true,
  79. physics: NeverScrollableScrollPhysics(),
  80. itemCount: itemsTabbar.length,
  81. itemBuilder: (context, index) {
  82. return GestureDetector(
  83. child: Container(
  84. width: (Get.width - 20) / 5,
  85. margin: EdgeInsets.all(1),
  86. padding: EdgeInsets.all(10),
  87. child: Column(
  88. mainAxisAlignment: MainAxisAlignment.center,
  89. children: [
  90. SvgPicture.asset(
  91. itemsTabbar[index].icon,
  92. width: 24,
  93. height: 24,
  94. color: (tabbarSelected.index ==
  95. itemsTabbar[index].index)
  96. ? AppColors.YELLOW
  97. : AppColors.GRAY1,
  98. ),
  99. Flexible(
  100. child: Text(
  101. itemsTabbar[index].title,
  102. style: TextStyle(
  103. color: (tabbarSelected.index ==
  104. itemsTabbar[index].index)
  105. ? AppColors.DEFAULT
  106. : Colors.grey,
  107. fontSize: 11),
  108. ),
  109. )
  110. ],
  111. )),
  112. onTap: () {
  113. changeTabbar
  114. .changeIndex(itemsTabbar[index].index);
  115. },
  116. );
  117. }),
  118. );
  119. })),
  120. )));
  121. }
  122. }
  123. class TabbarSelected extends GetxController {
  124. TabBarIndex index;
  125. void initValue() {
  126. index = TabBarIndex.plot;
  127. update();
  128. }
  129. void changeIndex(TabBarIndex changedIndex) {
  130. index = changedIndex;
  131. update();
  132. }
  133. }
  134. enum TabBarIndex { plot, device, qr, notification, account }
  135. class TabbarItem {
  136. TabBarIndex index;
  137. String icon;
  138. String title;
  139. TabbarItem({this.icon, this.title, this.index});
  140. }