【问题标题】:Why I got Instance of Future<List<int>> with flutter?为什么我得到 Instance of Future<List<int>> with flutter?
【发布时间】:2022-11-22 17:10:47
【问题描述】:

我试图在警报对话框的文本中显示 Future<List> 的值,但我得到了 future<list> 的实例。 这是我的代码:

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
                showDialog(
                    context: context,
                    barrierColor: Colors.transparent,
                    builder: (context) {
                      return AlertDialog(
                        title: Text(
                            'Be Careful ${characteristic46?.read()}'),
                        backgroundColor: Color.fromARGB(45, 231, 148, 54),
                        alignment: Alignment.topCenter,
                      );
                    });
              });

在此先感谢您的帮助

【问题讨论】:

标签: flutter dart bluetooth-lowenergy instance future


【解决方案1】:

你的 characteristic46?.read()Future 并且你需要 await 来获得它的结果。尝试这个:

WidgetsBinding.instance.addPostFrameCallback((timeStamp) async{
            var result = await characteristic46?.read();
            showDialog(
                context: context,
                barrierColor: Colors.transparent,
                builder: (context) {
                  return AlertDialog(
                    title: Text(
                        'Be Careful $result'),
                    backgroundColor: Color.fromARGB(45, 231, 148, 54),
                    alignment: Alignment.topCenter,
                  );
                });
          });

【讨论】:

    猜你喜欢
    • 2023-01-12
    • 1970-01-01
    • 2020-08-15
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2013-08-25
    • 2018-03-21
    相关资源
    最近更新 更多