create static method

LicensePlate create(
  1. String plate, {
  2. double? width,
  3. double? height,
  4. String? locality,
  5. PlateCategory? category,
  6. Color? backgroundColor,
  7. Color? borderColor,
  8. Color? textColor,
  9. Color? topBarColor,
  10. bool compact = false,
})

Create a TwoLettersPlate, ThreeLettersPlate or MercosulPlate from String. The plate type is auto-selected by category or by format of String. If category is not provided, the plate type is auto-selected by the format of plate. If category is not provided and plate is not a valid plate number, return a MercosulPlate with MercosulPlateCategory. Colors can be customized by passing the backgroundColor, borderColor, textColor and topBarColor parameters.

Implementation

static LicensePlate create(
  String plate, {
  double? width,
  double? height,
  String? locality,
  PlateCategory? category,
  Color? backgroundColor,
  Color? borderColor,
  Color? textColor,
  Color? topBarColor,
  bool compact = false,
}) {
  category ??= categoryFromPlate(plate, "particular") ?? MercosulPlateCategory.particular;

  if (category is ThreeLettersPlateCategory) {
    return ThreeLettersPlate(
      plate,
      height: height,
      width: width,
      locality: locality ?? "",
      category: category,
      backgroundColor: backgroundColor,
      borderColor: borderColor,
      textColor: textColor,
      compact: compact,
    );
  } else if (category is MercosulPlateCategory) {
    return MercosulPlate(
      plate,
      height: height,
      width: width,
      category: category,
      locality: locality ?? "",
      backgroundColor: backgroundColor,
      borderColor: borderColor,
      textColor: textColor,
      topBarColor: topBarColor,
      compact: compact,
    );
  } else if (category is TwoLettersPlateCategory) {
    return TwoLettersPlate(
      plate,
      height: height,
      width: width,
      locality: locality ?? "",
      showLocality: locality.isNotBlank,
      category: category,
      backgroundColor: backgroundColor,
      borderColor: borderColor,
      textColor: textColor,
      compact: compact,
    );
  }
  throw Exception('Invalid category');
}