Expected a class member error when defining a constructor for Widget State

2,504 views
Skip to first unread message

Leo Pelekh

unread,
Jan 7, 2022, 2:15:05 PM1/7/22
to Flutter Development (flutter-dev)
Hello,

I'm trying to define a constructor for my Widget's state, and am getting a "Expected a class member" error at the "} : super()" line.

class _TopContainerState extends State<TopContainer> {

_TopContainerState(){

print("foo");
} : super();

}

The reason why I'm defining a constructor is because some of my field's constructors require
passing them an instance event handler method, which aparently I cannot do on class initialization, only in the constructor.

Thank you!

Leo



Leo Pelekh

unread,
Jan 7, 2022, 9:00:11 PM1/7/22
to Flutter Development (flutter-dev)
Never mind, my apologies,  i must have been tired. The problem was trailing semicolon should not be there, and initialization list goes before constructor body. 
Reply all
Reply to author
Forward
0 new messages