0

I cant use the parameter variable.

class HomePage extends StatefulWidget {
  const HomePage({
    Key? key,
    required this.userState,
    required this.currentPageForRoute,
  }) : super(key: key);
  final bool userState;
  final int currentPageForRoute;


  @override
  _HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int currentPage = widget.currentPageForRoute;

//And then, i going to change currentPage often and use it.

}

I want use widget.currentPageForRoute as currentPage variable, but i cant. (If I can use it, I will change it often.) The error massage: Undefined name 'widget'.

1 Answer 1

1

You can use initState method or late

late int currentPage = widget.currentPageForRoute;
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to help, you can find more about late keyword with declaration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.