-
Flutter-Missing case clause for 'active'. Try adding a case clause for the missing constant, or ...Flutter/errors and solved 2020. 5. 15. 12:54
If you import and apply Flutter source code, the following error may occur in the following switch statement.
Missing case clause for 'active'.
Try adding a case clause for the missing constant, or adding a default clause.

It's a warning, not an error, but it's a very poignant phrase.
As the 'active' item is missing from the case statement, it is required to add 'active' or add a default statement.
(It seems to be a warning phrase that occurs frequently when writing a case statement.)
Here is the source code where the error (?) Occurred.

return FutureBuilder( future: this._fetchPage(pageNumber, 20), builder: (context, snapshot) { switch (snapshot.connectionState) { case ConnectionState.none: case ConnectionState.waiting: return Align( alignment: Alignment.center, child: CircularProgressIndicator() ); case ConnectionState.done: if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } else { var pageData = snapshot.data; return this._buildPage(pageData); } } } );It is said that the active item of the ConnectionState class has not been added ...
After checking the item, there was an actual "active" item, and the compiler is explaining that you can add it or add a "default" statement.

Then, what is the status of "active" ... You can check the link below.
[https://api.flutter.dev/flutter/widgets/ConnectionState-class.html] (https://api.flutter.dev/flutter/widgets/ConnectionState-class.html)

Connected to active asynchronous calculations ..... hmm ... what is it ?? Looking at the example just below makes a little sense.
"At least one data has been returned, but it has not been completed," he said.
Well, it depends on the situation, but I think it's okay to stick with waiting.
Add the active as below to solve it ...
return FutureBuilder( future: this._fetchPage(pageNumber, 20), builder: (context, snapshot) { switch (snapshot.connectionState) { case ConnectionState.none: case ConnectionState.waiting: case ConnectionState.active: return Align( alignment: Alignment.center, child: CircularProgressIndicator()); case ConnectionState.done: if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } else { var pageData = snapshot.data; return this._buildPage(pageData); } } }, );I think you can complete it by adding the default statement.
return FutureBuilder( future: this._fetchPage(pageNumber, 20), builder: (context, snapshot) { switch (snapshot.connectionState) { case ConnectionState.none: case ConnectionState.waiting: return Align( alignment: Alignment.center, child: CircularProgressIndicator()); case ConnectionState.done: if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } else { var pageData = snapshot.data; return this._buildPage(pageData); } break; default: return Align( alignment: Alignment.center, child: CircularProgressIndicator()); } }, );If you don't add all the items to use the case statement, you'll get a warning like this.
Adding at least one default, if any, looks good for mental health.
'Flutter > errors and solved' 카테고리의 다른 글