'Flutter convert package or dart:convert
I am following a Flutter tutorial.
JSON is converted using the dart convert library: import 'dart:convert';
However, I see that a flutter package is available which would also work, using: import 'package:convert/convert.dart';
and adding convert: ^2.1.1
as a dependency in the app pubspec.yaml file.
The convert package readme states "This package contains encoders and decoders for converting between different data representations. It's the external counterpart of the dart:convert core library, and contains less-central APIs and APIs that need more flexible versioning."
What does "contains less-central APIs and APIs that need more flexible versioning" mean?
Which method is preferable / best practice and why? Are there performance differences between using the dart:convert core library and the Flutter package?
Solution 1:[1]
'dart:convert'
contains the conversion utility that's built-in to the Dart framework. package:convert
on the other hand is the external counterpart. Depending on the API that you need to use, you can use either of the two as needed. If the converter that you need is present on one, you can use that library, and same the other way around.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Omatt |