Skip to content

Commit

Permalink
Make the default value also the default when no value is present
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Nov 28, 2024
1 parent fc9dae4 commit cd598c0
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 15 deletions.
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/boolean.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class BooleanEditor extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final value = ref.watch(fieldValueProvider(path, false));
final value =
ref.watch(fieldValueProvider(path, primitiveBlueprint.defaultValue()));

return FieldHeader(
path: path,
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ColorEditor extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final startColor =
ref.watch(fieldValueProvider(path, customBlueprint.defaultValue));
ref.watch(fieldValueProvider(path, customBlueprint.defaultValue()));

final pickerColor = startColor is int ? Color(startColor) : Colors.black;
return FieldHeader(
path: path,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/widgets/inspector/editors/cron.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CronEditor extends HookConsumerWidget {
shift: (_) => const Offset(15, 0),
child: ValidatedInspectorTextField<String>(
path: path,
defaultValue: "0 0 1 1 *",
defaultValue: customBlueprint.defaultValue(),
icon: TWIcons.clock,
inputFormatters: [
FilteringTextInputFormatter.allow(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/widgets/inspector/editors/duration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DurationEditor extends HookConsumerWidget {
shift: (_) => const Offset(15, 0),
child: ValidatedInspectorTextField<int>(
path: path,
defaultValue: 0,
defaultValue: customBlueprint.defaultValue(),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r"[\dwdhminsu ]")),
],
Expand Down
2 changes: 1 addition & 1 deletion app/lib/widgets/inspector/editors/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EnumEditor extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final value =
ref.watch(fieldValueProvider(path, enumBlueprint.values.first));
ref.watch(fieldValueProvider(path, enumBlueprint.defaultValue()));
return Dropdown<String>(
icon: icon,
value: forcedValue ?? value,
Expand Down
3 changes: 1 addition & 2 deletions app/lib/widgets/inspector/editors/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ItemEditor extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
// final value = ref.watch(fieldValueProvider(path));
final algebraicBlueprint = customBlueprint.shape is AlgebraicBlueprint
? customBlueprint.shape as AlgebraicBlueprint?
: null;
Expand Down Expand Up @@ -93,7 +92,7 @@ class SerializedItemEditor extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final value =
ref.watch(fieldValueProvider(path)) ?? customBlueprint.defaultValue();
ref.watch(fieldValueProvider(path, customBlueprint.defaultValue()));

if (value is! Map<String, dynamic>) {
return Admonition.danger(
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class MapEditor extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
// ignore: provider_parameters
final rawValue = ref.watch(fieldValueProvider(path, {}));
final rawValue =
ref.watch(fieldValueProvider(path, mapBlueprint.defaultValue()));

// Since the map will be of the form {dynamic: dynamic}, we
// need to recreate the map.
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ class MaterialEditor extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final value = ref.watch(fieldValueProvider(path, ""));
final value =
ref.watch(fieldValueProvider(path, customBlueprint.defaultValue()));
final propertiesModifier =
customBlueprint.getModifier("material_properties");
final properties = propertiesModifier != null
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class NumberEditor extends HookConsumerWidget {
final focus = useFocusNode();
useFocusedBasedCurrentEditingField(focus, ref.passing, path);

final value = ref.watch(fieldValueProvider(path, 0));
final value =
ref.watch(fieldValueProvider(path, primitiveBlueprint.defaultValue()));

final isNegativeAllowed =
primitiveBlueprint.get("negative") as bool? ?? true;
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/page_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class PageSelectorEditor extends HookConsumerWidget {
return const Text("Invalid page type");
}

final pageId = ref.watch(fieldValueProvider(path, ""));
final pageId =
ref.watch(fieldValueProvider(path, primitiveBlueprint.defaultValue()));
final hasPage = ref.watch(pageExistsProvider(pageId));

return DragTarget<PageDrag>(
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/potion_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ class PotionEffectEditor extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final value = ref.watch(fieldValueProvider(path, "speed"));
final value =
ref.watch(fieldValueProvider(path, customBlueprint.defaultValue()));

// While we are editing, we need to keep the potion effects loaded
ref.watch(potionEffectsProvider);
Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/sound_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ class SoundSelectorEditor extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final data = ref.watch(fieldValueProvider(path));
final data =
ref.watch(fieldValueProvider(path, customBlueprint.defaultValue()));
final soundId =
data != null ? SoundId.fromJson(data) : const SoundId(id: "");

Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class StringEditor extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final focus = useFocusNode();
useFocusedBasedCurrentEditingField(focus, ref.passing, path);
final value = ref.watch(fieldValueProvider(path, ""));
final value =
ref.watch(fieldValueProvider(path, primitiveBlueprint.defaultValue()));

final singleLine = !primitiveBlueprint.hasModifier("multiline");

Expand Down
3 changes: 2 additions & 1 deletion app/lib/widgets/inspector/editors/variable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class VariableEditor extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final value = ref.watch(fieldValueProvider(path));
final value =
ref.watch(fieldValueProvider(path, customBlueprint.defaultValue()));
final data = variableData(value);
if (data == null) {
final child =
Expand Down

0 comments on commit cd598c0

Please sign in to comment.