add packages, receiving & processing
This commit is contained in:
120
lib/pages/widgets/local_popup_menu_button.dart
Normal file
120
lib/pages/widgets/local_popup_menu_button.dart
Normal file
@@ -0,0 +1,120 @@
|
||||
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;
|
||||
|
||||
const LocalPopupMenuButton(
|
||||
{Key key,
|
||||
this.popupMenuCallback,
|
||||
this.popmenus,
|
||||
this.multiSelect = false})
|
||||
: 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) {
|
||||
if (!widget.multiSelect) {
|
||||
setState(() {
|
||||
popmenus.forEach((e) {
|
||||
if (e.id != selected.id)
|
||||
e.selected = false;
|
||||
else
|
||||
e.selected = true;
|
||||
});
|
||||
});
|
||||
selected.selected = true;
|
||||
} else {
|
||||
setState(() {
|
||||
popmenus.forEach((e) {
|
||||
if (e.id == selected.id) e.selected = !e.selected;
|
||||
});
|
||||
});
|
||||
selected.selected = !selected.selected;
|
||||
}
|
||||
if (widget.popupMenuCallback != null)
|
||||
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(
|
||||
Icons.filter_list,
|
||||
color: primaryColor,
|
||||
),
|
||||
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) {
|
||||
return PopupMenuItem<LocalPopupMenu>(
|
||||
value: choice,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, choice.textKey, color: primaryColor),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
choice.selected
|
||||
? Icon(
|
||||
Icons.check,
|
||||
color: Colors.grey,
|
||||
)
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
bool _needHighlight() {
|
||||
popmenus.forEach((e) {
|
||||
if (e.selected && e.highlight) return true;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user