我需要访问一个在我的有状态小部件的状态中声明和定义的变量:
class StatItemDeclarable extends StatefulWidget {
const StatItemDeclarable({Key? key, required this.title, required this.index}) : super(key: key);
final String title;
final int index;
//Need to access variables here
@override
State<StatItemDeclarable> createState() => _StatItemDeclarableState(title: title, index: index);
}
class _StatItemDeclarableState extends State<StatItemDeclarable> {
_StatItemDeclarableState({required this.title, required this.index});
String title; // Variable to access
final _titleController = TextEditingController();
final int index;
bool deleted = false;
late Color _color; // Variable to access
字符串
我是一个新手,所以我会很感激一些帮助:)
我想要访问的变量在StatefulWidget中不可访问
2条答案
按热度按时间qzwqbdag1#
你可以通过使用widget来访问这些变量。像这样:
字符串
rmbxnbpk2#
你可以通过在vat名称前使用关键字widget来访问任何var声明的inn构造函数,如
字符串