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.

156 lines
5.9KB

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