Skip to content

Commit

Permalink
added new fields. Updates dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sirily11 committed Apr 19, 2020
1 parent 5be03c7 commit 8c56497
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 63 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@
## [0.8.5]

- Fixed bugs

## [1.0.0]

- Added checkbox field
- Added dropdown menu for selection field
- Added tests
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ This is the plugin for flutter using JSON Schema to define the form itself.
It supports:

- Textfield
- Selection field
- forignkey field
- Selection Field
- forignkey Field
- qrcode scanning
- Checkbox Field
- DateTime Field
- custom field icon and action

Expand Down
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"barcode_scan","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/barcode_scan-2.0.1/","dependencies":[]},{"name":"image_picker","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.3+1/","dependencies":[]},{"name":"permission_handler","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-4.4.0+hotfix.1/","dependencies":[]}],"android":[{"name":"barcode_scan","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/barcode_scan-2.0.1/","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.5/","dependencies":[]},{"name":"image_picker","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.3+1/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-4.4.0+hotfix.1/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"barcode_scan","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-04-16 05:39:01.229828","version":"1.15.17"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"barcode_scan","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/barcode_scan-3.0.0/","dependencies":[]},{"name":"image_picker","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.5/","dependencies":[]},{"name":"permission_handler","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.0+hotfix.3/","dependencies":[]}],"android":[{"name":"barcode_scan","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/barcode_scan-3.0.0/","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.5/","dependencies":[]},{"name":"image_picker","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.5/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.0+hotfix.3/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"barcode_scan","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-04-18 22:22:43.973813","version":"1.15.17"}
27 changes: 27 additions & 0 deletions example/lib/data/sample_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,33 @@ Map<String, dynamic> itemJSONData2 = {
"translated": false,
"validations": {}
},
{
"label": "show in folder",
"readonly": false,
"extra": {"default": true, "help": "Select your widget"},
"name": "show_in_folder",
"widget": "checkbox",
"required": false,
"translated": false,
"validations": {}
},
{
"label": "unit",
"readonly": false,
"extra": {
"choices": [
{"label": "US Dollar", "value": "USD"},
{"label": "Hong Kong Dollar", "value": "HDK"},
{"label": "RMB", "value": "CNY"}
],
"default": "USD"
},
"name": "unit",
"widget": "select",
"required": false,
"translated": false,
"validations": {}
},
{
"label": "created time",
"readonly": true,
Expand Down
4 changes: 3 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _MyHomePageState extends State<MyHomePage> {
ThemeData buildTheme() {
final ThemeData base = ThemeData();
return base.copyWith(
iconTheme: IconThemeData(color: Colors.white),
iconTheme: IconThemeData(color: Colors.grey),
inputDecorationTheme: InputDecorationTheme(
fillColor: Colors.blue,
border: OutlineInputBorder(
Expand All @@ -55,6 +55,7 @@ class _MyHomePageState extends State<MyHomePage> {
title: Text("Form"),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.publish),
onPressed: () async {
var value = await this.controller.onSubmit(context);
print(value);
Expand All @@ -71,6 +72,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: JSONSchemaForm(
rounded: true,
controller: controller,
useDropdownButton: true,
schema: (snapshot.data['fields'] as List)
.map((s) => s as Map<String, dynamic>)
.toList(),
Expand Down
26 changes: 20 additions & 6 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ packages:
name: barcode_scan
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "3.0.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -77,7 +77,14 @@ packages:
name: dio
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.8"
version: "3.0.9"
fixnum:
dependency: transitive
description:
name: fixnum
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.11"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -115,14 +122,14 @@ packages:
name: image_picker
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3+1"
version: "0.6.5"
json_schema_form:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.8.5"
version: "1.0.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -157,14 +164,14 @@ packages:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "4.4.0+hotfix.1"
version: "5.0.0+hotfix.3"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "2.0.0"
petitparser:
dependency: transitive
description:
Expand All @@ -186,6 +193,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
protobuf:
dependency: transitive
description:
name: protobuf
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
provider:
dependency: transitive
description:
Expand Down
48 changes: 35 additions & 13 deletions lib/json_textform/JSONForm.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:json_schema_form/json_textform/components/JSONCheckboxField.dart';
import 'package:json_schema_form/json_textform/components/JSONDateTimeField.dart';
import 'package:json_schema_form/json_textform/components/JSONForignKeyField.dart';
import 'package:json_schema_form/json_textform/components/JSONSelectField.dart';
Expand Down Expand Up @@ -52,16 +53,25 @@ class JSONForm extends StatefulWidget {
/// Round corner of text field
final bool rounded;

JSONForm(
{@required this.schema,
this.onSubmit,
this.icons,
this.actions,
this.values,
this.rounded = false,
this.schemaName,
this.controller,
this.showSubmitButton = false});
/// Whether use dropdown button instead of using
/// another page to show choices.
/// This will only apply for the select field,
/// but not forign key field based on current
/// implementation. Default is false
final bool useDropdownButton;

JSONForm({
@required this.schema,
this.onSubmit,
this.icons,
this.actions,
this.values,
this.rounded = false,
this.schemaName,
this.controller,
this.showSubmitButton = false,
this.useDropdownButton,
});

@override
_JSONSchemaFormState createState() => _JSONSchemaFormState();
Expand All @@ -80,8 +90,10 @@ class _JSONSchemaFormState extends State<JSONForm> {
/// Merge actions
if (widget.actions != null) {
if (Platform.isIOS || Platform.isAndroid) {
PermissionHandler()
.requestPermissions([PermissionGroup.camera]).then((m) => null);
[
Permission.location,
Permission.storage,
].request().then((v) => print("requested permission"));
}

schemaList =
Expand Down Expand Up @@ -117,11 +129,21 @@ class _JSONSchemaFormState extends State<JSONForm> {
});
},
);

case WidgetType.checkbox:
return JSONCheckboxField(
schema: schema,
isOutlined: widget.rounded,
onSaved: (v) {
setState(() {
schema.value = v;
});
},
);
case (WidgetType.select):
return JSONSelectField(
isOutlined: widget.rounded,
schema: schema,
useDropdownButton: widget.useDropdownButton,
onSaved: (Choice value) {
setState(() {
schema.value = value.value;
Expand Down
32 changes: 21 additions & 11 deletions lib/json_textform/JSONSchemaForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,28 @@ class JSONSchemaForm extends StatefulWidget {
/// Whether show submit button
final bool showSubmitButton;

/// Whether use dropdown button instead of using
/// another page to show choices.
/// This will only apply for the select field,
/// but not forign key field based on current
/// implementation. Default is false
final bool useDropdownButton;

final Dio networkProvider = Dio();

JSONSchemaForm(
{@required this.schema,
this.onSubmit,
this.icons,
this.actions,
this.values,
this.rounded = false,
this.schemaName,
this.controller,
this.url = "http://0.0.0.0",
this.showSubmitButton = true});
JSONSchemaForm({
@required this.schema,
this.onSubmit,
this.icons,
this.actions,
this.values,
this.rounded = false,
this.schemaName,
this.controller,
this.url = "http://0.0.0.0",
this.showSubmitButton = true,
this.useDropdownButton = false,
});

@override
_JSONSchemaFormState createState() => _JSONSchemaFormState();
Expand Down Expand Up @@ -99,6 +108,7 @@ class _JSONSchemaFormState extends State<JSONSchemaForm> {
rounded: widget.rounded,
controller: widget.controller,
showSubmitButton: widget.showSubmitButton,
useDropdownButton: widget.useDropdownButton,
),
);
}
Expand Down
32 changes: 32 additions & 0 deletions lib/json_textform/components/JSONCheckboxField.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:json_schema_form/json_textform/components/SelectionPage.dart';
import 'package:json_schema_form/json_textform/models/Icon.dart';
import 'package:json_schema_form/json_textform/models/Schema.dart';

typedef void OnChange(bool value);

class JSONCheckboxField extends StatelessWidget {
final Schema schema;
final OnChange onSaved;
final bool showIcon;
final bool isOutlined;

JSONCheckboxField({
@required this.schema,
this.onSaved,
this.showIcon = true,
this.isOutlined = false,
});

@override
Widget build(BuildContext context) {
return CheckboxListTile(
value: schema.value ?? schema?.extra?.defaultValue ?? false,
onChanged: (v) {
onSaved(v);
},
title: Text("${schema.label}"),
subtitle: Text("${schema?.extra?.helpText ?? ""}"),
);
}
}
56 changes: 50 additions & 6 deletions lib/json_textform/components/JSONSelectField.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,66 @@
import 'package:flutter/material.dart';
import 'package:json_schema_form/json_textform/components/SelectionPage.dart';
import 'package:json_schema_form/json_textform/models/Icon.dart';
import 'package:json_schema_form/json_textform/models/Schema.dart';

typedef void OnChange(Choice choice);

class JSONSelectField extends StatelessWidget {
final Schema schema;
final Function onSaved;
final OnChange onSaved;
final bool showIcon;
final bool isOutlined;

JSONSelectField(
{@required this.schema,
this.onSaved,
this.showIcon = true,
this.isOutlined = false});
/// implementation. Default is false
final bool useDropdownButton;

JSONSelectField({
@required this.schema,
this.onSaved,
this.showIcon = true,
this.isOutlined = false,
@required this.useDropdownButton,
});

@override
Widget build(BuildContext context) {
if (useDropdownButton) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 2),
child: Row(
children: <Widget>[
if (schema.icon != null)
Icon(
schema.icon.iconData,
color: Theme.of(context).iconTheme.color,
),
Spacer(),
Expanded(
flex: 9,
child: DropdownButton(
hint: Text("Select ${schema.label}"),
isExpanded: true,
onChanged: (v) {
this.onSaved(v);
},
value: schema?.extra?.choices?.firstWhere(
(element) => element.value == schema.value,
orElse: () => null,
),
items: schema?.extra?.choices
?.map(
(e) => DropdownMenuItem(
value: e,
child: Text(e.label),
),
)
?.toList(),
),
),
],
),
);
}
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 2),
child: Container(
Expand Down
Loading

0 comments on commit 8c56497

Please sign in to comment.