force_type 1.0.0 force_type: ^1.0.0 copied to clipboard
A Flutter package that provides functions to forcefully convert dynamic types to specific types.
Force Type #
A Flutter 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
Usage #
Import the force_type
package and the test
package:
import 'package:force_type/force_type.dart';
import 'package:test/test.dart';
Create a group of tests using the group
function from the test
package:
void main() {
group('A group of tests', () {
// Define dynamic variables for testing
final dynamicA = 123;
final dynamicB = "123";
final dynamicC = "123.456";
final dynamicD = "true";
final dynamicE = "1";
final dynamicF = "1969-07-20 20:18:04Z";
// Write individual test cases
test('Force String Test', () {
expect(dynamicA.forceString, "123");
});
test('Force Integer Test', () {
expect(dynamicB.forceInteger, 123);
});
test('Force Double Test', () {
expect(dynamicC.forceDouble, 123.456);
});
test('Force Boolean Test', () {
expect(dynamicD.forceBoolean, true);
expect(dynamicE.forceBoolean, true);
});
test('Force DateTime Test', () {
expect(
dynamicF.forceDateTime, DateTime.parse("1969-07-20 20:18:04Z"));
});
});
}
API Reference #
forceString #
Converts a dynamic value to a String.
dynamicValue.forceString
forceInteger #
Converts a dynamic value to an integer.
dynamicValue.forceInteger
forceDouble #
Converts a dynamic value to a double.
dynamicValue.forceDouble
forceBoolean #
Converts a dynamic value to a boolean.
dynamicValue.forceBoolean
forceDateTime #
Converts a dynamic value to a DateTime object.
dynamicValue.forceDateTime
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.