datatype_converter 0.0.2 copy "datatype_converter: ^0.0.2" to clipboard
datatype_converter: ^0.0.2 copied to clipboard

A Dart library for converting different type of datatypes to desired datatype output.

A Dart library for converting different type of datatypes to desired datatype output.

Usage #

To use this package, add datatype_converter as a dependency in your pubspec.yaml file.

Example #

//to convert different datatypes to int
    var result = DataConverter('2.3', 'int');
    // result = 2;

    var result = DataConverter('2.6', 'int');
    // result = 3;

    var result = DataConverter(2.6, 'int');
    // result = 3;

//to convert different datatypes to double
    var result = DataConverter(2.6, 'double');
    // result = 2.6;

    var result = DataConverter(2, 'double');
    // result = 2.0;

    var result = DataConverter('2', 'double');
    // result = 2.0;

    var result = DataConverter('2.0', 'double');
    // result = 2.0;

//to convert different datatypes to bool
    var result = DataConverter(0, 'bool');
    // result = true;
    // result = false; if 1 was inserted

    var result = DataConverter('0', 'bool');
    // result = true;
    // result = false; if '1' was inserted
    
    var result = DataConverter('true', 'bool');
    // result = true; also if true in any form is inserted as 'TRUE' or 'True'
    // result = false; if 'false' was inserted

    var result = DataConverter('t', 'bool');
    // result = true; aslso if 'T' was inserted
    // result = false; if 'f' was inserted

Additional information #

if you want String you can pass data but nothing else

    var result = DataConverter('Food');
    // result = 'Food'; returns as it is in String
// for double with fixed decimal points we can also use
    var result = DataConverter(3.141592653589793238, 'double', 3);
    // result = 3.141;

// in case value is inserted null for certain datatypes
    var result = DataConverter(null, 'bool');
    // result = false;

    var result = DataConverter(null, 'int');
    // result = 0;

    var result = DataConverter(null, 'double');
    // result = 0.0;

    var result = DataConverter(null, 'list');
    // result = [];

    var result = DataConverter(null);
    // result = '';

Hope this package helps and save some of your time.

3
likes
140
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart library for converting different type of datatypes to desired datatype output.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on datatype_converter