Here is my server side dart code:
import 'dart:io';
import 'package:http_server/http_server.dart';
void main() {
HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8080).then((server) {
server.listen((HttpRequest request) {
if (request.method.toLowerCase() == 'post' && request.uri.path == '/upload') {
HttpBodyHandler.processRequest(request).then((body) {
HttpBodyFileUpload fileUpload = body.body['file'];
File file = new File('aaa');
file.writeAsBytes(fileUpload.content, mode: FileMode.WRITE).then((_) {
request.response.close();
});
});
}
});
});
}
and my error is:
Unhandled exception:
Uncaught Error: FormatException: Bad UTF-8 encoding 0xbf
Stack Trace:
#0 _Utf8Decoder.convert (dart:convert/utf.dart:534)
#1 _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:334)
#2 _Utf8ConversionSink.add (dart:convert/string_conversion.dart:330)
#3 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:89)
#4 _handleData (dart:async/stream_transformers.dart:119)
#5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1020)
#6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:270)
#8 _StreamController&&_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:578)
#9 _StreamController._add (dart:async/stream_controller.dart:453)
#10 _StreamController.add (dart:async/stream_controller.dart:410)
#11 BoundMultipartStream._parse.reportData (package:mime/src/bound_multipart_stream.dart:161:34)
#12 BoundMultipartStream._parse (package:mime/src/bound_multipart_stream.dart:318:28)
#13 BoundMultipartStream.BoundMultipartStream.<anonymous closure>.<anonymous closure> (package:mime/src/bound_multipart_stream.dart:111:24)
#14 _RootZone.runUnaryGuarded (dart:async/zone.dart:1020)
#15 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#16 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:270)
#17 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:122)
#18 _ForwardingStream._handleData (dart:async/stream_pipe.dart:86)
#19 _handleData (dart:async/stream_pipe.dart:154)
#20 _RootZone.runUnaryGuarded (dart:async/zone.dart:1020)
#21 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#22 _DelayedData.perform (dart:async/stream_impl.dart:595)
#23 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:711)
#24 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:671)
#25 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#26 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#27 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:126)
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:820)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:126)
Process finished with exit code 255
I used postman to make a post, I chose form-data and add a key called file, value is a txt file.
after send my post to dart server, i got this exception.
is there something wrong with the post ? or the dart code ?
I'm really new to dart, please help me out...
thank you.
Related
I have follow code. I need to handle Exception in it, but I can't do it. And can't understand the reason.
try {
print("aaa");
List<List<dynamic>> result =
await connection.query(sql).timeout(Duration(seconds: 120));
print('bbb');
if (result.isEmpty) {
sql = """ ... """;
await connection.query(sql);
} else {
int dbXmlId = result[0][0];
DateTime dbXMLDocDate = result[0][1];
if (dbXMLDocDate.isBefore(DateTime.parse(docDate!))) {
sql = """ ... """;
// print(sql);
await connection.query(sql);
sql = """ .... """;
currentJob['filesInserted']++;
await connection.query(sql);
} else {
sql = """ .... """;
await connection.query(sql);
}
}
} on PostgreSQLException catch (e) {
print('Exception during Insert in xml_files: $e');
exit(0);
} on SocketException catch (e) {
// пытаемся багу поймать
print('SocketException during Insert in xml_files: $e');
exit(0);
} on Exception catch (e) {
print('BaseException during Insert in xml_files: $e');
exit(0);
} catch (e) {
print("We should not reach this");
}
What I am getting on console:
aaa
Unhandled exception:
SocketException: Write failed (OS Error: An existing connection was forcibly closed by the remote host, errno = 10054), address = localhost, port = 51230
#0 _NativeSocket.write (dart:io-patch/socket_patch.dart:1182:34)
#1 _RawSocket.write (dart:io-patch/socket_patch.dart:1897:15)
#2 _Socket._write (dart:io-patch/socket_patch.dart:2334:18)
#3 _SocketStreamConsumer.write (dart:io-patch/socket_patch.dart:2082:26)
#4 _SocketStreamConsumer.addStream.<anonymous closure> (dart:io-patch/socket_patch.dart:2056:11)
#5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1620:10)
#6 _BufferingStreamSubscription._sendData(dart:async/stream_impl.dart:341:11)
#7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#8 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#9 _StreamController._add (dart:async/stream_controller.dart:607:7)
#10 _StreamController.add (dart:async/stream_controller.dart:554:5)
#11 _StreamSinkImpl.add (dart:io/io_sink.dart:136:17)
#12 _Socket.add (dart:io-patch/socket_patch.dart:2181:38)
#13 Query.sendExtended (package:postgres/src/query.dart:98:12)
#14 _PostgreSQLConnectionStateIdle.processQuery (package:postgres/src/connection_fsm.dart:214:9)
#15 _PostgreSQLConnectionStateIdle.awake (package:postgres/srcconnection_fsm.dart:200:14)
#16 _PostgreSQLExecutionContextMixin._enqueue (package:postgres/srcconnection.dart:516:67)
#17 _PostgreSQLExecutionContextMixin._query (package:postgres/srcconnection.dart:460:15)
#18 _PostgreSQLExecutionContextMixin.query (package:postgres/srcconnection.dart:427:7)
#19 insertOrUpdateXmlFiles (package:data_loader/Servicesftp_service.dart:499:53)
#20 scanUnpackedFolder (package:data_loader/Services/ftp_service.dart:360:11)
<asynchronous suspension>
#21 unpackArchive (package:data_loader/Services/ftp_service.dart:320:6)
<asynchronous suspension>
#22 downloadArchive (package:data_loader/Services/ftp_service.dart:281:7)
<asynchronous suspension>
#23 runFtpParsingOrOnlyUnpackArchives (package:data_loader/Services/ftp_service.dart:736:5)
<asynchronous suspension>
#24 choiceOfProcessingAction (package:data_loader/Services/ftp_service.dart:658:9)
<asynchronous suspension>
#25 startNewJob (package:data_loader/Services/ftp_service.dart:762:5)
<asynchronous suspension>
#26 main.<anonymous closure> (file:///D:/code/zakupki/data_loader/bin/data_loader.dart:61:9)
<asynchronous suspension>
#27 Alfred._incomingRequest (package:alfred/src/alfred.dart:345:15)
<asynchronous suspension>
#28 _QueuedFuture.execute (package:queue/src/dart_queue_base.dart:26:16)
<asynchronous suspension>
I am seeing on console: aaa but do not see bbb and try-catch do not handle an Exception between them.
Full code: https://gist.github.com/bubnenkoff/7377f735671aacd624371a14151856f4
Solved though chat so this is a resume:
There have been created an issue for this problem here: https://github.com/isoos/postgresql-dart/issues/23
Initial testing shows that it might be because the package are using a synchronously completer, which is really a great way to get a lot of potential issues if you read the official documentation: https://api.dart.dev/stable/2.15.1/dart-async/Completer/Completer.sync.html
If the Completer is changed to a normal asynchronously completer, it is possible to catch the exception from the question.
The issue might be solved in another way but the conclusion is that the problem (with not being able to catch the exceptions, not the exceptions themself) is very likely in the postgres package and should be fixed here.
Does anyone know how to fix this?
I tried to use these codes for issuing access token, but i got errored.
protected function oauthLogin(Request $request)
{
$client = DB::table('oauth_clients')
->where('password_client', true)
->first();
$request->request->add([
"grant_type" => "password",
"username" => $request->email,
"password" => $request->password,
"client_id" => $client->id,
"client_secret" => $client->secret,
]);
$tokenRequest = $request->create(
env('APP_URL') . 'api/v1/oauth/token',
'post'
);
$instance = Route::dispatch($tokenRequest);
return json_decode($instance->getContent());
}
This was the error traceable logs. I dont know if this is related because my even my credentials was correct so, i dont think, that my credentials was denied. I tried it also to oauth/token and it was working. Still the same error. I've got.
[2019-02-20 13:22:09] local.ERROR: League\OAuth2\Server\Exception\OAuthServerException: The resource owner or authorization server denied the request. in D:\laragon\www\auth-service-optimize\vendor\league\oauth2-server\src\Exception\OAuthServerException.php:215
Stack trace:
#0 D:\laragon\www\auth-service-optimize\vendor\league\oauth2-server\src\AuthorizationValidators\BearerTokenValidator.php(73): League\OAuth2\Server\Exception\OAuthServerException::accessDenied('Access token co...')
#1 D:\laragon\www\auth-service-optimize\vendor\league\oauth2-server\src\ResourceServer.php(84): League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator->validateAuthorization(Object(Zend\Diactoros\ServerRequest))
#2 D:\laragon\www\auth-service-optimize\vendor\laravel\passport\src\Guards\TokenGuard.php(174): League\OAuth2\Server\ResourceServer->validateAuthenticatedRequest(Object(Zend\Diactoros\ServerRequest))
#3 D:\laragon\www\auth-service-optimize\vendor\laravel\passport\src\Guards\TokenGuard.php(126): Laravel\Passport\Guards\TokenGuard->getPsrRequestViaBearerToken(Object(Laravel\Lumen\Http\Request))
#4 D:\laragon\www\auth-service-optimize\vendor\laravel\passport\src\Guards\TokenGuard.php(89): Laravel\Passport\Guards\TokenGuard->authenticateViaBearerToken(Object(Laravel\Lumen\Http\Request))
#5 D:\laragon\www\auth-service-optimize\vendor\laravel\passport\src\PassportServiceProvider.php(274): Laravel\Passport\Guards\TokenGuard->user(Object(Laravel\Lumen\Http\Request))
#6 [internal function]: Laravel\Passport\PassportServiceProvider->Laravel\Passport\{closure}(Object(Laravel\Lumen\Http\Request), NULL)
#7 D:\laragon\www\auth-service-optimize\vendor\illuminate\auth\RequestGuard.php(58): call_user_func(Object(Closure), Object(Laravel\Lumen\Http\Request), NULL)
#8 D:\laragon\www\auth-service-optimize\app\Http\Controllers\AuthController.php(169): Illuminate\Auth\RequestGuard->user()
#9 [internal function]: App\Http\Controllers\AuthController->adminLogin(Object(Laravel\Lumen\Http\Request))
#10 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(29): call_user_func_array(Array, Array)
#11 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#12 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#13 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\Container.php(572): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#14 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(378): Illuminate\Container\Container->call(Array, Array)
#15 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(344): Laravel\Lumen\Application->callControllerCallable(Array, Array)
#16 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(318): Laravel\Lumen\Application->callLumenController(Object(App\Http\Controllers\AuthController), 'adminLogin', Array)
#17 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(280): Laravel\Lumen\Application->callControllerAction(Array)
#18 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(265): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array)
#19 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(165): Laravel\Lumen\Application->handleFoundRoute(Array)
#20 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(418): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(Object(Laravel\Lumen\Http\Request))
#21 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(171): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#22 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(108): Laravel\Lumen\Application->dispatch(NULL)
#23 D:\laragon\www\auth-service-optimize\public\index.php(28): Laravel\Lumen\Application->run()
#24 {main} {"exception":"[object] (League\\OAuth2\\Server\\Exception\\OAuthServerException(code: 9): The resource owner or authorization server denied the request. at D:\\laragon\\www\\auth-service-optimize\\vendor\\league\\oauth2-server\\src\\Exception\\OAuthServerException.php:215)
[stacktrace]
#0 D:\\laragon\\www\\auth-service-optimize\\vendor\\league\\oauth2-server\\src\\AuthorizationValidators\\BearerTokenValidator.php(73): League\\OAuth2\\Server\\Exception\\OAuthServerException::accessDenied('Access token co...')
#1 D:\\laragon\\www\\auth-service-optimize\\vendor\\league\\oauth2-server\\src\\ResourceServer.php(84): League\\OAuth2\\Server\\AuthorizationValidators\\BearerTokenValidator->validateAuthorization(Object(Zend\\Diactoros\\ServerRequest))
#2 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php(174): League\\OAuth2\\Server\\ResourceServer->validateAuthenticatedRequest(Object(Zend\\Diactoros\\ServerRequest))
#3 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php(126): Laravel\\Passport\\Guards\\TokenGuard->getPsrRequestViaBearerToken(Object(Laravel\\Lumen\\Http\\Request))
#4 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php(89): Laravel\\Passport\\Guards\\TokenGuard->authenticateViaBearerToken(Object(Laravel\\Lumen\\Http\\Request))
#5 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\passport\\src\\PassportServiceProvider.php(274): Laravel\\Passport\\Guards\\TokenGuard->user(Object(Laravel\\Lumen\\Http\\Request))
#6 [internal function]: Laravel\\Passport\\PassportServiceProvider->Laravel\\Passport\\{closure}(Object(Laravel\\Lumen\\Http\\Request), NULL)
#7 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\auth\\RequestGuard.php(58): call_user_func(Object(Closure), Object(Laravel\\Lumen\\Http\\Request), NULL)
#8 D:\\laragon\\www\\auth-service-optimize\\app\\Http\\Controllers\\AuthController.php(169): Illuminate\\Auth\\RequestGuard->user()
#9 [internal function]: App\\Http\\Controllers\\AuthController->adminLogin(Object(Laravel\\Lumen\\Http\\Request))
#10 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(29): call_user_func_array(Array, Array)
#11 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#12 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure))
#13 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\Container.php(572): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL)
#14 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(378): Illuminate\\Container\\Container->call(Array, Array)
#15 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(344): Laravel\\Lumen\\Application->callControllerCallable(Array, Array)
#16 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(318): Laravel\\Lumen\\Application->callLumenController(Object(App\\Http\\Controllers\\AuthController), 'adminLogin', Array)
#17 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(280): Laravel\\Lumen\\Application->callControllerAction(Array)
#18 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(265): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute(Array)
#19 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(165): Laravel\\Lumen\\Application->handleFoundRoute(Array)
#20 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(418): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Laravel\\Lumen\\Http\\Request))
#21 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(171): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#22 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(108): Laravel\\Lumen\\Application->dispatch(NULL)
#23 D:\\laragon\\www\\auth-service-optimize\\public\\index.php(28): Laravel\\Lumen\\Application->run()
#24 {main}
"}
[2019-02-20 13:22:09] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Laravel\Lumen\Routing\Router::dispatch() in D:\laragon\www\auth-service-optimize\vendor\illuminate\support\Facades\Facade.php:237
Stack trace:
#0 D:\laragon\www\auth-service-optimize\app\Http\Controllers\AuthController.php(202): Illuminate\Support\Facades\Facade::__callStatic('dispatch', Array)
#1 D:\laragon\www\auth-service-optimize\app\Http\Controllers\AuthController.php(171): App\Http\Controllers\AuthController->oauthLogin(Object(Laravel\Lumen\Http\Request))
#2 [internal function]: App\Http\Controllers\AuthController->adminLogin(Object(Laravel\Lumen\Http\Request))
#3 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(29): call_user_func_array(Array, Array)
#4 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#5 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#6 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\Container.php(572): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#7 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(378): Illuminate\Container\Container->call(Array, Array)
#8 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(344): Laravel\Lumen\Application->callControllerCallable(Array, Array)
#9 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(318): Laravel\Lumen\Application->callLumenController(Object(App\Http\Controllers\AuthController), 'adminLogin', Array)
#10 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(280): Laravel\Lumen\Application->callControllerAction(Array)
#11 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(265): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array)
#12 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(165): Laravel\Lumen\Application->handleFoundRoute(Array)
#13 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(418): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(Object(Laravel\Lumen\Http\Request))
#14 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(171): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#15 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(108): Laravel\Lumen\Application->dispatch(NULL)
#16 D:\laragon\www\auth-service-optimize\public\index.php(28): Laravel\Lumen\Application->run()
#17 {main} {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to undefined method Laravel\\Lumen\\Routing\\Router::dispatch() at D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\support\\Facades\\Facade.php:237)
[stacktrace]
#0 D:\\laragon\\www\\auth-service-optimize\\app\\Http\\Controllers\\AuthController.php(202): Illuminate\\Support\\Facades\\Facade::__callStatic('dispatch', Array)
#1 D:\\laragon\\www\\auth-service-optimize\\app\\Http\\Controllers\\AuthController.php(171): App\\Http\\Controllers\\AuthController->oauthLogin(Object(Laravel\\Lumen\\Http\\Request))
#2 [internal function]: App\\Http\\Controllers\\AuthController->adminLogin(Object(Laravel\\Lumen\\Http\\Request))
#3 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(29): call_user_func_array(Array, Array)
#4 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#5 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure))
#6 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\Container.php(572): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL)
#7 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(378): Illuminate\\Container\\Container->call(Array, Array)
#8 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(344): Laravel\\Lumen\\Application->callControllerCallable(Array, Array)
#9 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(318): Laravel\\Lumen\\Application->callLumenController(Object(App\\Http\\Controllers\\AuthController), 'adminLogin', Array)
#10 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(280): Laravel\\Lumen\\Application->callControllerAction(Array)
#11 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(265): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute(Array)
#12 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(165): Laravel\\Lumen\\Application->handleFoundRoute(Array)
#13 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(418): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Laravel\\Lumen\\Http\\Request))
#14 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(171): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#15 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(108): Laravel\\Lumen\\Application->dispatch(NULL)
#16 D:\\laragon\\www\\auth-service-optimize\\public\\index.php(28): Laravel\\Lumen\\Application->run()
#17 {main}
"}
The request that is dispatched is without the credentials added in the preceding line.
The reason being that Request::create returns a new request instance.
Add the request parameters in the newly created on $request and then dispatch it.
$tokenRequest = $request->create(
env('APP_URL') . 'api/v1/oauth/token',
'POST'
);
$tokenRequest->request->add([
"grant_type" => "password",
"username" => $request->email,
"password" => $request->password,
"client_id" => $client->id,
"client_secret" => $client->secret,
]);
$response = app()->handle($tokenRequest);
I'm learning streams/bloc pattern in dart/flutter and can't pinpoint where the error is coming from when I try to run my app. I assume the stream is getting hung up somewhere judging by the async errors. I am usingdispose() and closing out the streams inside it. Any help would be appreciated.
Here is the code. I put it all in one big chunk but commented which file each of the code chunks is from:
// bloc.dart
import 'dart:async';
import 'validators.dart';
class Bloc extends Validators {
final _email = new StreamController<String>();
final _password = new StreamController<String>();
// Add data to stream
Stream<String> get email => _email.stream.transform(validateEmail);
Stream<String> get password => _password.stream.transform(validatePassword);
// Change Data
Function(String) get changeEmail => _email.sink.add;
Function(String) get changePassword => _password.sink.add;
dispose() {
_email.close();
_password.close();
}
}
final bloc = Bloc();
// login_screen.dart
import 'package:flutter/material.dart';
import '../blocs/bloc.dart';
class LoginScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(20.0),
child: Column(
children: [
emailField(),
passwordField(),
Container(
margin: EdgeInsets.only(top: 25.0),
),
raisedButton()
],
));
}
Widget emailField() {
return StreamBuilder(
stream: bloc.email,
builder: (context, snapshot) {
return TextField(
onChanged: bloc.changeEmail,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
hintText: 'ardon#exampl.com',
labelText: 'Enter your email!',
errorText: snapshot.error),
);
});
}
Widget passwordField() {
return TextField(
obscureText: true,
decoration: InputDecoration(hintText: 'password', labelText: 'password'),
);
}
Widget raisedButton() {
return RaisedButton(
child: Text('Login'),
color: Colors.blue,
onPressed: () {},
);
}
}
// validation.dart
import 'dart:async';
class Validators {
final validateEmail =
StreamTransformer<String, String>.fromHandlers(handleData: (email, sink) {
if (email.contains('#')) {
sink.add(email);
} else {
sink.addError('Please enter valid email');
}
});
final validatePassword = StreamTransformer<String, String>.fromHandlers(
handleData: (password, sink) {
if (password.length > 4) {
sink.add(password);
} else {
sink.addError('Please enter the right number of characters');
}
});
}
Here is the error I am getting when I try to hot restart my app:
⣯[VERBOSE-2:shell.cc(181)] Dart Error: Can't load Kernel binary: Invalid kernel binary format version.
[VERBOSE-2:engine.cc(158)] Could not prepare to run the isolate.
[VERBOSE-2:engine.cc(117)] Engine not prepare and launch isolate.
Error -32000 received from application: Could not run configuration in engine.
JSON-RPC error -32000: Could not run configuration in engine.
package:json_rpc_2/src/client.dart 110:64 Client.sendRequest
package:json_rpc_2/src/peer.dart 68:15 Peer.sendRequest
package:flutter_tools/src/vmservice.dart 293:13 VMService._sendRequest
package:flutter_tools/src/vmservice.dart 842:12 VM.invokeRpcRaw
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 865:49 VM.invokeRpc
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 932:12 VM.runInView
package:flutter_tools/src/vmservice.dart 1439:20 FlutterView.runFromSource
===== asynchronous gap ===========================
package:flutter_tools/src/run_hot.dart 379:18 HotRunner._launchInView
===== asynchronous gap ===========================
package:flutter_tools/src/run_hot.dart 390:13 HotRunner._launchFromDevFS
===== asynchronous gap ===========================
package:flutter_tools/src/run_hot.dart 442:11 HotRunner._restartFromSources
===== asynchronous gap ===========================
package:flutter_tools/src/run_hot.dart 505:15 HotRunner.restart
===== asynchronous gap ===========================
package:flutter_tools/src/run_hot.dart 282:44 HotRunner.handleTerminalCommand
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 754:15 ResidentRunner.processTerminalInput
===== asynchronous gap ===========================
dart:async/zone.dart 1132:38 _rootRunUnary
dart:async/zone.dart 1029:19 _CustomZone.runUnary
dart:async/zone.dart 931:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7 _BufferingStreamSubscription._add
dart:async/broadcast_stream_controller.dart 379:20 _SyncBroadcastStreamController._sendData
dart:async/broadcast_stream_controller.dart 254:5 _BroadcastStreamController.add
dart:async/broadcast_stream_controller.dart 480:11 _AsBroadcastStreamController.add
dart:async/zone.dart 1132:38 _rootRunUnary
dart:async/zone.dart 1029:19 _CustomZone.runUnary
dart:async/zone.dart 931:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7 _BufferingStreamSubscription._add
dart:async/stream_transformers.dart 68:11 _SinkTransformerStreamSubscription._add
dart:async/stream_transformers.dart 15:11 _EventSinkWrapper.add
dart:convert/string_conversion.dart 268:11 _StringAdapterSink.add
dart:convert/string_conversion.dart 273:7 _StringAdapterSink.addSlice
dart:convert/string_conversion.dart 348:20 _Utf8ConversionSink.addSlice
dart:convert/ascii.dart 278:17 _ErrorHandlingAsciiDecoderSink.addSlice
dart:convert/ascii.dart 264:5 _ErrorHandlingAsciiDecoderSink.add
dart:convert/chunked_conversion.dart 86:18 _ConverterStreamEventSink.add
dart:async/stream_transformers.dart 120:24 _SinkTransformerStreamSubscription._handleData
dart:async/zone.dart 1132:38 _rootRunUnary
dart:async/zone.dart 1029:19 _CustomZone.runUnary
dart:async/zone.dart 931:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 763:19 _SyncStreamController._sendData
dart:async/stream_controller.dart 639:7 _StreamController._add
dart:async/stream_controller.dart 585:5 _StreamController.add
dart:io/runtime/binsocket_patch.dart 1714:41 _Socket._onData
dart:async/zone.dart 1136:13 _rootRunUnary
dart:async/zone.dart 1029:19 _CustomZone.runUnary
dart:async/zone.dart 931:7 _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11 _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7 _BufferingStreamSubscription._add
dart:async/stream_controller.dart 763:19 _SyncStreamController._sendData
dart:async/stream_controller.dart 639:7 _StreamController._add
dart:async/stream_controller.dart 585:5 _StreamController.add
dart:io/runtime/binsocket_patch.dart 1276:33 new _RawSocket.<fn>
dart:io/runtime/binsocket_patch.dart 819:14 _NativeSocket.issueReadEvent.issue
dart:async/schedule_microtask.dart 41:21 _microtaskLoop
dart:async/schedule_microtask.dart 50:5 _startMicrotaskLoop
dart:isolate/runtime/libisolate_patch.dart 115:13 _runPendingImmediateCallback
dart:isolate/runtime/libisolate_patch.dart 172:5 _RawReceivePortImpl._handleMessage
edit: When I do a hot reload instead of a hot restart, I get this error:
Initializing hot reload... ⣟Hot reload failed: type 'TimeoutException' is not a subtype of type 'Map<String, dynamic>'
#0 HotRunner._reloadSources.<anonymous closure> (package:flutter_tools/src/run_hot.dart:587:45)
#1 _rootRunUnary (dart:async/zone.dart:1132:38)
#2 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#3 _FutureListener.handleError (dart:async/future_impl.dart:147:20)
#4 Future._propagateToListeners.handleError (dart:async/future_impl.dart:654:47)
#5 Future._propagateToListeners (dart:async/future_impl.dart:675:24)
#6 Future._completeError (dart:async/future_impl.dart:494:5)
#7 Future.wait.handleError (dart:async/future.dart:379:18)
#8 _rootRunBinary (dart:async/zone.dart:1144:38)
#9 _CustomZone.runBinary (dart:async/zone.dart:1037:19)
#10 _FutureListener.handleError (dart:async/future_impl.dart:143:20)
#11 Future._propagateToListeners.handleError (dart:async/future_impl.dart:654:47)
#12 Future._propagateToListeners (dart:async/future_impl.dart:675:24)
#13 Future._completeError (dart:async/future_impl.dart:494:5)
#14 _SyncCompleter._completeError (dart:async/future_impl.dart:55:12)
#15 _Completer.completeError (dart:async/future_impl.dart:27:5)
#16 _AsyncAwaitCompleter.completeError (dart:async/runtime/libasync_patch.dart:40:18)
#17 Isolate.reloadSources (package:flutter_tools/src/vmservice.dart)
<asynchronous suspension>
#18 FlutterDevice.reloadSources (package:flutter_tools/src/resident_runner.dart:144:66)
#19 HotRunner._reloadSources (package:flutter_tools/src/run_hot.dart:579:67)
<asynchronous suspension>
#20 HotRunner.restart (package:flutter_tools/src/run_hot.dart:520:24)
<asynchronous suspension>
#21 HotRunner.handleTerminalCommand (package:flutter_tools/src/run_hot.dart:282:44)
<asynchronous suspension>
#22 ResidentRunner.processTerminalInput (package:flutter_tools/src/resident_runner.dart:754:15)
<asynchronous suspension>
#23 _rootRunUnary (dart:async/zone.dart:1132:38)
#24 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#25 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#26 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#27 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#28 _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:379:20)
#29 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:254:5)
#30 _AsBroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:480:11)
#31 _rootRunUnary (dart:async/zone.dart:1132:38)
#32 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#33 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#34 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#35 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#36 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#37 _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#38 _StringAdapterSink.add (dart:convert/string_conversion.dart:268:11)
#39 _StringAdapterSink.addSlice (dart:convert/string_conversion.dart:273:7)
#40 _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:348:20)
#41 _ErrorHandlingAsciiDecoderSink.addSlice (dart:convert/ascii.dart:278:17)
#42 _ErrorHandlingAsciiDecoderSink.add (dart:convert/ascii.dart:264:5)
#43 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:86:18)
#44 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#45 _rootRunUnary (dart:async/zone.dart:1132:38)
#46 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#47 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#48 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#49 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#50 _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#51 _StreamController._add (dart:async/stream_controller.dart:639:7)
#52 _StreamController.add (dart:async/stream_controller.dart:585:5)
#53 _Socket._onData (dart:io/runtime/binsocket_patch.dart:1714:41)
#54 _rootRunUnary (dart:async/zone.dart:1136:13)
#55 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#56 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#57 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#58 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#59 _SyncStreamController._sendData (dart:async/stream_controller.dart:763:19)
#60 _StreamController._add (dart:async/stream_controller.dart:639:7)
#61 _StreamController.add (dart:async/stream_controller.dart:585:5)
#62 new _RawSocket.<anonymous closure> (dart:io/runtime/binsocket_patch.dart:1276:33)
#63 _NativeSocket.issueReadEvent.issue (dart:io/runtime/binsocket_patch.dart:819:14)
#64 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#65 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#66 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#67 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)
A case where you'll frequently run into this is if you're building your own engine from source, and using it via flutter's --local-engine option.
Dart code in a Flutter app is initially compiled through the Dart kernel compiler, which emits a .dill file in an intermediate format. This intermediate format includes an identifier that the Dart VM in the Flutter engine uses to validate that it's compatible with that VM version. The root cause of an Invalid kernel binary format version error message is that the .dill file in question was generated with an incompatible version of the kernel compiler.
To resolve this, after rebuilding the engine for your device (e.g. android_debug_unopt), you'll want to ensure that you've also rebuilt the associated host toolchain (e.g. host_debug_unopt).
If you're seeing this in other cases, it's almost certainly a bug, and I'd definitely encourage you to open an issue against Flutter.
There was a bug fixed very recently that resulted in this error message https://github.com/flutter/flutter/issues/21348
I would expect this to be included in the latest Flutter dev and master channel.
To switch to the dev channel use
flutter channel dev
flutter doctor
update
(from https://github.com/flutter/flutter/issues/22964#issuecomment-429071970)
import './src/app.dart'; in lib/main.dart is the culprit.
lib/main.dart must not contain relative imports and must not be imported from other files
https://github.com/dart-lang/sdk#33076
was just fixed but it will take a while until it lands in Flutter.
Below code snippet throws Format Exception in Flutter json decode, Any suggestion please?
import 'dart:async' show Future;
import 'dart:convert';
Future<String> readBooks() async {
String jsonString = '{"description":"As part of the "You Don’t Know JS" series","quantity":55}';
Map<String, dynamic> books = json.decode(jsonString);
return jsonString;
}
Format Exception:
2018-10-23 20:40:30.680 18115-18142/addon.com.bookshop E/flutter:
[ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled
exception:
FormatException: Unexpected character (at character 26)
{"name":"As part of the "You Don’t Know JS" series","Age":55}
^
#0 _ChunkedJsonParser.fail (dart:convert/runtime/libconvert_patch.dart:1358:5)
#1 _ChunkedJsonParser.parse (dart:convert/runtime/libconvert_patch.dart:919:48)
#2 _parseJson (dart:convert/runtime/libconvert_patch.dart:29:10)
#3 JsonDecoder.convert (dart:convert/json.dart:540:36)
#4 JsonCodec.decode (dart:convert/json.dart:167:41)
#5 _MyHomePageState.readBooks (file:///E:/Me/TimePass/flutter/book_shop/lib/main.dart:58:39)
<asynchronous suspension>
#6 _MyHomePageState.build.<anonymous closure> (file:///E:/Me/TimePass/flutter/book_shop/lib/main.dart:48:39)
<asynchronous suspension>
#7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:503:14)
#8 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:558:30)
#9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#10 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
#11 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
#12 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
#13 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
#14 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
#15 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
#16 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
#17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
#18 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue
(package:flutter/src/gestures/binding.dart:64:7)
#19 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket
(package:flutter/src/gestures/binding.dart:48:7)
#20 _invoke1 (dart:ui/hooks.dart:142:13)
#21 _dispatchPointerDataPacket (dart:ui/hooks.dart:99:5)
That's just invalid JSON.
The inner quotes need to be escaped as \" to make your JSON valid.
I am using Event Channels in Flutter to return beacon data from Native SDK to Flutter. This was working fine until a recent Flutter upgrade.Now, I am getting the following error.
type '(PlatformException) => void' is not a subtype of type '(Object) => FutureOr<dynamic>
with the following stack trace:
#0 _registerErrorHandler (dart:async/async_error.dart:22:60)
#1 _BufferingStreamSubscription.onError (dart:async/stream_impl.dart:146:16)
#2 new _BufferingStreamSubscription (dart:async/stream_impl.dart:113:10)
#3 new _ControllerSubscription (dart:async/stream_controller.dart)
#4 new _BroadcastSubscription (dart:async/broadcast_stream_controller.dart)
#5 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:212:46)
#6 _ControllerStream._createSubscription (dart:async/stream_controller.dart:817:19)
#7 _StreamImpl.listen (dart:async/stream_impl.dart:466:9)
#8 _MyHomePageState.initPlatformState.<anonymous closure>.<anonymous closure> (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:95:43)
#9 _RootZone.runUnary (dart:async/zone.dart:1381:54)
#10 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#11 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
#12 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
#13 Future._complete (dart:async/future_impl.dart:467:7)
#14 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#15 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart)
<asynchronous suspension>
#16 _MyHomePageState.initPlatformState.<anonymous closure> (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:89:24)
<asynchronous suspension>
#17 _RootZone.runUnary (dart:async/zone.dart:1381:54)
#18 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#19 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
#20 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
#21 Future._complete (dart:async/future_impl.dart:467:7)
#22 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#23 User_Profile.getUser (package:flutter_poc/Models/User.dart)
<asynchronous suspension>
#24 _MyHomePageState.initPlatformState (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:69:24)
<asynchronous suspension>
#25 _MyHomePageState.initState (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:52:5)
#26 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3734:58)
#27 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
#28 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
#29 Element.updateChild
This is my EventChannel implementation:
static const platform = const MethodChannel('samples.flutter.io/initialiseRanging');
static const stream =
const EventChannel('samples.flutter.io/ranging');
try {
await platform.invokeMethod('initialiseRanging').then((result){
print(result);
setState(() {
_currentValue = result;
});
stream.receiveBroadcastStream().listen(_onEvent, onError: _onError);
});
} on PlatformException catch (e) {
print( "{e.message}");
}
This is how the _onEvent and _onError functions are implemented.
void _onEvent(Object event) {
setState(() {
_currentValue = event.toString();
});
print(event);
}
void _onError(PlatformException error) {
print(error);
}
Any idea on why this could possible happen?
void _onError(PlatformException error) {
should be
void _onError(Object error) {
Even when you are only interested in PlatformException or even when this is the only exception that happened so far, doesn't mean there can't be others. The expected handler function needs to match the parameter type, instead of only the exceptions you expect.