Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: make Dio client configurable #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions lib/src/rpcclient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class RPCClient {
String username;
String password;
bool useSSL;
Dio? _dioClient;
late String _url;
late Map<String, String> _headers;
Dio? dioClient;

RPCClient({
required this.host,
Expand Down Expand Up @@ -77,18 +75,19 @@ class RPCClient {
}

Future<dynamic> call(var methodName, [var params]) async {
final headers = {
'Content-Type': 'application/json',
'authorization':
'Basic ${base64.encode(utf8.encode('$username:$password'))}'
};
final url = getConnectionString();

// init values
if (_dioClient == null) {
_headers = {
'Content-Type': 'application/json',
'authorization':
'Basic ${base64.encode(utf8.encode('$username:$password'))}'
};
_url = getConnectionString();
_dioClient = Dio();
_dioClient!.interceptors.add(
if (dioClient == null) {
dioClient = Dio();
dioClient!.interceptors.add(
RetryInterceptor(
dio: _dioClient!,
dio: dioClient!,
logPrint: null,
retries: 5,
),
Expand All @@ -102,11 +101,11 @@ class RPCClient {
};

try {
var response = await _dioClient!.post(
_url,
var response = await dioClient!.post(
url,
data: body,
options: Options(
headers: _headers,
headers: headers,
),
);
if (response.statusCode == HttpStatus.ok) {
Expand Down