osum_serializable

Creator: coderz1093

Last updated:

0 purchases

osum_serializable Image
osum_serializable Images
Add to Cart

Description:

osum serializable

osum_serializable #

The goal is to serialize almost everything you ever need! json_serializable is an amazing package to serialize classes but cannot serialize complex types. This package provides convertors for these types. Check the supported types to know more.
Supported types #



Type
Support
Type
Support




Color

MaterialColor



Offset

Size



Directory

File



DateTime

IconData



Duration

UuidValue



Locale






How it works #



Code
Json









How to use? #
Install #
osum_serializable depends on build_runner and json_serializable to building the toJson and fromJson implementations. To install run these commands in your terminal.
flutter pub add --dev build_runner
flutter pub add --dev json_serializable
flutter pub add osum_serializable
copied to clipboard
Usage #
To use the convertors, simply postfix the data type name with Convertor and call the annotation.
@{DATATYPE}Converter()
final {DATATYPE} variable;
copied to clipboard
For example, serializing IconData can be done like this.
@IconDataConverter()
final IconData variable;
copied to clipboard
Example #
Refer the example section for the full code.
// imports ...
part 'test.g.dart';

@JsonSerializable()
class Example {
const Example(this.directory, this.file, this.color, this.duration, this.materialColor);

factory Example.fromJson(Json json) => _$ExampleFromJson(json);

@DirectoryConverter() // <- Convertors provided by osum_serializable!
final Directory directory;

@MaterialColorConverter()
final MaterialColor materialColor;

@FileConverter()
final File file;

@ColorConverter()
final Color color;

@DurationConverter()
final Duration duration;

Json toJson() => _$ExampleToJson(this);
}
copied to clipboard
Finally, don't forget to call the build_runner to generate the json implementation.
flutter pub run build_runner build
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.