Skip to content

Instantly share code, notes, and snippets.

@RaminNietzsche
Created February 23, 2019 08:40
Show Gist options
  • Select an option

  • Save RaminNietzsche/3f282614d89223957072f746a3b235c3 to your computer and use it in GitHub Desktop.

Select an option

Save RaminNietzsche/3f282614d89223957072f746a3b235c3 to your computer and use it in GitHub Desktop.

Revisions

  1. RaminNietzsche created this gist Feb 23, 2019.
    79 changes: 79 additions & 0 deletions form.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    import 'dart:convert';

    import 'package:flutter/material.dart';

    class FormGen extends StatefulWidget{
    @override
    State<StatefulWidget> createState() => _FormGen();
    }

    class _FormGen extends State<FormGen> {
    String formJson = '''
    {
    "form": "khatm",
    "fields": [{
    "name": "username",
    "type": "text",
    "validator": "name",
    "options": null,
    "requierd": true
    }]
    }
    ''';
    List<Widget> formWidget = [];

    @override
    void initState() {
    // TODO: implement initState
    super.initState();
    }

    @override
    Widget build(BuildContext context) {
    List formList;
    var js = jsonDecode(formJson);
    js['fields'].forEach((element) {
    if (element["type"] == "text")
    this.formWidget.add(
    new TextField(

    )
    );
    });
    print(formList);
    return Scaffold(
    body: Row(
    children: this.formWidget,
    ),
    );
    }
    }

    class FormMaker {
    String name;
    String type;
    String validator;
    List options;
    bool required;

    FormMaker(
    {
    this.name,
    this.type,
    this.validator,
    this.options,
    this.required
    }
    );

    factory FormMaker.fromJson(Map<String, dynamic> json){
    print(json);
    return new FormMaker(
    name: json['name'],
    type: json['type'],
    validator: json['validator'],
    options: json['options'],
    required: json['required'],
    );
    }
    }