Search
 
SCRIPT & CODE EXAMPLE
 

DART

catching a socket exception in flutter

Future<Response> login(String user, String pwd) async {
  final String authHeader = encodeBasicCredentials(user, pwd);
  try {
    return await get(
        'http://192.168.0.100:8080/login',
        headers: {
          HttpHeaders.AUTHORIZATION: authHeader,
        },
      );
  } catch (e) {
    if(e is SocketException){
       //treat SocketException
       print("Socket exception: ${e.toString()}");
    }
    else if(e is TimeoutException){
       //treat TimeoutException
       print("Timeout exception: ${e.toString()}");
    }
    else print("Unhandled exception: ${e.toString()}");
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: rounded button flutter 
Dart :: flutter concat string list 
Dart :: path dart 
Dart :: remove native splash screen flutter 
Dart :: flutter build async 
Dart :: select an item woth index list dart 
Dart :: flutter firebase get provider type 
Dart :: flutter row vertical direction 
Dart :: flutter map get value by key 
Dart :: app bar color flutter 
Dart :: flutter sliver persistent header example 
Dart :: dart set union 
Dart :: flutter check variable has object 
Dart :: flutter pop to index 1 
Dart :: how to add a listner to a object in dart 
Dart :: package:grpc/grpc.dart import target uri doesnt exist 
Dart :: convert to string flutter 
Swift :: swift generate random number 
Swift :: change from Date to String swift 5 
Swift :: swift get app version and build 
Swift :: remove back button from navigation bar swift 
Swift :: uicollectionview detect scroll swift 
Swift :: rtl ios swift 
Swift :: Decimal to Double conversion in Swift 
Swift :: print an array in swift 
Swift :: how to insert element at start of the array ios swift 
Swift :: swift reload tableviewcell at index 
Swift :: power swift 
Swift :: wkwebview load delegate in swift 
Swift :: sf symbols 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =