Search code examples
flutterdartwebviewdiocookiemanager

CookieManager function of dio_cookie_manager plugin conflict with flutter_inappwebview Cookiemanager


When I use the CookieManager function of dio_cookie_manager plugin into the page of included flutter_inappwebview plugin, I got the errors:

The argument type 'CookieManager' can't be assigned to the parameter type 'interceptors'

and

'CookieManager' isn't a function.

How can I use both plugins with separate Cookiemanager?


Solution

  • to avoid such conflicts, make sure that you use import '...' as customName.
    For example;

    import 'package:dio/dio.dart';
    import 'package:dio_cookie_manager/cookie_manager.dart' as dioCookieManager;
    import 'package:cookie_jar/cookie_jar.dart';
    

    in that case, you can use it like

    var dio =  Dio();
      var cookieJar = CookieJar();
      dio.interceptors.add(dioCookieManager.CookieManager(cookieJar));
    // ...
    

    so you can avoid conflicts with other packages as well.