Skip to content

Commit

Permalink
added dialog style
Browse files Browse the repository at this point in the history
  • Loading branch information
sirily11 committed Jul 12, 2020
1 parent c32b042 commit 2a57267
Show file tree
Hide file tree
Showing 25 changed files with 793 additions and 386 deletions.
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-3.0.0/","dependencies":[]},{"name":"file_picker","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_picker-1.12.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.1+1/","dependencies":[]}],"android":[{"name":"barcode_scan","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/barcode_scan-3.0.0/","dependencies":[]},{"name":"file_picker","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_picker-1.12.0/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.8/","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.1+1/","dependencies":[]}],"macos":[{"name":"file_chooser","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_chooser-0.1.3/","dependencies":[]}],"linux":[{"name":"file_chooser","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_chooser-0.1.3/","dependencies":[]}],"windows":[{"name":"file_chooser","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_chooser-0.1.3/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"barcode_scan","dependencies":[]},{"name":"file_chooser","dependencies":[]},{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-07-11 23:49:39.200979","version":"1.20.0-7.1.pre"}
{"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":"file_picker","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_picker-1.12.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.1+1/","dependencies":[]}],"android":[{"name":"barcode_scan","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/barcode_scan-3.0.0/","dependencies":[]},{"name":"file_picker","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_picker-1.12.0/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.8/","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.1+1/","dependencies":[]}],"macos":[{"name":"file_chooser","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_chooser-0.1.3/","dependencies":[]}],"linux":[{"name":"file_chooser","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_chooser-0.1.3/","dependencies":[]}],"windows":[{"name":"file_chooser","path":"/Users/liqiwei/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/file_chooser-0.1.3/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"barcode_scan","dependencies":[]},{"name":"file_chooser","dependencies":[]},{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","dependencies":[]}],"date_created":"2020-07-12 09:13:10.722461","version":"1.20.0-7.1.pre"}
2 changes: 1 addition & 1 deletion example/lib/components/DatetimeFieldDemo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DatetimeFieldDemo extends StatelessWidget {

return Scaffold(
appBar: AppBar(
title: Text("CheckBox Preview"),
title: Text("Datetime Field Preview"),
),
body: Container(
height: MediaQuery.of(context).size.height,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/components/FileFieldDemo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FileFieldDemo extends StatelessWidget {

return Scaffold(
appBar: AppBar(
title: Text("CheckBox Preview"),
title: Text("FileField Preview"),
),
body: Container(
height: MediaQuery.of(context).size.height,
Expand Down
6 changes: 5 additions & 1 deletion example/lib/components/ForeignkeyDemo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class _ForeignkeyDemoState extends State<ForeignkeyDemo> {
children: <Widget>[
JSONSchemaForm(
schema: schema,
useDialog: homeProvider.useDialog,
showSubmitButton: homeProvider.showSubmitButton,
filled: homeProvider.isFilled,
rounded: homeProvider.isRounded,
Expand All @@ -67,10 +68,13 @@ class _ForeignkeyDemoState extends State<ForeignkeyDemo> {
(element) => element.value == id,
orElse: () => null,
);

if (choice != null) {
return SchemaValues(
schema: detailSchema,
values: choice.toJson(),
values: {
"title": choice.label,
},
);
}
}
Expand Down
123 changes: 123 additions & 0 deletions example/lib/components/ManyToManyFieldDemo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import 'package:flutter/material.dart';
import 'package:json_schema_form/json_textform/JSONForm.dart';
import 'package:json_schema_form/json_textform/JSONSchemaForm.dart';
import 'package:json_schema_form/json_textform/models/Schema.dart';
import 'package:json_schema_form/json_textform/models/components/Icon.dart';
import 'package:json_schema_form_example/menubutton/MenuButton.dart';
import 'package:json_schema_form_example/model/HomeProvider.dart';
import 'package:provider/provider.dart';

class ManyToManyFieldDemo extends StatefulWidget {
@override
_ManyToManyFieldDemoState createState() => _ManyToManyFieldDemoState();
}

class _ManyToManyFieldDemoState extends State<ManyToManyFieldDemo> {
List<Choice> choices = [];

@override
Widget build(BuildContext context) {
final schema = [
{
"label": "videos",
"readonly": false,
"extra": {"related_model": "podcast/video"},
"name": "video_list",
"widget": "manytomany-lists",
"required": false,
"translated": false,
"validations": {}
},
];

final detailSchema = [
{
"label": "Title",
"readonly": false,
"extra": {"help": "Please Enter your item name", "default": ""},
"name": "title",
"widget": "text",
"required": true,
"translated": false,
"validations": {
"length": {"maximum": 1024}
}
},
];

HomeProvider homeProvider = Provider.of(context);

return Scaffold(
appBar: AppBar(
title: Text("ManyToManyField Preview"),
),
body: Container(
height: MediaQuery.of(context).size.height,
child: Stack(
children: <Widget>[
JSONSchemaForm(
schema: schema,
useDialog: homeProvider.useDialog,
showSubmitButton: homeProvider.showSubmitButton,
filled: homeProvider.isFilled,
rounded: homeProvider.isRounded,
useDropdownButton: homeProvider.useDropdown,
onFetchingSchema: (path, isEdit, id) async {
if (isEdit) {
var choice = choices.firstWhere(
(element) => element.value == id,
orElse: () => null,
);

if (choice != null) {
return SchemaValues(
schema: detailSchema,
values: {
"title": choice.label,
},
);
}
}
return SchemaValues(schema: detailSchema, values: {});
},
onFetchingforeignKeyChoices: (path) async {
return choices;
},
onAddforeignKeyField: (path, values) async {
var choice = Choice(
label: values['title'],
value: choices.length,
);
setState(() {
choices.add(choice);
});
return choice;
},
onUpdateforeignKeyField: (path, values, id) async {
var index =
choices.indexWhere((element) => element.value == id);
if (index > -1) {
setState(() {
choices[index].label = values['title'];
});
}
return choices[index];
},
onDeleteforeignKeyField: (path, id) async {
var removed = choices.removeAt(id);
return removed;
},
icons: [
FieldIcon(
iconData: Icons.title,
schemaName: "unit",
),
],
),
MenuButton(),
],
),
),
);
}
}
11 changes: 9 additions & 2 deletions example/lib/components/SelectionFieldDemo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ class SelectionFieldDemo extends StatelessWidget {
"choices": [
{"label": "US Dollar", "value": "USD"},
{"label": "Hong Kong Dollar", "value": "HDK"},
{"label": "RMB", "value": "CNY"}
{"label": "RMB", "value": "CNY"},
{"label": "US Dollar", "value": "1"},
{"label": "US Dollar", "value": "2"},
{"label": "US Dollar", "value": "3"},
{"label": "US Dollar", "value": "4"},
{"label": "US Dollar", "value": "5"},
{"label": "US Dollar", "value": "6"},
],
"default": "USD"
},
Expand All @@ -32,14 +38,15 @@ class SelectionFieldDemo extends StatelessWidget {

return Scaffold(
appBar: AppBar(
title: Text("CheckBox Preview"),
title: Text("Selection Field Preview"),
),
body: Container(
height: MediaQuery.of(context).size.height,
child: Stack(
children: <Widget>[
JSONSchemaForm(
schema: schema,
useDialog: homeProvider.useDialog,
showSubmitButton: homeProvider.showSubmitButton,
filled: homeProvider.isFilled,
rounded: homeProvider.isRounded,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/components/TextFieldInListView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TextFieldInListView extends StatelessWidget {

return Scaffold(
appBar: AppBar(
title: Text("TextField Preview"),
title: Text("TextField List View Preview"),
),
body: Stack(
children: <Widget>[
Expand Down
5 changes: 5 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:json_schema_form/json_textform/models/Controller.dart';
import 'package:json_schema_form_example/components/CheckBoxDemo.dart';
import 'package:json_schema_form_example/components/DatetimeFieldDemo.dart';
import 'package:json_schema_form_example/components/FileFieldDemo.dart';
import 'package:json_schema_form_example/components/ManyToManyFieldDemo.dart';
import 'package:json_schema_form_example/components/SelectionFieldDemo.dart';
import 'package:json_schema_form_example/components/TextFieidDemo.dart';
import 'package:json_schema_form_example/components/TextFieldInListView.dart';
Expand Down Expand Up @@ -82,6 +83,10 @@ class _MyHomePageState extends State<MyHomePage> {
title: "File Field",
page: FileFieldDemo(),
),
DemoPage(
title: "ManyToMany Field",
page: ManyToManyFieldDemo(),
),
DemoPage(
title: "Text Field in ListView",
page: TextFieldInListView(),
Expand Down
5 changes: 5 additions & 0 deletions example/lib/menubutton/MenuButton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class MenuButton extends StatelessWidget {
title: Text("Use Dropdown"),
value: homeProvider.useDropdown,
onChanged: (v) => homeProvider.useDropdown = v,
),
CheckboxListTile(
title: Text("Use Dialog"),
value: homeProvider.useDialog,
onChanged: (v) => homeProvider.useDialog = v,
)
],
),
Expand Down
8 changes: 8 additions & 0 deletions example/lib/model/HomeProvider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ class HomeProvider with ChangeNotifier {
bool _showSubmitButton = true;
bool _isRounded = false;
bool _useDropdown = false;
bool _useDialog = false;

bool get useDialog => _useDialog;

set useDialog(bool value) {
_useDialog = value;
notifyListeners();
}

bool get useDropdown => _useDropdown;

Expand Down
7 changes: 7 additions & 0 deletions lib/json_textform/JSONForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class JSONForm extends StatefulWidget {

final OnDeleteforeignKeyField onDeleteforeignKeyField;

final bool useDialog;

/// [optional] Schema controller.
/// Call this to get value back from fields if you want to have
/// your custom submit button.
Expand Down Expand Up @@ -136,6 +138,7 @@ class JSONForm extends StatefulWidget {
this.controller,
this.showSubmitButton = false,
this.useDropdownButton,
@required this.useDialog,
@required this.onDeleteforeignKeyField,
@required this.onFileUpload,
@required this.onFetchingSchema,
Expand Down Expand Up @@ -230,6 +233,7 @@ class _JSONSchemaFormState extends State<JSONForm> {
);
case WidgetType.select:
return JSONSelectField(
useDialog: widget.useDialog,
filled: widget.filled,
isOutlined: widget.rounded,
schema: schema,
Expand All @@ -245,6 +249,7 @@ class _JSONSchemaFormState extends State<JSONForm> {
return JSONManyToManyField(
schema: schema,
filled: widget.filled,
useDialog: widget.useDialog,
isOutlined: widget.rounded,
onAddforeignKeyField: widget.onAddforeignKeyField,
onUpdateforeignKeyField: widget.onUpdateforeignKeyField,
Expand All @@ -265,6 +270,7 @@ class _JSONSchemaFormState extends State<JSONForm> {
case WidgetType.foreignkey:
return JSONForeignkeyField(
filled: widget.filled,
useDialog: widget.useDialog,
onAddforeignKeyField: widget.onAddforeignKeyField,
onUpdateforeignKeyField: widget.onUpdateforeignKeyField,
onDeleteforeignKeyField: widget.onDeleteforeignKeyField,
Expand Down Expand Up @@ -299,6 +305,7 @@ class _JSONSchemaFormState extends State<JSONForm> {
case WidgetType.text:
case WidgetType.number:
case WidgetType.unknown:
case WidgetType.url:
return JSONTextFormField(
key: Key(schema.name),
schema: schema,
Expand Down
25 changes: 25 additions & 0 deletions lib/json_textform/JSONSchemaForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import 'models/components/Icon.dart';
/// Which will take a schema input
/// and generate a form
class JSONSchemaForm extends StatelessWidget {
/// Use dialog instead of normal materialPageRoute
final bool useDialog;

/// Text form style is filled
final bool filled;

Expand All @@ -26,18 +29,35 @@ class JSONSchemaForm extends StatelessWidget {

/// Update foreign key's value and return Choice represents the update value.
/// return null if nothing change
///
/// * [path] A string represents current model's relatedModel value
/// * [values] A map of values where key represents field's name
/// and value represents field's value
/// * [id] a string/number represents the current object
final OnUpdateforeignKeyField onUpdateforeignKeyField;

/// Whenever user want to add foreignkey, this function will be called.
/// Should return a choice object after creating foreignkey.
///
/// * [path] A string represents current model's relatedModel value
/// * [values] A map of values where key represents field's name
/// and value represents field's value
final OnAddforeignKeyField onAddforeignKeyField;

/// Fetching foreign key's schema. Will be used to generate form for
/// foreignkey.
///
/// * [path] A string represents current model's relatedModel value
/// * [isEdit] A bool represents current mode. If true, then
/// should return a schema and values, otherwise, should return schema only
/// * [id] A value represents current object. Will be null if [isEdit] is false.
final OnFetchingSchema onFetchingSchema;

/// Whenever user want to delete a foreignkey object, this function
/// will be called
///
/// * [path] A string represents current model's relatedModel value
/// * [id] a string/number represents the current object
final OnDeleteforeignKeyField onDeleteforeignKeyField;

/// Schema's name
Expand All @@ -63,6 +83,9 @@ class JSONSchemaForm extends StatelessWidget {

/// Will call this function after user
/// clicked the submit button
///
/// * [json] A map. keys represent fields' name
/// and values represent fields' value
final OnSubmit onSubmit;

/// URL for foreignkey
Expand Down Expand Up @@ -99,6 +122,7 @@ class JSONSchemaForm extends StatelessWidget {
this.showSubmitButton = true,
this.useDropdownButton = false,
this.onFileUpload,
this.useDialog = false,
@required this.onFetchingSchema,
@required this.onFetchingforeignKeyChoices,
@required this.onAddforeignKeyField,
Expand Down Expand Up @@ -127,6 +151,7 @@ class JSONSchemaForm extends StatelessWidget {
values: values,
rounded: rounded,
controller: controller,
useDialog: useDialog,
showSubmitButton: showSubmitButton,
useDropdownButton: useDropdownButton,
onFetchingSchema: onFetchingSchema,
Expand Down
Loading

0 comments on commit 2a57267

Please sign in to comment.