Skip to content

Commit

Permalink
fix(3.22.x): use the values for AutovalidateMode instead of testing each
Browse files Browse the repository at this point in the history
Co-authored-by: Gustl22 <[email protected]>
  • Loading branch information
cyrilcolinet and Gustl22 committed Aug 22, 2024
1 parent 2e796e5 commit f08555b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 51 deletions.
24 changes: 2 additions & 22 deletions json_theme/lib/src/codec/theme_encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,32 +238,12 @@ class ThemeEncoder {
return _stripDynamicNull(result);
}

/// Encodes the given [value] to a [String]. Supported values are:
/// * `always`
/// * `disabled`
/// * `onUserInteraction`
/// * `onUnfocus`
/// Encodes the given [value] to a [String].
static String? encodeAutovalidateMode(AutovalidateMode? value) {
String? result;

if (value != null) {
switch (value) {
case AutovalidateMode.always:
result = 'always';
break;

case AutovalidateMode.disabled:
result = 'disabled';
break;

case AutovalidateMode.onUserInteraction:
result = 'onUserInteraction';
break;

case AutovalidateMode.onUnfocus:
result = 'onUnfocus';
break;
}
return value.name;
}

return _stripDynamicNull(result);
Expand Down
34 changes: 5 additions & 29 deletions json_theme/test/json_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -495,35 +495,11 @@ void main() {
AutovalidateMode.always,
);

expect(
ThemeDecoder.decodeAutovalidateMode('always'),
AutovalidateMode.always,
);
expect(
ThemeDecoder.decodeAutovalidateMode('disabled'),
AutovalidateMode.disabled,
);
expect(
ThemeDecoder.decodeAutovalidateMode('onUserInteraction'),
AutovalidateMode.onUserInteraction,
);

expect(
ThemeEncoder.encodeAutovalidateMode(AutovalidateMode.always),
'always',
);
expect(
ThemeEncoder.encodeAutovalidateMode(AutovalidateMode.disabled),
'disabled',
);
expect(
ThemeEncoder.encodeAutovalidateMode(AutovalidateMode.onUserInteraction),
'onUserInteraction',
);
expect(
ThemeEncoder.encodeAutovalidateMode(AutovalidateMode.onUnfocus),
'onUnfocus',
);
// Test each values from AutovalidateMode enum
for (var value in AutovalidateMode.values) {
expect(ThemeDecoder.decodeAutovalidateMode(value.name), value);
expect(ThemeEncoder.encodeAutovalidateMode(value), value.name);
}
});

test('Axis', () {
Expand Down

0 comments on commit f08555b

Please sign in to comment.