force_type

Last updated:

0 purchases

force_type Image
force_type Images
Add to Cart

Description:

force type

Force Type #
A Dart package that provides functions to forcefully convert dynamic types to specific types.


Installation #
Add the following dependency to your pubspec.yaml file:
dependencies:
force_type: any
copied to clipboard
Usage #
Import the force_type package and the test package:
import 'package:force_type/force_type.dart';
import 'package:test/test.dart';
copied to clipboard
Create a group of tests using the group function from the test package:
void main() {
group('A group of tests', () {
final dynamicA = 123;
final dynamicB = "123";
final dynamicC = "123.456";
final dynamicD = "true";
final dynamicE = "1";
final dynamicF = "1969-07-20 20:18:04Z";

test('Force String Test', () {
expect(dynamicA.forceString, "123");
//or
expect(forceString(dynamicA), "123");
});

test('Force Integer Test', () {
expect(dynamicB.forceInteger, 123);
//or
expect(forceInteger(dynamicB), 123);
});

test('Force Double Test', () {
expect(dynamicC.forceDouble, 123.456);
//or
expect(forceDouble(dynamicC), 123.456);
});

test('Force Boolean Test', () {
expect(dynamicD.forceBoolean, true);
expect(dynamicE.forceBoolean, true);
//or
expect(forceBoolean(dynamicD), true);
expect(forceBoolean(dynamicE), true);
});

test('Force DateTime Test', () {
expect(dynamicF.forceDateTime, DateTime.parse("1969-07-20 20:18:04Z"));
//or
expect(forceDateTime(dynamicF), DateTime.parse("1969-07-20 20:18:04Z"));
});
});
}
copied to clipboard
API Reference #
forceString #
Converts a dynamic value to a String.
dynamicValue.forceString
copied to clipboard
forceInteger #
Converts a dynamic value to an integer.
dynamicValue.forceInteger
//or
forceInteger(dynamicValue)
copied to clipboard
forceDouble #
Converts a dynamic value to a double.
dynamicValue.forceDouble
//or
forceDouble(dynamicValue)
copied to clipboard
forceBoolean #
Converts a dynamic value to a boolean.
dynamicValue.forceBoolean
//or
forceBoolean(dynamicValue)
copied to clipboard
forceDateTime #
Converts a dynamic value to a DateTime object.
dynamicValue.forceDateTime
//or
forceDateTime(dynamicValue)
copied to clipboard
That's it! You can now use the force_type package to forcefully convert dynamic types to specific types in your Flutter project.
I hope this documentation helps! Let me know if you need any further assistance.

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.