diff --git a/packages/stac/lib/src/framework/stac.dart b/packages/stac/lib/src/framework/stac.dart index 28ca0039..c558ec1f 100644 --- a/packages/stac/lib/src/framework/stac.dart +++ b/packages/stac/lib/src/framework/stac.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; @@ -150,6 +151,7 @@ class Stac { try { if (json != null) { Map? jsonVersion = json['version']; + final platform = json['platform']; /// Check if has version and buildNumber is not null if (jsonVersion != null && StacRegistry.instance.buildNumber != null) { @@ -164,6 +166,30 @@ class Stac { } } + /// Check if platform is specified and validate + if (platform != null) { + final currentPlatform = Platform.operatingSystem; + bool isPlatformSupported = false; + List supportedPlatforms = []; + + // Check if platform is a list or a single string + if (platform is List) { + supportedPlatforms = platform.map((e) => e.toString()).toList(); + isPlatformSupported = supportedPlatforms.contains(currentPlatform); + } else if (platform is String) { + supportedPlatforms.add(platform); + isPlatformSupported = platform == currentPlatform; + } + + // If platform is not supported, log and return null + if (!isPlatformSupported) { + final platformsStr = supportedPlatforms.join(', '); + Log.w( + 'Widget not supported on platform [$currentPlatform]. Only available for: $platformsStr'); + return null; + } + } + String widgetType = json['type']; StacParser? stacParser = StacRegistry.instance.getParser(widgetType);