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'.
CodePudding user response:
You can use initState
method or late
late int currentPage = widget.currentPageForRoute;