Compare commits

...

3 commits

6 changed files with 75 additions and 20 deletions

View file

@ -20,7 +20,7 @@ class NewProjectDialog extends HookWidget {
final newProjectAction = useMemoized(() { final newProjectAction = useMemoized(() {
if (newDialogNameController.text.isEmpty) return null; if (newDialogNameController.text.isEmpty) return null;
return () { return () {
projectsState.newProject(newDialogNameController.text); projectsState.newProject(newDialogNameController.text.trim());
Navigator.pop(context); Navigator.pop(context);
}; };
}, [newDialogNameController.text]); }, [newDialogNameController.text]);
@ -217,6 +217,9 @@ class NewProjectDialog extends HookWidget {
icon: const Icon(Icons.done), icon: const Icon(Icons.done),
onPressed: newProjectAction, onPressed: newProjectAction,
), ),
errorText: projectsState.projects.map((p) => p.projectName).contains(newDialogNameController.text.trim())
? 'A project with the same name already exists'
: null,
), ),
onSubmitted: newProjectAction == null ? null : (_) => newProjectAction(), onSubmitted: newProjectAction == null ? null : (_) => newProjectAction(),
), ),

View file

@ -27,6 +27,8 @@ class ComponentEntry with _$ComponentEntry {
List<String>? logicExpression, List<String>? logicExpression,
@JsonKey(defaultValue: false) @JsonKey(defaultValue: false)
required bool visualDesigned, required bool visualDesigned,
@JsonKey(defaultValue: [])
required List<String> dependencies,
}) = _ComponentEntry; }) = _ComponentEntry;
factory ComponentEntry.fromJson(Map<String, Object?> json) => _$ComponentEntryFromJson(json); factory ComponentEntry.fromJson(Map<String, Object?> json) => _$ComponentEntryFromJson(json);

View file

@ -170,6 +170,8 @@ mixin _$ComponentEntry {
List<String>? get logicExpression => throw _privateConstructorUsedError; List<String>? get logicExpression => throw _privateConstructorUsedError;
@JsonKey(defaultValue: false) @JsonKey(defaultValue: false)
bool get visualDesigned => throw _privateConstructorUsedError; bool get visualDesigned => throw _privateConstructorUsedError;
@JsonKey(defaultValue: [])
List<String> get dependencies => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError; Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
@ -190,7 +192,8 @@ abstract class $ComponentEntryCopyWith<$Res> {
List<String> outputs, List<String> outputs,
@JsonKey(includeIfNull: false) List<String>? truthTable, @JsonKey(includeIfNull: false) List<String>? truthTable,
@JsonKey(includeIfNull: false) List<String>? logicExpression, @JsonKey(includeIfNull: false) List<String>? logicExpression,
@JsonKey(defaultValue: false) bool visualDesigned}); @JsonKey(defaultValue: false) bool visualDesigned,
@JsonKey(defaultValue: []) List<String> dependencies});
} }
/// @nodoc /// @nodoc
@ -212,6 +215,7 @@ class _$ComponentEntryCopyWithImpl<$Res>
Object? truthTable = freezed, Object? truthTable = freezed,
Object? logicExpression = freezed, Object? logicExpression = freezed,
Object? visualDesigned = freezed, Object? visualDesigned = freezed,
Object? dependencies = freezed,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
componentId: componentId == freezed componentId: componentId == freezed
@ -246,6 +250,10 @@ class _$ComponentEntryCopyWithImpl<$Res>
? _value.visualDesigned ? _value.visualDesigned
: visualDesigned // ignore: cast_nullable_to_non_nullable : visualDesigned // ignore: cast_nullable_to_non_nullable
as bool, as bool,
dependencies: dependencies == freezed
? _value.dependencies
: dependencies // ignore: cast_nullable_to_non_nullable
as List<String>,
)); ));
} }
} }
@ -265,7 +273,8 @@ abstract class _$$_ComponentEntryCopyWith<$Res>
List<String> outputs, List<String> outputs,
@JsonKey(includeIfNull: false) List<String>? truthTable, @JsonKey(includeIfNull: false) List<String>? truthTable,
@JsonKey(includeIfNull: false) List<String>? logicExpression, @JsonKey(includeIfNull: false) List<String>? logicExpression,
@JsonKey(defaultValue: false) bool visualDesigned}); @JsonKey(defaultValue: false) bool visualDesigned,
@JsonKey(defaultValue: []) List<String> dependencies});
} }
/// @nodoc /// @nodoc
@ -289,6 +298,7 @@ class __$$_ComponentEntryCopyWithImpl<$Res>
Object? truthTable = freezed, Object? truthTable = freezed,
Object? logicExpression = freezed, Object? logicExpression = freezed,
Object? visualDesigned = freezed, Object? visualDesigned = freezed,
Object? dependencies = freezed,
}) { }) {
return _then(_$_ComponentEntry( return _then(_$_ComponentEntry(
componentId: componentId == freezed componentId: componentId == freezed
@ -323,6 +333,10 @@ class __$$_ComponentEntryCopyWithImpl<$Res>
? _value.visualDesigned ? _value.visualDesigned
: visualDesigned // ignore: cast_nullable_to_non_nullable : visualDesigned // ignore: cast_nullable_to_non_nullable
as bool, as bool,
dependencies: dependencies == freezed
? _value._dependencies
: dependencies // ignore: cast_nullable_to_non_nullable
as List<String>,
)); ));
} }
} }
@ -338,11 +352,13 @@ class _$_ComponentEntry implements _ComponentEntry {
required final List<String> outputs, required final List<String> outputs,
@JsonKey(includeIfNull: false) final List<String>? truthTable, @JsonKey(includeIfNull: false) final List<String>? truthTable,
@JsonKey(includeIfNull: false) final List<String>? logicExpression, @JsonKey(includeIfNull: false) final List<String>? logicExpression,
@JsonKey(defaultValue: false) required this.visualDesigned}) @JsonKey(defaultValue: false) required this.visualDesigned,
@JsonKey(defaultValue: []) required final List<String> dependencies})
: _inputs = inputs, : _inputs = inputs,
_outputs = outputs, _outputs = outputs,
_truthTable = truthTable, _truthTable = truthTable,
_logicExpression = logicExpression; _logicExpression = logicExpression,
_dependencies = dependencies;
factory _$_ComponentEntry.fromJson(Map<String, dynamic> json) => factory _$_ComponentEntry.fromJson(Map<String, dynamic> json) =>
_$$_ComponentEntryFromJson(json); _$$_ComponentEntryFromJson(json);
@ -391,10 +407,17 @@ class _$_ComponentEntry implements _ComponentEntry {
@override @override
@JsonKey(defaultValue: false) @JsonKey(defaultValue: false)
final bool visualDesigned; final bool visualDesigned;
final List<String> _dependencies;
@override
@JsonKey(defaultValue: [])
List<String> get dependencies {
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_dependencies);
}
@override @override
String toString() { String toString() {
return 'ComponentEntry(componentId: $componentId, componentName: $componentName, componentDescription: $componentDescription, inputs: $inputs, outputs: $outputs, truthTable: $truthTable, logicExpression: $logicExpression, visualDesigned: $visualDesigned)'; return 'ComponentEntry(componentId: $componentId, componentName: $componentName, componentDescription: $componentDescription, inputs: $inputs, outputs: $outputs, truthTable: $truthTable, logicExpression: $logicExpression, visualDesigned: $visualDesigned, dependencies: $dependencies)';
} }
@override @override
@ -415,7 +438,9 @@ class _$_ComponentEntry implements _ComponentEntry {
const DeepCollectionEquality() const DeepCollectionEquality()
.equals(other._logicExpression, _logicExpression) && .equals(other._logicExpression, _logicExpression) &&
const DeepCollectionEquality() const DeepCollectionEquality()
.equals(other.visualDesigned, visualDesigned)); .equals(other.visualDesigned, visualDesigned) &&
const DeepCollectionEquality()
.equals(other._dependencies, _dependencies));
} }
@JsonKey(ignore: true) @JsonKey(ignore: true)
@ -429,7 +454,8 @@ class _$_ComponentEntry implements _ComponentEntry {
const DeepCollectionEquality().hash(_outputs), const DeepCollectionEquality().hash(_outputs),
const DeepCollectionEquality().hash(_truthTable), const DeepCollectionEquality().hash(_truthTable),
const DeepCollectionEquality().hash(_logicExpression), const DeepCollectionEquality().hash(_logicExpression),
const DeepCollectionEquality().hash(visualDesigned)); const DeepCollectionEquality().hash(visualDesigned),
const DeepCollectionEquality().hash(_dependencies));
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
@ -444,15 +470,20 @@ class _$_ComponentEntry implements _ComponentEntry {
abstract class _ComponentEntry implements ComponentEntry { abstract class _ComponentEntry implements ComponentEntry {
const factory _ComponentEntry( const factory _ComponentEntry(
{required final String componentId, {required final String componentId,
required final String componentName, required final String componentName,
@JsonKey(includeIfNull: false) final String? componentDescription, @JsonKey(includeIfNull: false)
required final List<String> inputs, final String? componentDescription,
required final List<String> outputs, required final List<String> inputs,
@JsonKey(includeIfNull: false) final List<String>? truthTable, required final List<String> outputs,
@JsonKey(includeIfNull: false) final List<String>? logicExpression, @JsonKey(includeIfNull: false)
@JsonKey(defaultValue: false) required final bool visualDesigned}) = final List<String>? truthTable,
_$_ComponentEntry; @JsonKey(includeIfNull: false)
final List<String>? logicExpression,
@JsonKey(defaultValue: false)
required final bool visualDesigned,
@JsonKey(defaultValue: [])
required final List<String> dependencies}) = _$_ComponentEntry;
factory _ComponentEntry.fromJson(Map<String, dynamic> json) = factory _ComponentEntry.fromJson(Map<String, dynamic> json) =
_$_ComponentEntry.fromJson; _$_ComponentEntry.fromJson;
@ -478,6 +509,9 @@ abstract class _ComponentEntry implements ComponentEntry {
@JsonKey(defaultValue: false) @JsonKey(defaultValue: false)
bool get visualDesigned => throw _privateConstructorUsedError; bool get visualDesigned => throw _privateConstructorUsedError;
@override @override
@JsonKey(defaultValue: [])
List<String> get dependencies => throw _privateConstructorUsedError;
@override
@JsonKey(ignore: true) @JsonKey(ignore: true)
_$$_ComponentEntryCopyWith<_$_ComponentEntry> get copyWith => _$$_ComponentEntryCopyWith<_$_ComponentEntry> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;

View file

@ -34,6 +34,10 @@ _$_ComponentEntry _$$_ComponentEntryFromJson(Map<String, dynamic> json) =>
?.map((e) => e as String) ?.map((e) => e as String)
.toList(), .toList(),
visualDesigned: json['visualDesigned'] as bool? ?? false, visualDesigned: json['visualDesigned'] as bool? ?? false,
dependencies: (json['dependencies'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ??
[],
); );
Map<String, dynamic> _$$_ComponentEntryToJson(_$_ComponentEntry instance) { Map<String, dynamic> _$$_ComponentEntryToJson(_$_ComponentEntry instance) {
@ -54,5 +58,6 @@ Map<String, dynamic> _$$_ComponentEntryToJson(_$_ComponentEntry instance) {
writeNotNull('truthTable', instance.truthTable); writeNotNull('truthTable', instance.truthTable);
writeNotNull('logicExpression', instance.logicExpression); writeNotNull('logicExpression', instance.logicExpression);
val['visualDesigned'] = instance.visualDesigned; val['visualDesigned'] = instance.visualDesigned;
val['dependencies'] = instance.dependencies;
return val; return val;
} }

View file

@ -168,9 +168,12 @@ class EditComponentPage extends HookWidget {
sliver: SliverToBoxAdapter( sliver: SliverToBoxAdapter(
child: TextField( child: TextField(
controller: componentNameEditingController, controller: componentNameEditingController,
decoration: const InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: 'Component name', labelText: 'Component name',
errorText: projectState.index.components.where((c) => c.componentId != ce().componentId).map((c) => c.componentName).contains(componentNameEditingController.text.trim())
? 'A component with the same name already exists'
: null,
), ),
), ),
), ),
@ -449,6 +452,13 @@ class EditComponentPage extends HookWidget {
child: const Text('Visual Designer'), child: const Text('Visual Designer'),
), ),
), ),
const Padding(
padding: EdgeInsets.all(8.0),
child: OutlinedButton(
onPressed: null,
child: const Text('Script'),
),
),
], ],
), ),
), ),
@ -570,7 +580,7 @@ class EditComponentPage extends HookWidget {
floatingActionButton: !dirty ? null : FloatingActionButton( floatingActionButton: !dirty ? null : FloatingActionButton(
onPressed: () async { onPressed: () async {
if (componentNameEditingController.text.isNotEmpty) { if (componentNameEditingController.text.isNotEmpty) {
await projectState.editComponent(ce().copyWith(componentName: componentNameEditingController.text)); await projectState.editComponent(ce().copyWith(componentName: componentNameEditingController.text.trim()));
} }
await projectState.editComponent(ce().copyWith( await projectState.editComponent(ce().copyWith(
inputs: inputs.value, inputs: inputs.value,

View file

@ -77,6 +77,7 @@ class ProjectState extends ChangeNotifier {
inputs: [], inputs: [],
outputs: [], outputs: [],
visualDesigned: false, visualDesigned: false,
dependencies: [],
); );
await _updateIndex(index.copyWith(components: index.components + [newComponent])); await _updateIndex(index.copyWith(components: index.components + [newComponent]));
return newComponent; return newComponent;