-
-
Notifications
You must be signed in to change notification settings - Fork 94
Devall #447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Devall #447
Changes from all commits
7bd10f2
9161ed8
94de42f
fa82e68
2840f5a
e260f19
9dcfc91
68ac416
8462d5c
abb666c
18e6993
6abc595
8e380ed
ee098d6
32c39c3
1c27e76
dc8a2b9
638014b
8f84f83
dc9e16f
6082cc5
80dac42
2e8c130
5ce86bb
414ac47
9c25956
228e9b7
a68ee81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import 'dart:async'; | ||
| import 'dart:convert'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:dio/dio.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
|
|
@@ -8,21 +9,17 @@ import 'package:flutter/services.dart'; | |
| import 'package:stac/src/framework/stac.dart'; | ||
| import 'package:stac/src/models/stac_cache_config.dart'; | ||
| import 'package:stac/src/framework/stac_error.dart'; | ||
| import 'package:stac/src/framework/stac_registry.dart'; | ||
| import 'package:stac/src/parsers/actions/stac_form_validate/stac_form_validate_parser.dart'; | ||
| import 'package:stac/src/parsers/actions/stac_get_form_value/stac_get_form_value_parser.dart'; | ||
| import 'package:stac/src/parsers/actions/stac_network_request/stac_network_request_parser.dart'; | ||
| import 'package:stac/src/parsers/parsers.dart'; | ||
| import 'package:stac/src/parsers/widgets/stac_app_bar/stac_app_bar_parser.dart'; | ||
| import 'package:stac/src/parsers/widgets/stac_inkwell/stac_inkwell_parser.dart'; | ||
| import 'package:stac/src/parsers/widgets/stac_row/stac_row_parser.dart'; | ||
| import 'package:stac/src/parsers/widgets/stac_text/stac_text_parser.dart'; | ||
| import 'package:stac/src/parsers/widgets/stac_tool_tip/stac_tool_tip_parser.dart'; | ||
| import 'package:stac/src/services/stac_network_service.dart'; | ||
| import 'package:stac/src/utils/variable_resolver.dart'; | ||
| import 'package:stac/stac.dart'; | ||
| import 'package:stac_core/core/stac_options.dart'; | ||
| import 'package:stac_core/stac_core.dart'; | ||
| import 'package:stac_framework/stac_framework.dart'; | ||
| import 'package:stac_logger/stac_logger.dart'; | ||
|
|
||
| /// Internal service that manages Stac parsers, actions, and rendering. | ||
|
|
@@ -181,6 +178,7 @@ class StacService { | |
| bool logStackTraces = true, | ||
| StacErrorWidgetBuilder? errorWidgetBuilder, | ||
| StacCacheConfig? cacheConfig, | ||
| int? buildNumber, | ||
| }) async { | ||
| _options = options; | ||
| if (cacheConfig != null) { | ||
|
|
@@ -190,18 +188,65 @@ class StacService { | |
| _actionParsers.addAll(actionParsers); | ||
| StacRegistry.instance.registerAll(_parsers, override); | ||
| StacRegistry.instance.registerAllActions(_actionParsers, override); | ||
| StacRegistry.instance.registerBuildNumber(buildNumber); | ||
| StacNetworkService.initialize(dio ?? Dio()); | ||
| _showErrorWidgets = showErrorWidgets; | ||
| _logStackTraces = logStackTraces; | ||
| _errorWidgetBuilder = errorWidgetBuilder; | ||
| } | ||
|
|
||
| static void setParseCustomColor(Color? Function(String?)? parseCustomColor) => | ||
| StacRegistry.instance.parseCustomColor = parseCustomColor; | ||
|
|
||
| static Widget? fromJson(Map<String, dynamic>? json, BuildContext context) { | ||
| try { | ||
| if (json == null) { | ||
| return null; | ||
| } | ||
|
|
||
| Map<String, dynamic>? jsonVersion = json['version']; | ||
| final platform = json['platform']; | ||
|
|
||
| /// Check if has version and buildNumber is not null | ||
| if (jsonVersion != null && StacRegistry.instance.buildNumber != null) { | ||
| final stacVersion = StacVersion.fromJson(jsonVersion); | ||
| final isSatisfied = stacVersion.isSatisfied( | ||
| StacRegistry.instance.buildNumber!, | ||
| ); | ||
| // If version is not satisfied, return null | ||
| if (!isSatisfied) { | ||
| Log.w( | ||
| 'Stac buildNumber ${stacVersion.buildNumber} is not satisfied; current build is: ${StacRegistry.instance.buildNumber}', | ||
| ); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /// Check if platform is specified and validate | ||
| if (platform != null) { | ||
| final currentPlatform = Platform.operatingSystem; | ||
| bool isPlatformSupported = false; | ||
| List<String> 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; | ||
| } | ||
| } | ||
|
Comment on lines
+226
to
+248
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Platform gating uses
Additionally, the platform check accepts arbitrary strings (e.g., 🤖 Prompt for AI Agents |
||
|
|
||
| // Safely extract widget type with validation | ||
| final widgetType = json['type']; | ||
| if (widgetType == null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export 'stac_axis_parser.dart'; | ||
| export 'stac_box_fit_parser.dart'; | ||
| export 'stac_box_shape_parser.dart'; | ||
| export 'stac_clip_parser.dart'; | ||
| export 'stac_flex_fit_parser.dart'; | ||
| export 'stac_material_tap_target_size_parser.dart'; | ||
| export 'stac_stack_fit_parser.dart'; | ||
| export 'stac_vertical_direction_parser.dart'; | ||
| export 'stac_wrap_alignment_parser.dart'; | ||
| export 'stac_wrap_cross_alignment_parser.dart'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export 'package:stac/src/utils/color_utils.dart'; | ||
| export 'package:stac/src/utils/version/stac_version.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registerBuildNumbersilently ignoresnull, preventing reset.Once a build number is set, there is no way to clear it back to
null. The test setUp callsStacRegistry.instance.registerBuildNumber(null)expecting a reset, but this is a no-op due to the null guard. TheisSatisfiedgroup's "returns false when app version is null" test (line 66 of test file) accidentally passes because_buildNumberretains the previous non-null value (2000), not because it was actually reset tonull.If the intent is to protect against accidental null assignment, consider a separate
clearBuildNumber()method. Otherwise, simply remove the guard:🐛 Proposed fix
void registerBuildNumber(int? buildNumber) { - if (buildNumber != null) { - _buildNumber = buildNumber; - } + _buildNumber = buildNumber; }📝 Committable suggestion
🤖 Prompt for AI Agents