Flutter “this function has a return type of void and I want a return type of map”
307
It seems that parseBody
does not return a map of the pasred body. It just makes sure the body is parsed and you can access it from the req.bodyAsMap
property. So your line should be:
await req.parseBody();
var body = req.bodyAsMap;
Author by
Mohammad Taghizadeh
Updated on December 02, 2022Comments
-
Mohammad Taghizadeh over 1 year
I am getting this error:This expression has a type of 'void' so its value can't be used. Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void.
code:
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_hot/angel_hot.dart'; import 'package:logging/logging.dart'; import 'dart:async'; import 'package:mongo_dart/mongo_dart.dart'; main() async { var hot = HotReloader(createServer, ['main.dart']); await hot.startServer('127.0.0.1', 3000); } Future<Angel> createServer() async { var app = Angel(); app.logger = Logger('Log')..onRecord.listen((event) => print(event)); print('start server..'); Db db = Db('mongodb://localhost:27017/wearina'); await db.open(); print('connected to ${db.databaseName}'); DbCollection userscoll = DbCollection(db, 'users'); print('${userscoll.collectionName}'); app.post('/signup', (req, res) async { var body = await req.parseBody(); //// parseBody => Future<void> , I want => Future<Map> ): var name = body['name']; var lastname = body['lastname']; var email = body['email']; var phone = body['phone']; var pass = body['pass']; }); return app; }
I don't understand what this is. I am new to flutter. This is my first app. Can someone please help me with this.
-
Eli Front about 3 yearsCheck which line this error originates from. If need be you can add the full log to the question. I can help from there. This error is likely due to you to assigning a function to a variable/object, but because the function is void (doesn't return a value) there ends up being an error. This should be a quickfix, but I'll need to see the full code & error log.
-
-
Mohammad Taghizadeh about 3 yearsThank you very much (: