-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add triple state switch widget #1160
Conversation
@@ -1849,6 +1849,35 @@ | |||
] | |||
}, | |||
"Switch-payload": { | |||
"type": "object", |
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.
hey vinoth, the schema needs to add in ensemble-web-studio ts files, check the studio repo readme
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.
Okay I'll update in the studio once this PR is merged
lib/widget/triple_state_switch.dart
Outdated
void onToggle(SwitchState newValue) { | ||
widget.onToggle(newValue); | ||
widget._controller.value = newValue; | ||
if (widget._controller.onChange != null) { |
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.
add a dispatch event here, so if any listener is bind to switch state change will update as well.
Something like this
ensemble/lib/layout/tab_bar.dart
Lines 160 to 161 in afa3e8d
scopeManager.dispatch( | |
ModelChangeEvent( |
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.
This should be automatic right @snehmehta ? We shouldn't have to dispatch anythign for binding to work.
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.
Yes, my bad. It works. For some reason i thought the case of tabbar and footer not updating on tab change because of event but I was wrong it update I check my theory.
lib/widget/triple_state_switch.dart
Outdated
widget: FormField<bool>( | ||
key: validatorKey, | ||
validator: (value) { | ||
if (widget._controller.required) { |
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.
do test this validation case, from the look of it won't work as expected
lib/widget/triple_state_switch.dart
Outdated
import 'package:ensemble_ts_interpreter/invokables/invokable.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class EnsembleTripleStateSwitch extends StatefulWidget |
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.
see Avatar for new widget implementation. This is the legacy way of building a widget.
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.
Currently, the Switch widget is using the FormFieldController which is not migrated to the new way (extending the EnsembleWidgetController instead of WidgetController). I tried changing the FormFieldController so I am supposed to migrate all the widget which uses the FormFieldController to new way of building widgets (EnsembleWidget).
So as of now I done in the old way only
lib/widget/triple_state_switch.dart
Outdated
void onToggle(SwitchState newValue) { | ||
widget.onToggle(newValue); | ||
widget._controller.value = newValue; | ||
if (widget._controller.onChange != null) { |
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.
This should be automatic right @snehmehta ? We shouldn't have to dispatch anythign for binding to work.
lib/widget/triple_state_switch.dart
Outdated
} | ||
|
||
@override | ||
Map<String, Function> setters() { |
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.
why copy and pasted all these code? 99% of it identical to the regular switch. You should at least use a base class instead of replicating all these.
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.
Refactored
lib/widget/triple_state_switch.dart
Outdated
} | ||
} | ||
|
||
enum SwitchState { |
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.
use on, off, and mixed as these are more user friendly. Start and End doesn't mean much.
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.
Changed it
lib/widget/triple_state_switch.dart
Outdated
Map<String, Function> setters() { | ||
return { | ||
'value': (value) => _controller.value = | ||
SwitchState.values.from(Utils.getString(value, fallback: 'start')) ?? |
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.
You have two "start" values here plus the default "start" - that is 3 different places to change if you decide to change the default state. Potential cause for bug unnecessary.
Use this:
_controller.value = SwitchState.values.from(value) ?? _controller.value
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.
Done
lib/widget/switch.dart
Outdated
'leadingText': (text) => | ||
_controller.leadingText = Utils.optionalString(text), | ||
'trailingText': (text) => | ||
_controller.trailingText = Utils.optionalString(text), | ||
'activeColor': (color) => _controller.activeColor = Utils.getColor(color), | ||
'inactiveColor': (color) => | ||
_controller.inactiveColor = Utils.getColor(color), | ||
'intermediateColor': (color) => |
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.
mixedColor
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.
Changed it
lib/widget/switch.dart
Outdated
@@ -50,28 +61,30 @@ class EnsembleSwitch extends StatefulWidget | |||
}; | |||
} | |||
|
|||
void onToggle(bool newValue) { | |||
setProperty('value', newValue); | |||
void setSwitchValue(dynamic value) { |
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.
Switch and TripleSwitch's value should be succinct. The former takes in true/false, the latter 3 states. There should be no guessing like this, so please refactor so their inputs are separate. The schema should reflect tis too
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.
Added onToggle
in those widgets with their state as input parameter
lib/widget/switch.dart
Outdated
|
||
framework.EnsembleAction? onChange; | ||
void onToggle(dynamic newValue) { |
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.
same thing here. Each widget should have its own onToggle
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.
Updated it
lib/widget/switch.dart
Outdated
@@ -102,12 +115,13 @@ class SwitchState extends FormFieldWidgetState<EnsembleSwitch> { | |||
|
|||
// wraps around FormField to get all the form effects | |||
return InputWrapper( | |||
type: EnsembleSwitch.type, | |||
// type: EnsembleTripleStateSwitch.type, | |||
type: '', |
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.
put the type in. This is to help with exceptions.
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.
Done
@vusters Can you review it? Just updated it, also checked the validation and it's working fine (It fixes this issue also #1155)
|
Ticket: #1154
value = off | mixed | on
Doc - https://github.com/EnsembleUI/ensemble_docs/pull/123
Sample EDL
Simulator.Screen.Recording.-.iPhone.15.-.2024-01-22.at.17.13.41.mp4