In Dart, a function cannot be used before it is defined. How can 2 functions call each other? How can I work around with the following code snippet ? The _createComponent function calls _showLayerPopupMenu which has an menu item action to call _createComponent.
void _showLayerPopupMenu(int idx) async {
var selected = await showMenu(
context: context,
position: RelativeRect.fromLTRB(100, 100, 100, 100),
items: [
PopupMenuItem(
child: Text("Merge Down"),
value: 0,
),
PopupMenuItem(
child: Text("Duplicate"),
value: 1,
),
],
elevation: 8.0,
);
if (selected == 0) _mergeLayer(idx);
if (selected == 1) {
LayerPainter layerPainter=LayerPainter();
_createComponent(layerPainter,idx);
}
}
Widget _createComponent(LayerPainter layerPainter, int id) {
return Container(
width: 120,
height: 160,
decoration: BoxDecoration(
color: layerPainter.isColorMask ? Colors.blue : Colors.green,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0),
)),
child: Stack(children: <Widget>[
IconButton(
icon: id >= 0
? const Icon(Icons.menu)
: Icon(null), //const Icon(Icons.remove),
onPressed: () {
if (id >= 0) _showLayerPopupMenu(id);
},
),
]),
),
}