showGrpcPopup static method

Future<void> showGrpcPopup({
  1. required BuildContext context,
  2. required String defaultErrMsg,
  3. required GrpcError grpcErr,
  4. required String buttonTestKey,
  5. required String buttonName,
  6. required dynamic onButton(),
  7. String? err,
  8. String? noConnectionMsg,
  9. Function? beforePopup,
})

Basing on parameters shows popup with grpc error message

  • if err is null and grpcErr have message it will show it
  • if noConnectionMsg is set and grpcErr has status unavailable and message contains 'lookup' it will show noConnectionMsg
  • if err is not null and none of the previous cases occur it will show it
  • otherwise it will show defaultErrMsg

Implementation

static Future<void> showGrpcPopup(
    {required BuildContext context,
    required String defaultErrMsg,
    required GrpcError grpcErr,
    required String buttonTestKey,
    required String buttonName,
    required Function() onButton,
    String? err,
    String? noConnectionMsg,
    Function? beforePopup}) async {
  if (_isGrpcShowing) return;
  _isGrpcShowing = true;
  if (beforePopup != null) beforePopup();

  if (err == null && grpcErr.message != null && grpcErr.message!.isNotEmpty) {
    err = grpcErr.message;
  }

  if (noConnectionMsg != null &&
      grpcErr.code == StatusCode.unavailable &&
      (grpcErr.message != null && grpcErr.message!.contains("lookup"))) {
    err = noConnectionMsg;
  }

  showDialog(
      context: context,
      barrierDismissible: false,
      builder: (context) {
        return AlertDialog(
          icon: TkfIcons.failed(color: kErrorColor),
          content: Text(err ?? defaultErrMsg,
              style: kTextStyle14o80.copyWith(
                  fontSize: 16, fontWeight: FontWeight.bold)),
          actions: [
            TkfPopUpButton(
              testKey: Key(buttonTestKey),
              name: buttonName,
              onPress: () {
                _isGrpcShowing = false;
                onButton();
              },
            )
          ],
        );
      });
}