This library lets you annotate fields of classes to automatically generate getters for checking whether a field is null or, in case of enum fields, checking the value of a field. That leads to cleaner code on the caller side:

Before                                 |  After
if (fruit.price != null) {             |  if (fruit.hasPrice) {
  ...                                  |    ...
}                                      |  }
if (fruit.color ==          |  if (fruit.isBlue || fruit.isNotOrange) {
    || fruit.color != {  |    ...
  ...                                  |  }
}                                      |

Here's how to get started:

1. 📦 Add these packages to your dependencies:

  has_is_getters: ^1.1.0

  build_runner: ^1.7.1
  has_is_getters_generator: ^1.1.0

2. 📎 Annotate fields with @GenerateHasGetter() or enum fields with @GenerateIsGetters().

import 'package:has_is_getters/has_is_getters.dart';

part 'my_file.g.dart';

enum Color { orange, blue }

class Fruit {
  int price;

  Color color;

3. 🏭 Run pub run build_runner build in the command line (or flutter pub run build_runner build, if you're using Flutter). The getters will automatically be generated, so you can do stuff like this:

fruit.hasPrice // equal to: fruit.price != null
fruit.isOrange // equal to: fruit.color ==


You can opt-in to generating negations by customizing the annotations:

class Paper {
  @GenerateHasGetter(generateNegation: true)
  @GenerateIsGetters(generateNegations: true)
  Color color;


For is-getters, you can also opt-in to using the field name as a prefix:

class Image {
  @GenerateIsGetters(usePrefix: true)
  Color background;

Private fields

The getters can also be generated for private fields.