Flutter client error


adding servicestack to flutter app failing with this message:

flutter packages get
Running “flutter packages get” in test_flutter_app… 1,1s
exit code 0
[test_flutter_app] flutter packages get
Running “flutter packages get” in test_flutter_app…
Because every version of flutter_test from sdk depends on http 0.12.0 and servicestack >=1.0.0 depends on http ^0.11.3+16, flutter_test from sdk is incompatible with servicestack >=1.0.0.
So, because test_flutter_app depends on both servicestack ^1.0.5 and flutter_test any from sdk, version solving failed.

pub get failed (1)
exit code 1

Installed latest flutter:

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.10.2, on Microsoft Windows [Version 10.0.17134.345], locale sr-Latn-RS)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[√] Android Studio (version 3.2)
[√] VS Code, 64-bit edition (version 1.28.2)
[√] Connected device (1 available)

• No issues found!

I’ve published an updated version with updated dependencies so this issue should be resolved if you reference:

  servicestack: ^1.0.6


I have one more question:
exceptionFilter hook is not catching SocketException that is thrown when connection timeout happends. Is there a way to catch this globaly and not wrap every call in try-except block?

There’s no other catch handlers except for exceptionFilter and its equivalent static globalExceptionFilter.

What’s the StackTrace of the SocketException?

I did this to reduce connection timeout, catch exceptios and authenticate:

class Client extends JsonServiceClient {

  Client() : super(Strings.host) {
    this.onAuthenticationRequired = _authenticate;    

    this.client.connectionTimeout = Duration(seconds: 5);    

    this.exceptionFilter = (HttpClientResponse respone, Exception exc) {          

I find this In http.dart:

/// Gets and sets the connection timeout.
/// When connecting to a new host exceeds this timeout, a [SocketException]
/// is thrown. The timeout applies only to connections initiated after the
/// timeout is set.
/// When this is null, the OS default timeout is used. The default is
/// null.
Duration connectionTimeout;

In my test application when server is not running I get this in DEBUG CONSOLE:

E/flutter ( 3508): [ERROR:flutter/shell/common/shell.cc(188)] Dart Error: Unhandled exception:
E/flutter ( 3508): NoSuchMethodError: The method ‘setOption’ was called on null.
E/flutter ( 3508): Receiver: null
E/flutter ( 3508): Tried calling: setOption(Instance of ‘SocketOption’, true)
E/flutter ( 3508): #0 JsonServiceClient.createRequest (package:servicestack/client.dart:353:15)
E/flutter ( 3508):
E/flutter ( 3508): #1 JsonServiceClient.sendRequest (package:servicestack/client.dart:258:21)
E/flutter ( 3508):
E/flutter ( 3508): #2 JsonServiceClient.send (package:servicestack/client.dart:240:12)
E/flutter ( 3508): #3 JsonServiceClient.get (package:servicestack/client.dart:80:12)
E/flutter ( 3508): #4 DnevneInformacijeState._loadData (package:panagent_flutter/views/dnevne_informacije_view.dart:76:51)
E/flutter ( 3508):

exceptionFilter is not executed.

I’ve moved createRequest() to within the try/catch handler in this commit.

This change is available from 1.0.7 that’s now on dart pub.

I think that Stack Trace from my previus message is comming from this bug in Dart:

If I leave HttpClient.connectiontimeout to default value (null) and server is not running then null exception is thrown on line 288 in client.dart (res is null):

Don’t have control over bugs with internal APIs, but is it now caught by the exceptionHandler?

No, it is not caught, I’m only getting null exception.

I/flutter (21121): NoSuchMethodError: The getter ‘statusCode’ was called on null.
I/flutter (21121): Receiver: null
I/flutter (21121): Tried calling: statusCode
E/flutter (21121): [ERROR:flutter/shell/common/shell.cc(188)] Dart Error: Unhandled exception:
E/flutter (21121): NoSuchMethodError: The getter ‘statusCode’ was called on null.
E/flutter (21121): Receiver: null
E/flutter (21121): Tried calling: statusCode
E/flutter (21121): #0 Client.getStatus (package:panagent_flutter/shared/client.dart:71:9)
E/flutter (21121):
E/flutter (21121): #1 DnevneInformacijeState._loadData (package:panagent_flutter/views/dnevne_informacije_view.dart:76:54)
E/flutter (21121):

ok it should be now handled from this commit.

This change is now available in 1.0.8.