Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
428 changes: 428 additions & 0 deletions examples/stac_gallery/assets/json/conditional_example.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions examples/stac_gallery/assets/json/home_screen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1373,5 +1373,27 @@
"assetPath": "assets/json/variable_example.json"
}
}
},
{
"type": "listTile",
"leading": {
"type": "icon",
"icon": "code"
},
"title": {
"type": "text",
"data": "Conditional Rendering"
},
"subtitle": {
"type": "text",
"data": "Use if-else conditions in STAC templates"
},
"onTap": {
"actionType": "navigate",
"widgetJson": {
"type": "exampleScreen",
"assetPath": "assets/json/conditional_example.json"
}
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
Expand Down Expand Up @@ -54,6 +55,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
1 change: 1 addition & 0 deletions packages/stac/lib/src/framework/stac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Stac {
const StacGestureDetectorParser(),
const StacSetValueParser(),
const StacInkwellParser(),
const StacConditionalParser(),
];

static final _actionParsers = <StacActionParser>[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:stac_framework/stac_framework.dart';

export 'stac_conditional_parser.dart';

part 'stac_conditional.freezed.dart';
part 'stac_conditional.g.dart';

@freezed
abstract class StacConditional with _$StacConditional {
const factory StacConditional({
required String condition,
required StacWidget ifTrue,
StacWidget? ifFalse,
}) = _StacConditional;

factory StacConditional.fromJson(Map<String, dynamic> json) =>
_$StacConditionalFromJson(json);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:stac/src/framework/stac.dart';
import 'package:stac/src/parsers/widgets/stac_conditional/stac_conditional.dart';
import 'package:stac/src/utils/expression_resolver.dart';
import 'package:stac/src/utils/widget_type.dart';
import 'package:stac_framework/stac_framework.dart';

class StacConditionalParser extends StacParser<StacConditional> {
const StacConditionalParser();

@override
String get type => WidgetType.conditional.name;

@override
StacConditional getModel(StacWidget json) => StacConditional.fromJson(json);

@override
Widget parse(BuildContext context, StacConditional model) {
final result = ExpressionResolver.evaluate(model.condition);
if (result) {
return Stac.fromJson(model.ifTrue, context) ?? const SizedBox();
} else if (model.ifFalse != null) {
return Stac.fromJson(model.ifFalse, context) ?? const SizedBox();
}
return const SizedBox();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ class StacDynamicViewParser extends StacParser<StacDynamicView> {

// Extract the value from the data
final dataValue = _extractNestedData(data, keys);
if (dataValue != null) {
processedValue = processedValue.replaceAll(
placeholder, dataValue.toString());
}

processedValue =
processedValue.replaceAll(placeholder, dataValue.toString());
}

template[key] = processedValue;
Expand Down
1 change: 1 addition & 0 deletions packages/stac/lib/src/parsers/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export 'package:stac/src/parsers/widgets/stac_clip_oval/stac_clip_oval.dart';
export 'package:stac/src/parsers/widgets/stac_clip_rrect/stac_clip_rrect.dart';
export 'package:stac/src/parsers/widgets/stac_colored_box/stac_colored_box.dart';
export 'package:stac/src/parsers/widgets/stac_column/stac_column.dart';
export 'package:stac/src/parsers/widgets/stac_conditional/stac_conditional.dart';
export 'package:stac/src/parsers/widgets/stac_container/stac_container.dart';
export 'package:stac/src/parsers/widgets/stac_custom_scroll_view/stac_custom_scroll_view.dart';
export 'package:stac/src/parsers/widgets/stac_decoration_image/stac_decoration_image.dart';
Expand Down
Loading