import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_retrofit/example.dart';
class _HomepageState extends State<Homepage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: FutureBuilder(
future: this._getPosts(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return CircularProgressIndicator();
break;
case ConnectionState.waiting:
return CircularProgressIndicator();
break;
case ConnectionState.active:
return CircularProgressIndicator();
break;
case ConnectionState.done:
return CircularProgressIndicator();
break;
default:
return CircularProgressIndicator();
}
},),
),
);
}
Future _getPosts() async {
final dio= Dio();
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = await (client) async {
SecurityContext securityContext=new SecurityContext();
final ByteData crtData = await rootBundle.load('assets/server.crt');
securityContext.setTrustedCertificatesBytes(crtData.buffer.asUint8List());
final ByteData keyBytes = await rootBundle.load('assets/server.key');
securityContext.usePrivateKeyBytes(keyBytes.buffer.asUint8List());
return HttpClient(context: securityContext);
};
final client = RestClient(dio);
client.login('mad***h@****.in', '88888');
}
}
在颤振中,我们正在使用 Dio。我在使用 Dio 时遇到错误问题出在我需要使用 SSl 证书所以我使用了 Dio 但现在我收到以下错误。未处理的异常 Future 不是 HttpClient 的子类型。