hurshi / dio-http-cache

http cache lib for Flutter dio like RxCache
Apache License 2.0
274 stars 223 forks source link

Exception when run dart code test #73

Closed winterdl closed 3 years ago

winterdl commented 3 years ago

I have a

import 'package:dio_http_cache/dio_http_cache.dart';

Future<String> _getWebContent(String url) async {
  Dio dio = Dio();
  dio.interceptors.add(DioCacheManager(
          CacheConfig(baseUrl: url, skipDiskCache: true, skipMemoryCache: false))
      .interceptor);
  var response = await dio.get(url,
      options: buildCacheOptions(
        Duration(minutes: 5),
        maxStale: Duration(minutes: 15),
      ));
  dio.close();
  return response.data;
}

getWebContent('https://google.com');

Exception:

dart ./test/dio_test.dart
../../../../dev/flutter/flutter/packages/flutter/lib/src/cupertino/action_sheet.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show ImageFilter;
       ^
../../../../dev/flutter/flutter/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show ImageFilter;
....

But when I comment added code, and not comment out 'dio_http_cache.dart' import statement, the exception still occurs, I comment the import statement and the added code, it runs as expected.

//import 'package:dio_http_cache/dio_http_cache.dart';

Future<String> _getWebContent(String url) async {
  Dio dio = Dio();
  //dio.interceptors.add(DioCacheManager(
  //        CacheConfig(baseUrl: url, skipDiskCache: true, skipMemoryCache: true))
  //    .interceptor);
  var response = await dio.get(url);

 //     options: buildCacheOptions(
 //       Duration(minutes: 5),
 //       maxStale: Duration(minutes: 15),
 //      )

  dio.close();
  return response.data;
}
winterdl commented 3 years ago

Could not use in isolate, https://github.com/flutter/flutter/issues/47197, I think I should try another ways. If you wanna test, should add TestWidgetsFlutterBinding.ensureInitialized(), but the problem is cache access os functions, this is not allowed in isolate except main function.