0

I want to pass the ScopedModel to another page. Or in the initState call the ScopedModel so I can use the data.

  final MainModel model;
  IndexPage(this.model);
  @override
  State<StatefulWidget> createState() {
    return IndexPageState();
  }
}

class IndexPageState extends State<IndexPage> {
  final pages = [
    HomePage(),
    CreatePage(),
    MapPage(widget.model),
  ];

When I do this I have this error:

Only static members can be accessed in initializers

Thanks!

R. Martinez
  • 119
  • 2
  • 10

1 Answers1

0

Martinez, you would need to move the declaration of your pages inside initState()

class IndexPageState extends State<IndexPage> {

List<Widget> pages;

@override
void initState() {  
   pages = [
        HomePage(),
        CreatePage(),
       MapPage(widget.model),
      ];
}
digitaljoni
  • 1,357
  • 1
  • 9
  • 12