aman-kassa-flutter/lib/views/home/home_view.dart

146 lines
4.5 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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:aman_kassa_flutter/widgets/loader/Dialogs.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<Choice> choices = const <Choice>[
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<HomeView> {
PageController pageController;
int selectedTabIndex;
DataService _dataService = locator<DataService>();
final GlobalKey<State> _keyLoader = new GlobalKey<State>();
@override
void initState() {
// TODO: implement initState
super.initState();
selectedTabIndex = 0;
pageController = new PageController(initialPage: selectedTabIndex);
}
@override
void dispose() {
pageController.dispose();
super.dispose();
}
void _onSelectChoice(Choice choice) async {
if(choice.command == 'exit') {
} else if (choice.command == 'update') {
Dialogs.showLoadingDialog(context, _keyLoader);
bool result = await _dataService.getDataFromServer(Redux.store.state.userState.user.token);
print('result: $result');
Navigator.of(_keyLoader.currentContext,rootNavigator: true).pop();
}
}
@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: <Widget>[
PopupMenuButton<Choice>(
icon: Icon(
Icons.more_vert,
color: menuColor,
),
onSelected: _onSelectChoice,
itemBuilder: (BuildContext context) {
return choices.map((Choice choice) {
return PopupMenuItem<Choice>(
value: choice,
child: Row(children: <Widget>[
Icon(choice.icon, color: primaryColor,),
Text(choice.title)
], ),
);
}).toList();
},
)
],
backgroundColor: fillColor,
),
body: PageView(
onPageChanged: (index) {
setState(() {
selectedTabIndex = index;
});
},
controller: pageController,
children: <Widget>[
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,
);
},
),
);
}
}