'Flutter/dart: The getter 'id' isn't defined for the type 'WelcomeScreen'
In 2nd dart file I have a class 'WelcomeScreen' with property-
String id = 'welcome_screen';
I want to use it in 1st dart file and this is how I am doing it-
initialRoute: WelcomeScreen().id,
routes: {
WelcomeScreen().id : (context) => WelcomeScreen(),
And then for id, flutter throws an error - The getter 'id' isn't defined for the type 'WelcomeScreen'
Solution 1:[1]
Make the id a static const field and use it without WelcomeScreen instantiation, i.e.:
static const String id = 'welcome_screen';
...
initialRoute: WelcomeScreen.id,
routes: {
WelcomeScreen.id : (context) => WelcomeScreen(),
Solution 2:[2]
you have to put inside class WelcomeScreen extends StatefulWidget {} then its will be work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | olexa.le |
| Solution 2 | Taka |
