2020-10-12 03:34:05 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import 'local_popupmenu.dart';
|
|
|
|
|
|
|
|
|
|
typedef PopupMenuCallback = Function(LocalPopupMenu popupMenu);
|
|
|
|
|
|
|
|
|
|
class LocalPopupMenuButton extends StatefulWidget {
|
|
|
|
|
final PopupMenuCallback popupMenuCallback;
|
|
|
|
|
final List<LocalPopupMenu> popmenus;
|
|
|
|
|
final bool multiSelect;
|
2020-10-19 05:13:49 +06:30
|
|
|
final bool selectable;
|
2020-10-18 02:38:46 +06:30
|
|
|
final IconData buttonIcon;
|
2020-10-24 06:14:07 +06:30
|
|
|
final Color buttonColor;
|
2020-10-12 03:34:05 +06:30
|
|
|
|
|
|
|
|
const LocalPopupMenuButton(
|
|
|
|
|
{Key key,
|
|
|
|
|
this.popupMenuCallback,
|
|
|
|
|
this.popmenus,
|
2020-10-18 02:38:46 +06:30
|
|
|
this.buttonIcon,
|
2020-10-19 05:13:49 +06:30
|
|
|
this.selectable = true,
|
2020-10-24 06:14:07 +06:30
|
|
|
this.multiSelect = false,
|
|
|
|
|
this.buttonColor = primaryColor})
|
2020-10-12 03:34:05 +06:30
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_LocalPopupMenuButtonState createState() => _LocalPopupMenuButtonState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _LocalPopupMenuButtonState extends State<LocalPopupMenuButton> {
|
|
|
|
|
List<LocalPopupMenu> popmenus;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
popmenus = widget.popmenus;
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
bool hightlight = _needHighlight();
|
|
|
|
|
return PopupMenuButton<LocalPopupMenu>(
|
|
|
|
|
elevation: 3.2,
|
|
|
|
|
onSelected: (selected) {
|
2020-10-19 05:13:49 +06:30
|
|
|
if (widget.selectable) {
|
|
|
|
|
if (!widget.multiSelect) {
|
|
|
|
|
setState(() {
|
|
|
|
|
popmenus.forEach((e) {
|
|
|
|
|
if (e.id != selected.id)
|
|
|
|
|
e.selected = false;
|
|
|
|
|
else
|
|
|
|
|
e.selected = true;
|
|
|
|
|
});
|
2020-10-12 03:34:05 +06:30
|
|
|
});
|
2020-10-19 05:13:49 +06:30
|
|
|
selected.selected = true;
|
|
|
|
|
} else {
|
|
|
|
|
setState(() {
|
|
|
|
|
popmenus.forEach((e) {
|
|
|
|
|
if (e.id == selected.id) e.selected = !e.selected;
|
|
|
|
|
});
|
2020-10-12 03:34:05 +06:30
|
|
|
});
|
2020-10-19 05:13:49 +06:30
|
|
|
selected.selected = !selected.selected;
|
|
|
|
|
}
|
2020-10-12 03:34:05 +06:30
|
|
|
}
|
2020-10-19 05:13:49 +06:30
|
|
|
if (selected.enabled && widget.popupMenuCallback != null)
|
2020-10-12 03:34:05 +06:30
|
|
|
widget.popupMenuCallback(selected);
|
|
|
|
|
},
|
|
|
|
|
icon: Container(
|
|
|
|
|
width: 30,
|
|
|
|
|
height: 30,
|
|
|
|
|
decoration: new BoxDecoration(
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
child: Stack(
|
|
|
|
|
fit: StackFit.expand,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Icon(
|
2020-10-18 02:38:46 +06:30
|
|
|
widget.buttonIcon ?? Icons.filter_list,
|
2020-10-24 06:14:07 +06:30
|
|
|
color: widget.buttonColor ?? primaryColor,
|
2020-10-12 03:34:05 +06:30
|
|
|
),
|
|
|
|
|
hightlight
|
|
|
|
|
? Positioned(
|
|
|
|
|
bottom: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 10,
|
|
|
|
|
height: 10,
|
|
|
|
|
decoration: new BoxDecoration(
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
color: secondaryColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Container()
|
|
|
|
|
],
|
|
|
|
|
)),
|
|
|
|
|
itemBuilder: (BuildContext context) {
|
|
|
|
|
return popmenus.map((LocalPopupMenu choice) {
|
2020-10-19 05:13:49 +06:30
|
|
|
if (choice == null) return null;
|
2020-10-12 03:34:05 +06:30
|
|
|
return PopupMenuItem<LocalPopupMenu>(
|
|
|
|
|
value: choice,
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
2020-10-19 05:13:49 +06:30
|
|
|
LocalText(context, choice.textKey,
|
|
|
|
|
color:
|
|
|
|
|
choice?.enabled ?? true ? primaryColor : Colors.grey),
|
2020-10-12 03:34:05 +06:30
|
|
|
SizedBox(
|
|
|
|
|
width: 10,
|
|
|
|
|
),
|
|
|
|
|
choice.selected
|
|
|
|
|
? Icon(
|
|
|
|
|
Icons.check,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
)
|
|
|
|
|
: Container(),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _needHighlight() {
|
|
|
|
|
popmenus.forEach((e) {
|
2020-10-19 05:13:49 +06:30
|
|
|
if (e == null) return false;
|
2020-10-12 03:34:05 +06:30
|
|
|
if (e.selected && e.highlight) return true;
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|