【问题标题】:Flutter error while showing profile picture google play games显示个人资料图片谷歌玩游戏时出现颤振错误
【发布时间】: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


    【解决方案1】:

    Flutter 对你大喊大叫,因为你给了它一个带有协议 content:// 的 URL,而它却期望 http://https:// 得到一个 NetworkImage 小部件。参见文档:https://flutter.dev/docs/cookbook/images/network-image

    【讨论】:

    • 是的,如何将其转换为图像或 http?s?
    【解决方案2】:

    发生这种情况是因为 google 提供了编码图像。在 android 中,我们可以使用ImageManager 作为谷歌的建议。

    在颤振中有从hiresImageUri 获取Future&lt;Image&gt; 的机制。检查here

    使用类似下面的东西,

    profile.hiResImage.then((Image result){
            //here you can get image in result
    });
    

    【讨论】:

    • 此错误:编译器消息:lib/main.dart:77:32:错误:无法将参数类型“Null Function(Image/*1*/)”分配给参数类型'FutureOr 函数(图像/*2*/)'。 - 'Image/*1*/' 来自'package:flutter/src/widgets/image.dart' ('/C:/ProgramData/Flutter/packages/flutter/lib/src/widgets/image.dart')。 - 'FutureOr' 来自 'dart:async'。 - 'Image/*2*/' 来自 'dart:ui'。 this.profile.hiResImage.then((图像结果) {
    猜你喜欢
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 2023-01-31
    • 2020-01-05
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 2022-07-10
    相关资源
    最近更新 更多