return_of_invalid_type返回类型'String'不是'void',如方法'getData'所定义

时间:2019-05-18 18:15:11

标签: function dart flutter redis return-type

错误:如方法'getData'所定义,返回类型'String'不是'void'。 (位于[todo_app_ui] lib / redis.dart:9处的return_of_invalid_type)

此功能用于从Redis服务器获取数据并将其放入Flutter应用中。

import 'package:resp_client/resp_client.dart';
import 'package:resp_client/resp_commands.dart';

void getData(key) async {
  final server = await connectSocket('localhost');
  final client = RespClient(server);
  final commands = RespCommands(client);
  final get = await commands.get('test');
  return get;
}

错误:如方法'getData'所定义,返回类型'String'不是'void'。 (位于[todo_app_ui] lib / redis.dart:9处的return_of_invalid_type)

1 个答案:

答案 0 :(得分:0)

有它如何解决! :

import 'package:resp_client/resp_client.dart';
import 'package:resp_client/resp_commands.dart';

Future<void> getData(key) async {
  final server = await connectSocket('localhost');
  final client = RespClient(server);
  final commands = RespCommands(client);
  final get = await commands.get('test');
  return get;
}