I want to get variables of a StatefulWidget from within the state. Is there a easy way to just get the Stateobject like username.state.value.
EDIT: To clarify I want to access a variable that's defined in the state from the parent of the widget(not the state). The variable is gonna change, but I don't want to update it constantly in the parent. I want to get the variable when I press a button. I have an example below how I can access variables normally, but I want to know if there is a way to access the state and its variables.
EDIT2: I am getting suggestions that I should use a listener(this.onValueChange), but isn't that inefficient. I only want to get the value once and not every time I change the value.
class MyTextField extends StatefulWidget {
final String? validator;
const MyTextField(
{super.key,
this.validator});
@override
State<MyTextField> createState() => _MyTextFieldState();
}
class _MyTextFieldState extends State<MyTextField> {
String value = "";
MyTextField username = MyTextField(validator: null)
String? validator = username.validator;
String value = ?