Im trying to pass data from a child widget to a parent widget using callback

so IM having this error
setState() or markNeedsBuild() called during build.

and I know its because of calling "callback" set msg before returning the stack(during building of child , superclass call setState :( )

`widget.setmsg(msg);`

```
return Stack(children: widget.model == posenet ? _renderKeypoints() : null); 

```

SO how can I return renderKeypoints() widget and return msg to super? or is there a way to print msg immediately in the screen (I get the value of msg after having calculation in renderkeypoint ?

Subclass code :

```
typedef void IntCallback(String id);

// ignore: must_be_immutable
class BndBox extends StatefulWidget {
  final List<dynamic> results;
  final int previewH;
  final int previewW;
  final double screenH;
  final double screenW;
  final String model;
  final IntCallback setmsg;

  BndBox(this.results, this.previewH, this.previewW, this.screenH, this.screenW,
      this.model, this.setmsg);

  @override
  _BndBoxState createState() => _BndBoxState();
}

class _BndBoxState extends State<BndBox> {
  @override
  Widget build(BuildContext context) {
    String msg = "";
    List<Widget> _renderKeypoints() {
      var lists = <Widget>[];
      var kx = [10.9];

      kx.removeAt(0);
      widget.results.forEach((re) {
        var list = re["keypoints"].values.map<Widget>((k) {
          var _x = k["x"];
          var _y = k["y"];
          var scaleW, scaleH, x, y;
          kx.add(k["x"]);

          if (widget.screenH / widget.screenW >
              widget.previewH / widget.previewW) {
            scaleW = widget.screenH / widget.previewH * widget.previewW;
            scaleH = widget.screenH;
            print("scaleW");
            print(scaleW);
            print("scaleH");
            print(scaleH);
            var difW = (scaleW - widget.screenW) / scaleW;
            x = (_x - difW / 2) * scaleW;
            y = _y * scaleH;
          } else {
            scaleH = widget.screenW / widget.previewW * widget.previewH;
            scaleW = widget.screenW;
            var difH = (scaleH - widget.screenH) / scaleH;
            x = _x * scaleW;
            y = (_y - difH / 2) * scaleH;
          }

          return Stack(children: [
            Positioned(
              left: x - 6,
              top: y - 6,
              width: 100,
              height: 12,
              child: Container(
                child: Text(
                  "● ${k["part"]}",
                  style: TextStyle(
                    color: Color.fromRGBO(37, 213, 253, 1.0),
                    fontSize: 12.0,
                  ),
                ),
              ),
            ),
          ]);
        }).toList();

        lists..addAll(list);
      });
      try {
        if (((kx[3] - kx[5]).abs() <= 0.05) &&
            ((kx[3] - kx[11]).abs() <= 0.1)) {
          msg = "RIGHT POSE";
        } else if (((kx[3] - kx[5]) > 0.05 && (kx[3] - kx[5]) < 0.1) &&
            (((kx[3] - kx[11]) > 0.1) && (kx[3] - kx[11]) < 0.2)) {
          msg = "WRONG POSE";
        } else {
          msg = "UNDEFINED";
        }
      } catch (Exception) {
        msg = "EXCEPTION";
      }

      return lists;
    }

    //  widget.setmsg(msg); //error here 
    return Stack(
          children: widget.model == posenet ? _renderKeypoints() : SizedBox(),

  }
}

```