Surface/lib/providers/sn_network.dart
2024-11-09 01:11:56 +08:00

36 lines
895 B
Dart

import 'dart:io';
import 'package:dio/dio.dart';
import 'package:dio_smart_retry/dio_smart_retry.dart';
import 'package:flutter/foundation.dart';
import 'package:native_dio_adapter/native_dio_adapter.dart';
const kUseLocalNetwork = true;
class SnNetworkProvider {
late final Dio client;
SnNetworkProvider() {
client = Dio();
client.options.baseUrl = kUseLocalNetwork
? 'http://localhost:8001'
: 'https://api.sn.solsynth.dev';
client.interceptors.add(RetryInterceptor(
dio: client,
retries: 3,
retryDelays: const [
Duration(milliseconds: 300),
Duration(milliseconds: 1000),
Duration(milliseconds: 3000),
],
));
if (!kIsWeb && Platform.isAndroid || Platform.isIOS || Platform.isMacOS) {
// Switch to native implementation if possible
client.httpClientAdapter = NativeAdapter();
}
}
}