這段代碼有什么錯誤?請問你能把它改正并把代碼發給我嗎?
預期有 4 個位置引數,但找到了 2 個。嘗試添加缺少的引數。
未定義的名稱“_formKey”。嘗試將名稱更正為已定義的名稱,或定義名稱。
未定義的名稱“_authData”。嘗試將名稱更正為已定義的名稱,或定義名稱。
未定義的名稱“_passwordController”。嘗試將名稱更正為已定義的名稱,或定義名稱。
未定義的名稱“_passwordController”。嘗試將名稱更正為已定義的名稱,或定義名稱。
未定義函式“_submit”。嘗試匯入定義“_submit”的庫,將名稱更正為現有函式的名稱,或定義名為“_submit”的函式。
需要方法、getter、setter 或運算子宣告。這似乎是不完整的代碼。嘗試洗掉它或完成它。
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/authentication.dart';
import 'home_screen.dart';
import 'login_screen.dart';
class SignupScreen extends StatefulWidget {
static const routeName = '/signup';
@override
_SignupScreenState createState() => _SignupScreenState();
}
class _SignupScreenState extends State<SignupScreen> {
final GlobalKey<FormState> _formKey = GlobalKey();
TextEditingController _passwordController = new TextEditingController();
Map<String, String> _authData = {
'email' : '',
'password' : ''
};
void _showErrorDialog(String msg)
{
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text('An Error Occured'),
content: Text(msg),
actions: <Widget>[
FlatButton(
child: Text('Okay'),
onPressed: (){
Navigator.of(ctx).pop();
},
)
],
)
);
}
Future<void> _submit() async
{
if(!_formKey.currentState!.validate())
{
return;
}
_formKey.currentState!.save();
try{
var key = 'email';
await Provider.of<Authentication>(context, listen: false).signUp(
_authData[key],
_authData['password']
);
Navigator.of(context).pushReplacementNamed(HomeScreen.routeName);
} catch(error)
{
var errorMessage = 'Authentication Failed. Please try again later.';
_showErrorDialog(errorMessage);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Signup'),
actions: <Widget>[
FlatButton(
child: Row(
children: <Widget>[
Text('Login'),
Icon(Icons.person)
],
),
textColor: Colors.white,
onPressed: (){
Navigator.of(context).pushReplacementNamed(LoginScreen.routeName);
},
)
],
),
body: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.limeAccent,
Colors.redAccent,
]
)
),
),
Center(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Container(
height: 300,
width: 300,
padding: EdgeInsets.all(16),
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
//email
TextFormField(
decoration: InputDecoration(labelText: 'Email'),
keyboardType: TextInputType.emailAddress,
validator: (value)
{
if(value!.isEmpty || !value.contains('@'))
{
return 'invalid email';
}
return null;
},
onSaved: (value)
{
_authData['email'] = value!;
},
),
//password
TextFormField(
decoration: InputDecoration(labelText: 'Password'),
obscureText: true,
controller: _passwordController,
validator: (value)
{
if(value!.isEmpty || value.length<=5)
{
return 'invalid password';
}
return null;
},
onSaved: (value)
{
_authData['password'] = value!;
},
),
//Confirm Password
TextFormField(
decoration: InputDecoration(labelText: 'Confirm Password'),
obscureText: true,
validator: (value)
{
if(value!.isEmpty || value != _passwordController.text)
{
return 'invalid password';
}
return null;
},
onSaved: (value)
{
},
),
SizedBox(
height: 30,
),
RaisedButton(
child: Text(
'Submit'
),
onPressed: ()
{
_submit();
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
color: Colors.blue,
textColor: Colors.white,
)
],
),
),
),
),
),
)
],
),
);
}
}

uj5u.com熱心網友回復:
我指的是你對我之前回答的評論,所以不,我不能給你我的電話號碼,這不是尋求幫助的正確方式,我猜這個網站就是為此而建立的。我復制了您的錯誤并通過評論中的解釋解決了它,您可以在下圖中看到。

因此,呼叫您的 signUp 方法的正確方法是:
Provider.of<Authentication>(context, listen:false).signUp(
authdata['email'] as String,
authdata['password'] as String,
'pass third argument here',
'pass fourth argument here',
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/431500.html
上一篇:如何在VSCode和WebStorm中將React.tsx檔案中的CSS/SCSS/PostCSS撰寫為JavaScript字串?
