openDialog method

dynamic openDialog(
  1. String title,
  2. String text, {
  3. int numPops = 1,
})

Implementation

openDialog(String title, String text, {int numPops = 1}) {
  if (getPlatformType == PlatformType.iOS) {
    showDialog(
      context: Dao.inst.globalNavigatorKey.currentContext,
      builder: (BuildContext context) {
        // set up the AlertDialog
        return CupertinoAlertDialog(
          title: Text(
            title,
            style: TextStyle(
              color: Theme.of(context).accentColor,
              fontSize: 18.0,
            ),
          ),
          content: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Padding(
                padding: const EdgeInsets.only(bottom: 18.0),
                child: Text(
                  text,
                  style: TextStyle(
                    fontSize: 16.0,
                  ),
                ),
              ),
            ],
          ),
          actions: <Widget>[
            CupertinoDialogAction(
              child: TextButton(
                child: Text("OK"),
                onPressed: () {
                  int count = 0;
                  Navigator.of(context).popUntil((_) => count++ >= numPops);
                },
              ),
            )
          ],
        );
      },
    );
  } else {
    // show the dialog
    showDialog(
      context: Dao.inst.globalNavigatorKey.currentContext,
      builder: (BuildContext context) {
        // set up the AlertDialog
        return AlertDialog(
          title: Text(
            title,
            style: TextStyle(
              color: Theme.of(context).accentColor,
              fontSize: 18.0,
            ),
          ),
          content: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Padding(
                padding: const EdgeInsets.only(bottom: 18.0),
                child: Text(
                  text,
                  style: TextStyle(
                    fontSize: 16.0,
                  ),
                ),
              ),
            ],
          ),
          actions: [
            TextButton(
              child: Text("OK"),
              onPressed: () {
                int count = 0;
                Navigator.of(context).popUntil((_) => count++ >= numPops);
              },
            ),
          ],
        );
      },
    );
  }
}