dimanche 25 juillet 2021

Error: Unsupported operation: Platform._version when call api flutter

I use packages http: ^ 0.12.2

this is my import

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';

for retrieving the data from a server. It works fine with Android and iOS. But on the web I get the error message Unsupported operation: Platform._version

this is my class:

class ApiService {
   var client = new http.Client();

   http.Client httpsClient() {
      var ioClient = new HttpClient()
         ..badCertificateCallback =
              (X509Certificate cert, String host, int port) => true;
      return new IOClient(ioClient);
   }

   Future<String> login(String user, String pass) async {
   try {
       var response = await httpsClient().post(
           '192.168.1.1:1234/api/abc',
           headers: <String, String>{
             'Content-Type': 'application/json; charset=UTF-8',
           },
           body: jsonEncode(<String, String>{'username': user, 'matkhau': pass}),
         );
         if (response.statusCode == 200) {
             print('ok');
         } else {
             return null;
         }
    }catch (e) {
       print(e);
    }
  }
  ....
}

please help me




Aucun commentaire:

Enregistrer un commentaire