【发布时间】:2020-02-06 02:19:52
【问题描述】:
使用 play_games 扩展程序,我无法返回用户的个人资料图片。
使用下面的方法登录并设置状态,返回用户数据。
图片提供者:NetworkImage ("content: //com.google.android.gms.games.background/images/f56551ac/42", scale: 1.0)
// Google Play Games stance
final GameServices gameservices = GameServices();
Account profile;
ui.Image profileimage;
void _login() async {
final res = await gameservices.login();
final resimage = await res.hiResImage;
setState(() {
profile = res;
profileimage = resimage;
});
print(profileimage);
}
在小部件中,我是 NetworkImage 的形式,但它仍然没有呈现在屏幕上。
此错误:无法将参数类型“图像”分配给参数类型“字符串”。
Container(
width: 128,
height: 128,
padding: EdgeInsets.all(8),
child: CircleAvatar(
backgroundImage: NetworkImage(this.profileimage != null ? this.profileimage : 'https://api.adorable.io/avatars/128/')
),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle
),
),
[已解决!!! ]
更改我的代码,play_games 返回类型变量。 走吧:
Future<Uint8List> get hiResImage async =>
await _fetchToMemory(await _channel.invokeMethod('getHiResImage'));
Future<Uint8List> get iconImage async =>
await _fetchToMemory(await _channel.invokeMethod('getIconImage'));
}
Future<Uint8List> _fetchToMemory(Map<dynamic, dynamic> result) {
Uint8List bytes = result['bytes'];
if (bytes == null) {
print('was null, mate');
return Future.value(null);
}
// Completer<Image> completer = new Completer();
// decodeImageFromList(bytes, (image) => completer.complete(image));
return Future.value(bytes);
}
而我的代码,只有这个改变:
Uint8List profileimage;
【问题讨论】:
标签: flutter dart google-play-games