我还不了解框架,你能帮我解决这个错误吗?我正在尝试获取基本用户数据并在此处输入图像描述
颤振医生:
[!]Android工具链-为Android设备开发(Android SDK版本30.0.0)!某些Android许可证不被接受。要解决此问题,请运行:flutter博士--android-许可证[!]Android Studio(4.0版)X Flutter插件未安装;这增加了Flutter特定功能。X Dart插件未安装;这增加了Dart特定功能。[√]连接的设备(1个可用)
!医生在2类中发现了问题。
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'constants.dart';
import 'package:simple_auth/simple_auth.dart' as simpleAuth;
import 'package:simple_auth_flutter/simple_auth_flutter.dart';
class Inst_Login extends StatefulWidget {
Inst_Login({Key key}) : super(key: key);
@override
_Inst_LoginState createState() => _Inst_LoginState();
}
class _Inst_LoginState extends State<Inst_Login> {
String _errorMsg;
Map _userData;
final simpleAuth.InstagramApi _igApi = simpleAuth.InstagramApi(
"instagram",
Constants.igClientId,
Constants.igClientSecret,
Constants.igRedirectURL,
scopes: [
'user_profile', // For getting username, account type, etc.
'user_media', // For accessing media count & data like posts, videos etc.
],
);
@override
void initState() {
super.initState();
SimpleAuthFlutter.init(context);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Instagram Basic Display API Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Visibility(
visible: _userData != null,
child: Text(
_userData.keys.fold(
'', (kvText, key) => kvText + "$key: ${_userData[key]} \n"),
textAlign: TextAlign.center,
),
replacement:
Text("Click the button below to get Instagram Login."),
),
FlatButton.icon(
icon: Icon(Icons.input),
label: Text(
"Get Profile Data",
),
onPressed: _loginAndGetData,
color: Colors.pink.shade400,
),
if (_errorMsg != null) Text("Error occured: $_errorMsg"),
],
),
),
);
}
Future<void> _loginAndGetData() async {
_igApi.authenticate().then(
(simpleAuth.Account _user) async {
simpleAuth.OAuthAccount user = _user;
var igUserResponse =
await Dio(BaseOptions(baseUrl: 'https://graph.instagram.com')).get(
'/me',
queryParameters: {
// Get the fields you need.
// https://developers.facebook.com/docs/instagram-basic-display-api/reference/user
"fields": "username,id,account_type,media_count",
"access_token": user.token,
},
);
setState(() {
_userData = igUserResponse.data;
_errorMsg = null;
});
},
).catchError(
(Object e) {
setState(() => _errorMsg = e.toString());
},
);
}
}
即使您使用的是< code>Visibility widget,该widget也不应该有null _userdata。如果您执行的api调用是< code >异步的并返回< code>Future,那么请使用< code>FutureBuilder
未来生成器的代码将是 -
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'constants.dart';
import 'package:simple_auth/simple_auth.dart' as simpleAuth;
import 'package:simple_auth_flutter/simple_auth_flutter.dart';
class Inst_Login extends StatefulWidget {
Inst_Login({Key key}) : super(key: key);
@override
_Inst_LoginState createState() => _Inst_LoginState();
}
class _Inst_LoginState extends State<Inst_Login> {
String _errorMsg;
Map _userData;
final simpleAuth.InstagramApi _igApi = simpleAuth.InstagramApi(
"instagram",
Constants.igClientId,
Constants.igClientSecret,
Constants.igRedirectURL,
scopes: [
'user_profile', // For getting username, account type, etc.
'user_media', // For accessing media count & data like posts, videos etc.
],
);
@override
void initState() {
super.initState();
SimpleAuthFlutter.init(context);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Instagram Basic Display API Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FutureBuilder(
future: _loginAndGetData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done)
return Text(
_userData.keys.fold('',
(kvText, key) => kvText + "$key: ${_userData[key]} \n"),
textAlign: TextAlign.center,
);
return Text("Click the button below to get Instagram Login.");
},
),
FlatButton.icon(
icon: Icon(Icons.input),
label: Text(
"Get Profile Data",
),
onPressed: _loginAndGetData,
color: Colors.pink.shade400,
),
if (_errorMsg != null) Text("Error occured: $_errorMsg"),
],
),
),
);
}
Future<void> _loginAndGetData() async {
_igApi.authenticate().then(
(simpleAuth.Account _user) async {
simpleAuth.OAuthAccount user = _user;
var igUserResponse =
await Dio(BaseOptions(baseUrl: 'https://graph.instagram.com')).get(
'/me',
queryParameters: {
// Get the fields you need.
// https://developers.facebook.com/docs/instagram-basic-display-api/reference/user
"fields": "username,id,account_type,media_count",
"access_token": user.token,
},
);
setState(() {
_userData = igUserResponse.data;
_errorMsg = null;
});
},
).catchError(
(Object e) {
setState(() => _errorMsg = e.toString());
},
);
}
}
如果你在评论中有任何问题或疑问,希望这能帮助你。
我在使用Flutter注册电子邮件和密码时遇到了问题。我用它来注册新用户,它保存了他们的Firebase身份验证信息,但不会将任何配置文件数据保存到Firebase存储部分。我不确定我在这里做错了什么,我不明白为什么id是空的。一些帮助和指导将真的非常感谢! 这就是我犯的错误 这是来自用户的。飞奔 这是来自注册。飞奔 错误指向用户引用。文档行。 这是Timeline.dart 该错误指向这两个方法
此错误“”getter'uid'在null上被调用。receiver:null尝试调用:uid“ 退出按钮: 控制台: widgets库捕获的异常接收者:null尝试调用:uid 相关的导致错误的小部件是:Qr file://g://androidstudioprojects/facem/lib/screens/home/home.dart:687:67当抛出异常时,这是堆栈:#0 object.
在单元测试(Groovy和Spock)的中,我用mock填充上面的字段: 接下来,在我的测试用例中,我调用一个方法,我希望从中获取,该方法来自步骤中的模拟对象: 问题是,对于,我将获得。 这是因为我以错误的方式使用Groovy吗?如何使成为它应该成为的对象?我应该使用mock/stub吗?
[错误:flatter/lib/ui/ui_dart_state.cc(157)]未处理的异常:NoSuchMethodError:对null调用了方法“validate”。E/flatter(6538):接收器:null E/flatter(6538):尝试调用:validate()E/flatter(6538):#0对象。无此方法(dart:core patch/object_patch.da
我对getter方法中的有一个问题。 代码如下:
正如您在onCreate方法中看到的,我在“片段”列表的第0个片段上调用了getView。它返回null。我试着在代码中加入一个计时器,让它每秒运行一次,并检查视图是否为空。在计时器的第二个滴答声中,视图不为空。大体上 主要活动。JAVA 空白碎片。JAVA