Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7bd10f2
feat: Introduce custom color parsing functionality in StacRegistry
May 19, 2025
9161ed8
feat: Implement version management in Stac with StacVersion class and…
felipecastrosales May 26, 2025
94de42f
auto
felipecastrosales May 26, 2025
fa82e68
refactor: Update StacVersion class to use versionCode and improve ver…
felipecastrosales May 26, 2025
2840f5a
wip
felipecastrosales May 26, 2025
e260f19
test: Add comprehensive tests for StacVersion class and its conditions
felipecastrosales May 26, 2025
9dcfc91
wip
felipecastrosales May 27, 2025
68ac416
refactor: change to buildNumber and add support to platforms
felipecastrosales May 27, 2025
8462d5c
refactor: change to buildNumber (and delete freezed specifics)
felipecastrosales May 27, 2025
abb666c
test: adjust test and behaviours
felipecastrosales May 27, 2025
18e6993
test: Platform tests
felipecastrosales May 27, 2025
6abc595
fix: add missing import
felipecastrosales May 28, 2025
8e380ed
refactor: appBuildNumber as parameter
felipecastrosales May 29, 2025
ee098d6
docs: added documentation
felipecastrosales May 29, 2025
32c39c3
Merge pull request #1 from SuaMusica/feature/version
felipecastrosales Jun 4, 2025
1c27e76
Merge branch 'dev' into feature/flutter35
atrope Sep 15, 2025
dc8a2b9
chore: standardize quotes in pubspec.yaml files and remove unused imp…
atrope Sep 15, 2025
638014b
Merge pull request #2 from SuaMusica/feature/flutter35
lstonussi Sep 22, 2025
8f84f83
feat: add platform validation for widget support in Stac class
felipecastrosales Dec 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/counter_example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: counter_example
description: "A Stac example app showcasing a simple counter."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
Expand Down Expand Up @@ -58,7 +58,6 @@ dev_dependencies:

# The following section is specific to Flutter packages.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
Expand Down
3 changes: 1 addition & 2 deletions examples/movie_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: movie_app
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
Expand Down Expand Up @@ -54,7 +54,6 @@ dev_dependencies:

# The following section is specific to Flutter packages.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
Expand Down
47 changes: 47 additions & 0 deletions packages/stac/lib/src/framework/stac.dart
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/material.dart';
Expand All @@ -10,6 +11,7 @@ import 'package:stac/src/parsers/parsers.dart';
import 'package:stac/src/parsers/widgets/stac_inkwell/stac_inkwell_parser.dart';
import 'package:stac/src/parsers/widgets/stac_set_value/stac_set_value_parser.dart';
import 'package:stac/src/services/stac_network_service.dart';
import 'package:stac/src/utils/version/stac_version.dart';
import 'package:stac/src/utils/variable_resolver.dart';
import 'package:stac/src/utils/widget_type.dart';
import 'package:stac_framework/stac_framework.dart';
Expand Down Expand Up @@ -132,17 +134,62 @@ class Stac {
List<StacActionParser> actionParsers = const [],
Dio? dio,
bool override = false,
int? buildNumber,
}) async {
_parsers.addAll(parsers);
_actionParsers.addAll(actionParsers);
StacRegistry.instance.registerAll(_parsers, override);
StacRegistry.instance.registerAllActions(_actionParsers, override);
StacRegistry.instance.registerBuildNumber(buildNumber);
StacNetworkService.initialize(dio ?? Dio());
}

static void setParseCustomColor(Color? Function(String?)? parseCustomColor) =>
StacRegistry.instance.parseCustomColor = parseCustomColor;

static Widget? fromJson(Map<String, dynamic>? json, BuildContext context) {
try {
if (json != 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;
}
}

String widgetType = json['type'];
StacParser? stacParser = StacRegistry.instance.getParser(widgetType);

Expand Down
10 changes: 10 additions & 0 deletions packages/stac/lib/src/framework/stac_registry.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:stac_logger/stac_logger.dart';
import 'package:stac_framework/stac_framework.dart';

Expand All @@ -14,6 +15,9 @@ class StacRegistry {

static final _stacActionParsers = <String, StacActionParser>{};

Color? Function(String?)? parseCustomColor;
int? _buildNumber;
int? get buildNumber => _buildNumber;
static final Map<String, dynamic> _variables = {};

bool register(StacParser parser, [bool override = false]) {
Expand Down Expand Up @@ -70,6 +74,12 @@ class StacRegistry {
);
}

void registerBuildNumber(int? buildNumber) {
if (buildNumber != null) {
_buildNumber = buildNumber;
}
}

StacParser<dynamic>? getParser(String type) {
return _stacParsers[type];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ abstract class StacDialogTheme with _$StacDialogTheme {
}

extension StacDialogThemeParser on StacDialogTheme {
DialogTheme? parse(BuildContext context) {
return DialogTheme(
DialogThemeData? parse(BuildContext context) {
return DialogThemeData(
backgroundColor: backgroundColor.toColor(context),
elevation: elevation,
shadowColor: shadowColor.toColor(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ abstract class StacTabBarThemeData with _$StacTabBarThemeData {
}

extension StacTabBarThemeDataParser on StacTabBarThemeData {
TabBarTheme? parse(BuildContext context) {
return TabBarTheme(
TabBarThemeData? parse(BuildContext context) {
return TabBarThemeData(
indicator: indicator.parse(context),
indicatorColor: indicatorColor.toColor(context),
indicatorSize: indicatorSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ extension StacThemeParser on StacTheme {
checkboxTheme: checkboxTheme?.parse(context),
chipTheme: chipTheme?.parse(context),
datePickerTheme: datePickerTheme?.parse(context),
dialogTheme: dialogTheme?.parse(context)?.data,
dialogTheme: dialogTheme?.parse(context),
dividerTheme: dividerTheme?.parse(context),
drawerTheme: drawerTheme?.parse(context),
// DropdownMenuThemeData? dropdownMenuTheme,
Expand Down
5 changes: 5 additions & 0 deletions packages/stac/lib/src/utils/color_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:stac/src/utils/color_type.dart';
import 'package:stac/stac.dart';

const String _hashtag = "#";
const String _empty = "";
Expand Down Expand Up @@ -145,6 +146,10 @@ Color? _parseThemeColor(String color, BuildContext context) {
case StacColorType.surfaceTint:
return Theme.of(context).colorScheme.surfaceTint;
case StacColorType.none:
final customColor = StacRegistry.instance.parseCustomColor?.call(color);
if (customColor != null) {
return customColor;
}
return null;
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/stac/lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export 'package:stac/src/utils/color_utils.dart';
export 'package:stac/src/utils/stac_scroll_physics.dart';
export 'package:stac/src/utils/version/stac_version.dart';
Loading