aman-kassa-flutter/lib/views/home/components/popup_menu.dart

69 lines
2.1 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/BankService.dart';
import 'package:aman_kassa_flutter/shared/app_colors.dart';
import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
class PopupMenu extends StatefulWidget {
final void Function(Choice value) onSelectChoice;
PopupMenu({this.onSelectChoice});
@override
_PopupMenuState createState() => _PopupMenuState();
}
class _PopupMenuState extends State<PopupMenu> {
BankService _bankService = locator<BankService>();
List<Choice> choices;
@override
void initState() {
// TODO: implement initState
super.initState();
load();
}
load () async {
int version = await _bankService.version();
List<Choice> _choices = <Choice>[
const Choice(title: 'Информация о ККМ', icon: Icons.info_outline, command: 'infokkm'),
//if (version >= 24 )
// const Choice(title: 'Bank', icon: Icons.text_fields, command: 'bank'),
if (version >= 24 )
const Choice(title: 'Настройка HalykPos', icon: Icons.phonelink_lock_outlined, command: 'tap2phone'),
const Choice(title: 'Настройки', icon: Icons.settings, command: 'settings'),
const Choice(title: 'Принтер', icon: Icons.print, command: 'print'),
const Choice(title: 'Выйти', icon: Icons.exit_to_app, command: 'exit')
];
setState(() {
choices= _choices;
});
}
@override
Widget build(BuildContext context) {
return PopupMenuButton<Choice>(
icon: Icon(
Icons.more_vert,
color: menuColor,
),
onSelected: widget.onSelectChoice,
itemBuilder: (BuildContext context) {
return choices.map((Choice choice) {
return PopupMenuItem<Choice>(
value: choice,
child: Row(children: <Widget>[
Icon(choice.icon, color: primaryColor,),
SizedBox(width: 5,),
Text(choice.title)
], ),
);
}).toList();
},
);
}
}