-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cfb6a8
commit 546c5d3
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
packages/system/vyuh_feature_system/lib/action/conditional_action.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:flutter/material.dart' as flutter; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:vyuh_core/vyuh_core.dart'; | ||
import 'package:vyuh_extension_content/vyuh_extension_content.dart'; | ||
|
||
part 'conditional_action.g.dart'; | ||
|
||
@JsonSerializable() | ||
class ConditionalAction extends ActionConfiguration { | ||
static const schemaName = 'vyuh.action.conditional'; | ||
|
||
static final typeDescriptor = TypeDescriptor( | ||
schemaType: ConditionalAction.schemaName, | ||
title: 'Conditional Action', | ||
fromJson: ConditionalAction.fromJson, | ||
); | ||
|
||
@JsonKey(defaultValue: []) | ||
final List<CaseAction>? cases; | ||
|
||
final String? defaultCase; | ||
final Condition? condition; | ||
|
||
ConditionalAction({this.cases, this.condition, this.defaultCase}) | ||
: super(schemaType: ConditionalAction.schemaName); | ||
|
||
factory ConditionalAction.fromJson(Map<String, dynamic> json) => | ||
_$ConditionalActionFromJson(json); | ||
|
||
@override | ||
void execute(flutter.BuildContext context) async { | ||
final value = (await condition?.execute()) ?? defaultCase; | ||
|
||
if (context.mounted) { | ||
final caseAction = | ||
cases?.firstWhereOrNull((element) => element.value == value); | ||
|
||
caseAction?.action?.execute(context); | ||
} | ||
} | ||
} | ||
|
||
@JsonSerializable() | ||
final class CaseAction { | ||
final String? value; | ||
|
||
final Action? action; | ||
|
||
CaseAction({this.value, this.action}); | ||
|
||
factory CaseAction.fromJson(Map<String, dynamic> json) => | ||
_$CaseActionFromJson(json); | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/system/vyuh_feature_system/lib/action/conditional_action.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/system/vyuh_feature_system/lib/vyuh_feature_system.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters