Search code examples
functiondartflutterredisreturn-type

return_of_invalid_type The return type 'String' isn't a 'void', as defined by the method 'getData'


error: The return type 'String' isn't a 'void', as defined by the method 'getData'. (return_of_invalid_type at [todo_app_ui] lib/redis.dart:9)

This is function for get data from redis server and put it into flutter app.

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;
}

error: The return type 'String' isn't a 'void', as defined by the method 'getData'. (return_of_invalid_type at [todo_app_ui] lib/redis.dart:9)


Solution

  • There how its get fixed! :

    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;
    }