Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
petrnymsa committed Mar 24, 2024
1 parent e584d05 commit 4efb171
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
melos_my_project.iml
.vscode/*
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/settings.json

.packages
Expand Down
8 changes: 7 additions & 1 deletion glade_forms/lib/src/core/glade_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ class GladeInput<T> extends ChangeNotifier {
return value == initialValue;
}

set value(T value) => _setValue(value, shouldTriggerOnChange: true);
set value(T value) {
if (_useTextEditingController) {
_syncValueWithController(value, shouldTriggerOnChange: true);
} else {
_setValue(value, shouldTriggerOnChange: true);
}
}

// ignore: avoid_setters_without_getters, ok for internal use
set _conversionError(ConvertError<T> value) {
Expand Down
4 changes: 2 additions & 2 deletions glade_forms/lib/src/widgets/glade_model_debug_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class GladeModelDebugInfo<M extends GladeModel> extends StatelessWidget {
this.showIsValid = true,
this.showValidationError = true,
this.showConversionError = true,
this.showValue = false,
this.showInitialValue = false,
this.showValue = true,
this.showInitialValue = true,
this.showControllerText = false,
this.hiddenKeys = const [],
this.scrollable = true,
Expand Down
71 changes: 45 additions & 26 deletions storybook/lib/usecases/complex_object_mapping_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class _Model extends GladeModel {
},
converterBack: (input) => input.join(','),
),
useTextEditingController: true,
);

super.initialize();
Expand All @@ -75,39 +76,57 @@ class ComplexObjectMappingExample extends StatelessWidget {
child: Row(
children: [
Expanded(
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(labelText: 'Characters stats'),
controller: model.availableStats.controller,
validator: model.availableStats.textFormFieldInputValidator,
),
DropdownButton(
items: model.availableItems
.map(
(e) => DropdownMenuItem(
value: e.id,
child: Text(e.name),
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(labelText: 'Characters stats'),
controller: model.availableStats.controller,
validator: model.availableStats.textFormFieldInputValidator,
),
Row(
children: [
const Text('Character item'),
const SizedBox(width: 30),
DropdownButton(
items: model.availableItems
.map(
(e) => DropdownMenuItem(
value: e.id,
child: Text(e.name),
),
)
.toList(),
value: model.selectedItem.value?.id,
onChanged: (v) => model.updateInput(
model.selectedItem,
// ignore: avoid-unsafe-collection-methods, ok here.
model.availableItems.firstWhere((element) => element.id == v),
),
)
.toList(),
value: model.selectedItem.value?.id,
onChanged: (v) => model.updateInput(
model.selectedItem,
// ignore: avoid-unsafe-collection-methods, ok here.
model.availableItems.firstWhere((element) => element.id == v),
),
],
),
),
],
],
),
),
),
Expanded(
child: Column(
children: [
const Text('Character stats'),
...model.availableStats.value.map((e) => Text(e.toString())),
const Text('Selected item'),
Text(model.selectedItem.value?.name ?? ''),
Text(
'Character stats',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(decoration: TextDecoration.underline),
),
if (model.availableStats.value.isEmpty)
const Text('No stats')
else
...model.availableStats.value.map((e) => Text(e.toString())),
Text(
'Selected item',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(decoration: TextDecoration.underline),
),
Text(model.selectedItem.value?.name ?? 'No item selected'),
],
),
),
Expand Down
5 changes: 1 addition & 4 deletions storybook/lib/usecases/one_checkbox_deps_validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class AgeRestrictedModel extends GladeModel {
..notNull()
..satisfy(
(value, extra, dependencies) {
final vipContentInput = dependencies.byKey<bool>('vip-input');

if (!vipContentInput.value) {
if (!vipInput.value) {
return true;
}

Expand All @@ -44,7 +42,6 @@ class AgeRestrictedModel extends GladeModel {
))
.build(),
value: 0,
dependencies: () => [vipInput],
valueConverter: GladeTypeConverters.intConverter,
inputKey: 'age-input',
translateError: (error, key, devMessage, dependencies) {
Expand Down
2 changes: 0 additions & 2 deletions storybook/lib/usecases/two_way_checkbox_change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ If *age* is changed to value under 18, *vip content* is unchecked and vice-versa
),
),
const GladeModelDebugInfo<AgeRestrictedModel>(
showValue: true,
showInitialValue: true,
showControllerText: true,
),
],
Expand Down

0 comments on commit 4efb171

Please sign in to comment.