flutter_json_to_dart

Last updated:

0 purchases

flutter_json_to_dart Image
flutter_json_to_dart Images
Add to Cart

Description:

flutter json to dart

Json2Dart #
Json2Dart is a package to converts your map (json) to a String, wich is the output Dart code. You can write the String to a file or put it in a text widget.
How to use #
import 'dart:convert';
import 'dart:io';

import 'package:json2dart/json2dart.dart';

void main(List<String> args) {
// Your json String
String jsonString = '''
{
"weather": "sunny",
"clouds": "no",
"time": "11.30",
"sports you can do": [
"running",
"hiking",
"biking"
],
"any map": {
"key 1": "value 1",
"key 2": "value 2"
}
}''';

// Decode the json String to a Map
Map<String, dynamic> jsonData = jsonDecode(jsonString);

// Compile the json to Dart code
final String dartCode = Json2Dart.compileJson2Dart(jsonData, null);

// Output
print("Json:");
print(jsonData);
print("");
print("Dart:");
print(dartCode);

// Or write to a file
File dartCodeFile = File("${Directory.current.path}/example/generated_json.dart");
dartCodeFile.writeAsString(dartCode);
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.