convert json
a flutter plugin to use convert json to form.
instalation
- add this to your package’s pubspec.yaml file:
dependencies:
json_to_form: "^0.0.1"
- you can install packages from the command line:
with flutter:
$ flutter packages get
- import it now in your dart code, you can use:
import 'package:json_to_form/json_to_form.dart';
usage
- textfield
string form = json.encode([
{
'type': 'input',
'title': 'hi group',
'placeholder': "hi group flutter"
},
{
'type': 'password',
'title': 'password',
},
{
'type': 'email',
'title': 'email test',
'placeholder': "hola a todos"
},
{
'type': 'tareatext',
'title': 'tareatext test',
'placeholder': "hola a todos"
},
]);
- radio
string form = json.encode([
{
'type': 'radiobutton',
'title': 'radio button tests',
'value': 2,
'list': [
{
'title': "product 1",
'value': 1,
},
{
'title': "product 2",
'value': 2,
},
{
'title': "product 3",
'value': 3,
}
]
},
]);
- switch
string form = json.encode([
{
'type': 'switch',
'title': 'switch test',
'switchvalue': false,
},
]);
- checkbox
string form = json.encode([
{
'type': 'checkbox',
'title': 'checkbox test 2',
'list': [
{
'title': "product 1",
'value': true,
},
{
'title': "product 2",
'value': true,
},
{
'title': "product 3",
'value': false,
}
]
},
]);
- example
string form_send_email = json.encode([
{'type': 'input', 'title': 'subject', 'placeholder': "subject"},
{'type': 'tareatext', 'title': 'message', 'placeholder': "content"},
]);
dynamic response;
@override
widget build(buildcontext context) {
return new scaffold(
appbar: new appbar(
title: new text(widget.title),
),
body: new singlechildscrollview(
child: new container(
child: new column(children: <widget>[
new coreform(
form: form,
onchanged: (dynamic response) {
this.response = response;
},
),
new raisedbutton(
child: new text('send'),
onpressed: () {
print(this.response.tostring());
})
]),
),
),
);
}
when there is a change in the form, the (dynamic response;) is updated,
onchanged: (dynamic response) {
this.response = response;
},
when text is added to the textfield, add field called response
// initial form_send_email
[{"type":"input","title":"subject","placeholder":"subject"},{"type":"tareatext","title":"message","placeholder":"content"}]
// add text (hi) in textfield message, update dynamic response; and add field called response
[{type: input, title: subject, placeholder: subject}, {type: tareatext, title: message, placeholder: content, response: hi }]
Comments are closed.