From 8f46499c6fa073f3f3a65fdd3b2a29477bc8acaf Mon Sep 17 00:00:00 2001 From: Arthur Miranda <60884977+arthurbcd@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:16:21 -0300 Subject: [PATCH] fix no-element exception when href is absent --- lib/src/gpx_reader.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/gpx_reader.dart b/lib/src/gpx_reader.dart index 2b2f94a..b2b2242 100644 --- a/lib/src/gpx_reader.dart +++ b/lib/src/gpx_reader.dart @@ -439,9 +439,11 @@ class GpxReader { final elm = iterator.current; if (elm is XmlStartElementEvent) { - link.href = elm.attributes - .firstWhere((attr) => attr.name == GpxTagV11.href) - .value; + final hrefs = elm.attributes.where((attr) => attr.name == GpxTagV11.href); + + if (hrefs.isNotEmpty) { + link.href = hrefs.first.value; + } } if ((elm is XmlStartElementEvent) && !elm.isSelfClosing) {