From d465ac601072a9d33ec19bdf0badd126aa0a3e4e Mon Sep 17 00:00:00 2001 From: Robert Schulze Dieckhoff Date: Mon, 25 Nov 2024 11:08:27 +0100 Subject: [PATCH] extracted resize viewport into own method --- .../components/card/base_card_component.dart | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/src/components/card/base_card_component.dart b/lib/src/components/card/base_card_component.dart index 82b0b54f..1e096fc4 100644 --- a/lib/src/components/card/base_card_component.dart +++ b/lib/src/components/card/base_card_component.dart @@ -135,19 +135,22 @@ class _BaseCardComponentState extends State { void _onComponentCommunication(event) { if (event.type case ComponentCommunicationType.resize) { - final newViewportHeight = event.data as int; - if (newViewportHeight == previousViewportHeight) { - return; - } else { - setState(() { - previousViewportHeight = viewportHeight; - viewportHeight = newViewportHeight; - }); - } + _resizeViewport(event); } else if (event.type case ComponentCommunicationType.result) { widget.onResult(event); } else { widget.handleComponentCommunication(event); } } + + void _resizeViewport(event) { + final newViewportHeight = event.data is int ? event.data : null; + if (newViewportHeight != previousViewportHeight && + newViewportHeight != null) { + setState(() { + previousViewportHeight = viewportHeight; + viewportHeight = newViewportHeight; + }); + } + } }