import 'package:aman_kassa_flutter/core/locator.dart'; import 'package:aman_kassa_flutter/core/models/Choice.dart'; import 'package:aman_kassa_flutter/core/services/DataService.dart'; import 'package:aman_kassa_flutter/redux/store.dart'; import 'package:aman_kassa_flutter/shared/app_colors.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; import './tabs/KassaTab.dart'; import './tabs/AdditionalTab.dart'; import './tabs/CalculatorTab.dart'; const List choices = const [ const Choice(title: 'Обновить номенклатуру', icon: Icons.update, command: 'update'), const Choice(title: 'Помощь', icon: Icons.help, command: 'help'), const Choice(title: 'О Программе', icon: Icons.info_outline, command: 'info'), const Choice(title: 'Язык', icon: Icons.language, command: 'language'), const Choice(title: 'Выйти', icon: Icons.exit_to_app, command: 'exit') ]; class HomeView extends StatefulWidget { @override _HomeViewState createState() => _HomeViewState(); } class _HomeViewState extends State { PageController pageController; int selectedTabIndex; DataService _dataService = locator(); @override void initState() { // TODO: implement initState super.initState(); selectedTabIndex = 0; pageController = new PageController(initialPage: selectedTabIndex); } void _onSelectChoice(Choice choice) async { if(choice.command == 'exit') { } else if (choice.command == 'update') { bool result = await _dataService.getDataFromServer(Redux.store.state.userState.user.token); print('result: $result'); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Center( child: Container( width: 100, child: Image( image: AssetImage('assets/images/logo.png'), fit: BoxFit.fitHeight, ), )), actions: [ PopupMenuButton( icon: Icon( Icons.more_vert, color: menuColor, ), onSelected: _onSelectChoice, itemBuilder: (BuildContext context) { return choices.map((Choice choice) { return PopupMenuItem( value: choice, child: Row(children: [ Icon(choice.icon, color: primaryColor,), Text(choice.title) ], ), ); }).toList(); }, ) ], backgroundColor: fillColor, ), body: PageView( onPageChanged: (index) { setState(() { selectedTabIndex = index; }); }, controller: pageController, children: [ KassaTab(0), CalculatorTab(1), AdditionalTab(2), ], ), bottomNavigationBar: BottomNavigationBar( currentIndex: selectedTabIndex, backgroundColor: menuColor, type: BottomNavigationBarType.shifting, items: [ BottomNavigationBarItem( backgroundColor: menuColor, icon: Icon(MdiIcons.cashRegister, color: Colors.white), title: new Text( 'Касса', style: TextStyle(color: Colors.white), )), BottomNavigationBarItem( icon: Icon(MdiIcons.calculator, color: Colors.white), title: new Text( 'Калькулятор', style: TextStyle(color: Colors.white), )), BottomNavigationBarItem( icon: Icon(MdiIcons.tune, color: Colors.white), title: new Text( 'Опции', style: TextStyle(color: Colors.white), )), ], onTap: (index) { pageController.animateToPage( index, duration: const Duration(milliseconds: 300), curve: Curves.easeIn, ); }, ), ); } }