Skip to content
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

Refactoring ramil #20

Merged
merged 4 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions lib/json_schema_ui/json_schema_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import 'fields/json_schema_field.dart';
class JSONSchemaUI extends StatelessWidget {
JSONSchemaUI(
{Key? key,
this.schema = const {},
this.ui = const {},
this.data = const {},
UIModel? controller,
required this.onUpdate})
this.schema = const {},
this.ui = const {},
this.data = const {},
UIModel? controller,
required this.onUpdate})
: fields = schema['properties']?.keys?.toList() ?? [],
controller = (controller == null)
? UIModel()
Expand All @@ -29,6 +29,8 @@ class JSONSchemaUI extends StatelessWidget {
final UIModel controller;
final void Function(
{required MapPath path, required Map<String, dynamic> data})? onUpdate;
final _formKey = GlobalKey<FormState>();


@override
Widget build(BuildContext context) {
Expand All @@ -37,11 +39,31 @@ class JSONSchemaUI extends StatelessWidget {
// create: (context) => UIModel(data: data, onUpdate: onUpdate),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: JSONSchemaUIField(
schema: schema,
ui: ui,
child: Form(
key: _formKey,
child: Column(
children: [
JSONSchemaUIField(
schema: schema,
ui: ui,
),

// Button that submit the whole form using global key
ElevatedButton(
onPressed: (){
if (_formKey.currentState!.validate()) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Processing Data')),
);
}
},
child: const Text("Submit"),
),
],
),

),
),
);
}
}
}
11 changes: 5 additions & 6 deletions lib/json_schema_ui/widgets/array_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ import '../models/mapPath.dart';

class ArrayPanel extends StatelessWidget {
const ArrayPanel(this.path, {Key? key}) : super(key: key);

final MapPath path;

@override
Widget build(BuildContext context) {
return Row(
children: [
ElevatedButton(
onPressed: () => onAdd(context, path), child: const Text('+')
),
onPressed: () => onAdd(context, path), child: const Text('+')),
ElevatedButton(
onPressed: () => onRemove(context, path), child: const Text('-')
),
onPressed: () => onRemove(context, path), child: const Text('-')),
],
);
}

void onAdd(BuildContext context, MapPath path) {
Provider.of<UIModel>(context, listen: false).addArrayElement(path);
}

void onRemove(BuildContext context, MapPath path) {
Provider.of<UIModel>(context, listen: false).removeArrayElement(path);
}
}
}
Loading