Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

Flutter Rendering Widgets Using JSON Data

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:json_dynamic_widget/json_dynamic_widget.dart';


void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.teal,
        ),
        home: const RenderingWidget());
  }
}

class RenderingWidget extends StatefulWidget {
  const RenderingWidget({Key? key}) : super(key: key);

  @override
  _RenderingWidgetState createState() => _RenderingWidgetState();
}

class _RenderingWidgetState extends State<RenderingWidget> {
  Map<dynamic, dynamic> mapData = {};
  var registry = JsonWidgetRegistry.instance;

  Future<Map> readJson() async {
    final String response = await rootBundle.loadString('assets/sample.json');
    final data = await json.decode(response);
    return data;
  }

  @override
  Widget build(BuildContext context) {
    readJson().then((value) => mapData = value);
    var widget = JsonWidgetData.fromDynamic(mapData, registry: registry);
    return widget!.build(context: context);
  }
}
Source by medium.flutterdevs.com #
 
PREVIOUS NEXT
Tagged: #Flutter #Rendering #Widgets #Using #JSON #Data
ADD COMMENT
Topic
Name
3+2 =