Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
31 changes: 12 additions & 19 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,21 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
Expand All @@ -56,7 +49,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -94,28 +87,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
simple_json_form:
dependency: "direct main"
description:
Expand All @@ -134,7 +127,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -155,21 +148,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
vector_math:
dependency: transitive
description:
Expand Down
115 changes: 58 additions & 57 deletions lib/src/controller/simple_json_form_controller.dart
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
import 'package:flutter/widgets.dart';
import 'package:simple_json_form/simple_json_form.dart';
import 'package:simple_json_form/src/model/raw_builder.dart';

class SimpleJsonFormController {
SimpleJsonFormController({required this.jsonSchema}) {
controllerMapping = generateKeyMapping(jsonSchema);
}

final JsonSchema jsonSchema;

static Map<String, TextEditingController> controllerMapping = {};

Map<String, TextEditingController> generateKeyMapping(JsonSchema jsonSchema) {
Map<String, TextEditingController> keyMapping = {};
for (var entry in jsonSchema.form) {
for (Properties property in entry.properties ?? []) {
// if (property.remark) {
// keyMapping['${property.key}_remark'] = TextEditingController();
// }
if (property.type == JsonSchemaType.format1) {
if (property.raw != null) {
final mapRaw = generateKeyMappingFormBuilder(property.raw!);
keyMapping.addAll(mapRaw);
}
}

if (property.type == JsonSchemaType.text ||
property.type == JsonSchemaType.number ||
property.type == JsonSchemaType.date ||
property.type == JsonSchemaType.time) {
keyMapping[property.key] = TextEditingController();
}
}
}
return keyMapping;
}

Map<String, TextEditingController> generateKeyMappingFormBuilder(List<RawBuilder> formBuilders) {
Map<String, TextEditingController> keyMapping = {};
for (var entry in formBuilders) {
for (Properties property in entry.properties) {
if (property.type == JsonSchemaType.text ||
property.type == JsonSchemaType.number ||
property.type == JsonSchemaType.date ||
property.type == JsonSchemaType.time) {
keyMapping[property.key] = TextEditingController();
}
}
}
return keyMapping;
}

static TextEditingController? getKeyController(String key) {
return controllerMapping.containsKey(key) ? controllerMapping[key] : null;
}
}
import 'package:flutter/widgets.dart';
import 'package:simple_json_form/simple_json_form.dart';
import 'package:simple_json_form/src/model/raw_builder.dart';

class SimpleJsonFormController {
SimpleJsonFormController({required this.jsonSchema}) {
controllerMapping = generateKeyMapping(jsonSchema);
}

final JsonSchema jsonSchema;

static Map<String, TextEditingController> controllerMapping = {};

Map<String, TextEditingController> generateKeyMapping(JsonSchema jsonSchema) {
Map<String, TextEditingController> keyMapping = {};
for (var entry in jsonSchema.form) {
for (Properties property in entry.properties ?? []) {
// if (property.remark) {
// keyMapping['${property.key}_remark'] = TextEditingController();
// }
if (property.type == JsonSchemaType.format1) {
if (property.raw != null) {
final mapRaw = generateKeyMappingFormBuilder(property.raw!);
keyMapping.addAll(mapRaw);
}
}

if (property.type == JsonSchemaType.text ||
property.type == JsonSchemaType.number ||
property.type == JsonSchemaType.date ||
property.type == JsonSchemaType.time) {
keyMapping[property.key] = TextEditingController();
}
}
}
return keyMapping;
}

Map<String, TextEditingController> generateKeyMappingFormBuilder(
List<RawBuilder> formBuilders) {
Map<String, TextEditingController> keyMapping = {};
for (var entry in formBuilders) {
for (Properties property in entry.properties) {
if (property.type == JsonSchemaType.text ||
property.type == JsonSchemaType.number ||
property.type == JsonSchemaType.date ||
property.type == JsonSchemaType.time) {
keyMapping[property.key] = TextEditingController();
}
}
}
return keyMapping;
}

static TextEditingController? getKeyController(String key) {
return controllerMapping.containsKey(key) ? controllerMapping[key] : null;
}
}
43 changes: 24 additions & 19 deletions lib/src/key/simple_json_form_key.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import 'package:flutter/widgets.dart';
import 'package:simple_json_form/simple_json_form.dart';

class SimpleJsonFormKey {
SimpleJsonFormKey({required this.jsonSchema}) {
keyMapping = generateKeyMapping(jsonSchema);
}

final JsonSchema jsonSchema;
static Map<String, GlobalKey<FormState>> keyMapping = {};

Map<String, GlobalKey<FormState>> generateKeyMapping(JsonSchema jsonSchema) {
Map<String, GlobalKey<FormState>> keyMapping = {};
for (var entry in jsonSchema.form) {
keyMapping[entry.key] = GlobalKey<FormState>();
}
return keyMapping;
}
}
import 'package:flutter/widgets.dart';
import 'package:simple_json_form/simple_json_form.dart';

class SimpleJsonFormKey {
SimpleJsonFormKey({required this.jsonSchema}) {
keyMapping = generateKeyMapping(jsonSchema);
}

final JsonSchema jsonSchema;
static Map<String, GlobalKey<FormState>> keyMapping = {};

Map<String, GlobalKey<FormState>> generateKeyMapping(JsonSchema jsonSchema) {
Map<String, GlobalKey<FormState>> keyMapping = {};
for (var entry in jsonSchema.form) {
keyMapping[entry.key] = GlobalKey<FormState>();
}
return keyMapping;
}

static final formKey = GlobalKey<FormState>();
static GlobalKey<FormState> generateFormKeyMapping() {
return formKey;
}
}
Loading