如何将TextField中输入的文本传输到另一个小部件?



我有一个输入文本的TextField,如果可能的话,我想将此文本转移到文本中的另一个文件。问题是,我已经使用控制器来检查TextField中是否有文本,并且根据状态改变了ElevatedButton中的颜色。如何为文本传输创建另一个控制器?或者如何使用已有的

class __AurButtnonWidghetState extends State<_AurButtnonWidghet> {
final _textController = TextEditingController();
final _formKey = GlobalKey<FormState>();
final successColor =
MaterialStateProperty.all(Color.fromARGB(255, 62, 126, 199));
final errorColor =
MaterialStateProperty.all(Color.fromARGB(255, 145, 144, 144));
bool isValid = false;
@override
void initState() {
super.initState();
_textController.addListener(() {
if (_textController.text.isEmpty) {
setState(() {
isValid = false;
});
} else {
setState(() {
isValid = true;
});
}
});
}
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
TextFormField(
controller: _textController,
decoration: AppTextFieldStyle.LinkButton,
validator: (value) {
() {};
},
),
SizedBox(height: 15),
ElevatedButton(
onPressed: !isValid
? null
: () {
Navigator.of(context).pushNamed('/password_screen');
// go  further.
},
style: ButtonStyle(
backgroundColor: isValid ? successColor : errorColor,
minimumSize: MaterialStateProperty.all(Size.fromHeight(1)),
foregroundColor: MaterialStateProperty.all(Colors.white),
textStyle: MaterialStateProperty.all(
TextStyle(fontSize: 16, fontWeight: FontWeight.w500)),
padding: MaterialStateProperty.all(
EdgeInsets.symmetric(horizontal: 10, vertical: 10))),
child: Text('Next')),

在另一个文件中,我有一个文本,我想在这里插入输入的文本

Text(
'Use the password specified during registration  (+Entered Text)' ,
style: AppDescribeTittleStyle.LinkButton,
textAlign: TextAlign.center,
),

在screen1中使用

Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => PasswordScreen(passwordText : _textController.text),
),
);

在screen2

class SecondScreen extends StatelessWidget {
final String passwordText;
SecondScreen({Key key, required this.passwordText}) : super(key: key);
.....

现在在第二个屏幕中你可以像

那样使用它
Text('$passwordText also someother text here');