import 'package:farm_tpf/main.dart'; import 'package:farm_tpf/presentation/screens/account/sc_account.dart'; import 'package:farm_tpf/presentation/screens/control_device/sc_control_device.dart'; import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart'; import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart'; import 'package:farm_tpf/presentation/screens/profile/sc_update_profile.dart'; import 'package:farm_tpf/utils/const_color.dart'; import 'package:farm_tpf/utils/const_icons.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; class TabbarScreen extends StatefulWidget { static Route route() { return MaterialPageRoute(builder: (_) => TabbarScreen()); } @override _TabbarScreenState createState() => _TabbarScreenState(); } class _TabbarScreenState extends State { final changeTabbar = Get.put(TabbarSelected()); List itemsTabbar = [ TabbarItem( icon: AppIcons.icPlot, title: 'Lô trồng', index: TabBarIndex.plot), TabbarItem( icon: AppIcons.icDevice, title: 'Thiết bị', index: TabBarIndex.device), TabbarItem(icon: AppIcons.icQr, title: 'Quét QR', index: TabBarIndex.qr), TabbarItem( icon: AppIcons.icNotification, title: 'Thông báo', index: TabBarIndex.notification), TabbarItem( icon: AppIcons.icPerson, title: 'Cá nhân', index: TabBarIndex.account) ]; @override void initState() { super.initState(); changeTabbar.initValue(); } @override Widget build(BuildContext context) { return Container( color: Colors.white, child: SafeArea( top: false, bottom: true, child: Scaffold( body: GetBuilder(builder: (tabbarSelected) { switch (tabbarSelected.index) { case TabBarIndex.plot: return PlotListScreen(); break; case TabBarIndex.device: return ControlDeviceScreen(); break; case TabBarIndex.qr: // scan(context); return PlotListScreen(); break; case TabBarIndex.notification: return NotificationScreen(); break; case TabBarIndex.account: return AccountScreen(); break; default: return PlotListScreen(); } }), bottomNavigationBar: Container( padding: EdgeInsets.all(4), height: 70, decoration: BoxDecoration( color: Colors.white, border: Border( top: BorderSide(color: Colors.grey, width: 0.35))), child: GetBuilder(builder: (tabbarSelected) { return Center( child: ListView.builder( scrollDirection: Axis.horizontal, shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: itemsTabbar.length, itemBuilder: (context, index) { return GestureDetector( child: Container( width: (Get.width - 20) / 5, margin: EdgeInsets.all(1), padding: EdgeInsets.all(10), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SvgPicture.asset( itemsTabbar[index].icon, width: 24, height: 24, color: (tabbarSelected.index == itemsTabbar[index].index) ? AppColors.YELLOW : AppColors.GRAY1, ), Flexible( child: Text( itemsTabbar[index].title, style: TextStyle( color: (tabbarSelected.index == itemsTabbar[index].index) ? AppColors.DEFAULT : Colors.grey, fontSize: 11), ), ) ], )), onTap: () { changeTabbar .changeIndex(itemsTabbar[index].index); }, ); }), ); })), ))); } } class TabbarSelected extends GetxController { TabBarIndex index; void initValue() { index = TabBarIndex.plot; update(); } void changeIndex(TabBarIndex changedIndex) { index = changedIndex; update(); } } enum TabBarIndex { plot, device, qr, notification, account } class TabbarItem { TabBarIndex index; String icon; String title; TabbarItem({this.icon, this.title, this.index}); }