Powerful of Enums in dart

Do

class _HomeScreenState extends State<HomeScreen> {
  LoadingState state = LoadingState.complete;

  @override
  Widget build(BuildContext context) {
    switch (state) {
      case LoadingState.stopped:
        return Text(state.name);
      case LoadingState.loading:
        return Text(state.name);
      case LoadingState.complete:
        return Text(state.name);
      case LoadingState.failed:
        return Text(state.name);
    }
  }
}


Don't

class _HomeScreenState extends State<HomeScreen> {
  LoadingState state = Stopped();

  @override
  Widget build(BuildContext context) {
    if(state is Stopped) {
      return const Text("Stopped");
    }
    else if(state is Loading) {
      return const Text("Loading");
    }
    else if(state is Complete) {
      return const Text("Complete");
    }
    else if(state is Failed) {
      return const Text("Failed");
    }
    else {
      return const Text("");
    }
  }
}


Conclusion: If you used classes extends from LoadingState, it would be hard to discover what the other states (which the constants in enum could be used to define) are. However with an enum, even a simple switch statement will complain if you don't fill in all the cases. There are a lot of things to like about the Enums. Please look into flutter documentation.