【发布时间】:2021-02-09 15:06:26
【问题描述】:
我是上周刚学的 Flutter 的新手,在这里遇到两个问题,我正在尝试解决错误,但仍然无法解决,有人可以帮帮我吗?下面是飞镖代码。
'main.dart'
class Sharer extends StatefulWidget
{
bool _isLoggedIn = false;
Map userProfile;
final facebookLogin = FacebookLogin();
@override
Widget build(BuildContext context)
{
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.amber,
centerTitle: true,
title: Text('Welcome Sharer',
style: TextStyle(
fontSize: 16.0,
color: Colors.black87,
letterSpacing: 1.0,
),
),
),
body:
//Center(
//child: isLoggedin
//?
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
padding: EdgeInsets.all(20.0),
child: RaisedButton.icon(
onPressed: () async {
final result = await facebookLogin.logIn(['email']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
final token = result.accessToken.token;
final graphResponse = await http.get('https://graph.facebook.com/v2.12/me?fields=name,picture,email&access_token=${token}');
final profile = JSON.jsonDecode(graphResponse.body);
print(profile);
setState(() {
userProfile = profile;
_isLoggedIn = true;
});
break;
case FacebookLoginStatus.cancelledByUser:
setState(() => _isLoggedIn = false );
break;
case FacebookLoginStatus.error:
setState(() => _isLoggedIn = false );
break;
}
},
icon: Icon(
MyFlutterApp.facebook,
),
label: Text(
'Sharer',
style: TextStyle(
fontFamily: 'MyFlutterApp',
color: Colors.black87,
letterSpacing: 1.0,
),
),
),
),
),
],
),
//),
);
}
}
错误显示在类名上说'缺少 statefulwidget.create state 的具体实现'另一个是'setstate is not defined',我不知道有什么问题可以帮忙吗? 谢谢和问候。
【问题讨论】: