Home > Software engineering >  Defining multiple cases - which case these will get?
Defining multiple cases - which case these will get?

Time:10-12

In the following piece will the ConnectionState.none and ConnectionState.waiting give the CircularProgressIndicator? Is it legal to define cases that way?

switch (snapshot.connectionState) {
    case ConnectionState.none:
    case ConnectionState.waiting:
    case ConnectionState.active:
        return const CircularProgressIndicator();
    case ConnectionState.done:
        ...

CodePudding user response:

You can use multiple cases too. But instead of multiple cases, we can use or operator in a single switch case itself.

switch (connection) {
        case connection.none:
        case connection.waiting:
            return CircularProgressIndicator();
        }
  • Related