initializeFromJsonOrUri method Null safety

bool initializeFromJsonOrUri(
  1. String linkOrJson
)

Implementation

bool initializeFromJsonOrUri(String linkOrJson) {
  final String js;
  if (linkOrJson.startsWith('http://') || linkOrJson.startsWith('https://')) {
    final q = Uri.tryParse(linkOrJson)?.queryParameters;
    if (q == null || q.isEmpty) {
      return false;
    }
    final String? qs = q['state'];
    if (qs == null) {
      throw ArgumentError('No state query parameter in $linkOrJson');
    }
    js = String.fromCharCodes(
        const ZLibDecoder().decodeBytes(base64Url.decoder.convert(qs)));
  } else {
    js = linkOrJson;
  }
  try {
    decodeJson(json.decode(js) as Map<String, dynamic>, needsSave: true);
  } finally {
    display.displayX(flash: false);
  }
  return true;
}