openThen function

dynamic openThen(
  1. dynamic context,
  2. Widget page, {
  3. Function? then,
  4. Function? beforeOpen,
  5. Function? afterClose,
})

Open a window, execute @then until window closed

Implementation

openThen(context, Widget page,
    {Function? then, Function? beforeOpen, Function? afterClose}) {
  if (beforeOpen != null) {
    beforeOpen();
  } else {
    SoundPlayer.i.play(Sounds.action);
  }
  Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {
    return page;
  })).then((_) {
    if (then != null) then();
    if (afterClose != null) {
      afterClose();
    } else {
      SoundPlayer.i.play(Sounds.wood_hit);
    }
  });
}