dot_cast 1.0.1 copy "dot_cast: ^1.0.1" to clipboard
dot_cast: ^1.0.1 copied to clipboard

This package provides the user with extension methods for casting objects allowing you to write less and cleaner code.

example/dot_cast_example.dart

import 'package:dot_cast/dot_cast.dart';

void main() {
  Vehicle vehicle = Car();

  // cast

  final car = vehicle.cast<Car>(); // Car
  car.drive();

  final plane = vehicle.cast<Plane>(); // throws error!

  // tryCast

  final nullableCar = vehicle.tryCast<Car>(); // Car?
  nullableCar?.drive();

  final nullablePlane = vehicle.tryCast<Plane>(); // null
}

class Vehicle {}

class Car extends Vehicle {
  void drive() {}
}

class Plane extends Vehicle {
  void fly() {}
}
6
likes
0
points
130
downloads

Publisher

verified publisherveenstra.dev

Weekly Downloads

This package provides the user with extension methods for casting objects allowing you to write less and cleaner code.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on dot_cast