我正在使用Flutter创建注册和登录页面,但遇到了一个问题:我想在另一个类SignupPage中使用在main.dart文件中_MyHomePage类中声明的相同变量'email'和'password'。
我已经导入了文件,但无法在两个类中同时使用这些值。
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
String _email = '';
String _password = '';
final formKey = new GlobalKey<FormState>();
FormType _formType = FormType.login;
bool validateAndSave() {
final form = formKey.currentState;
if (form.validate()) {
form.save();
return true;
// print('Form is Valid Email: $_email, Password: $_password');
}
return false;
}