getPowerState method Null safety

Future<bool> getPowerState()

Implementation

Future<bool> getPowerState() async {
  try {
    final url = 'http://$_tvHostname:$powerPort';
    BaseOptions options = new BaseOptions(connectTimeout: _timeout);
    final dio = Dio(options);
    final Response response = await dio.get(url);
    return true;
  } on DioError catch (e) {
    if (e.type == DioErrorType.connectTimeout) {
      return false;
    }
    if (e.error.osError.message == 'Connection refused') {
      return true;
    }
    debug('error ${e.error.osError.message}');
    return false;
  } catch (e) {
    print('exception ${e}');
    return false;
  }
}