问题描述
有什么办法可以在Flutter的小部件少类中设置输入值?我有一个包含所有配置的类,但该类中没有小部件。现在我想从使用中获取输入,并想在config类中设置该值。
我尝试过,它说The return type 'AllConfig' isn't a 'Widget',as required by the closure's context.dart (return_of_invalid_type_from_closure)
预先感谢
解决方法
在无小部件的类中,您可以创建一个具有输入值的函数
class TestClass {
static testValue;
_functionInClass(inputValue){
print(inputValue);
setState(() {
testValue= inputValue;
});
}
然后从其他地方导入该类并调用该函数
import '.../testClassesFile.dart' as testClass;
var x = 1;
testClass._functionInClass(x); //call function in another class with a value