1
\$\begingroup\$

I want to create a wrapper around this third party package class so that I don't litter my app with calls to it. The idea being that if there are breaking changes to the package (rename the class or one of its members), or if I want to delete the package, I can just change my implementation of it in this one file. Here is the third party package class:

abstract class GetWidget<T extends DisposableInterface>
    extends GetStatelessWidget {
  GetWidget({Key key}) : super(key: key);

  final Set<T> _value = <T>{};

  final String tag = null;

  T get controller {
    if (_value.isEmpty) _value.add(GetInstance().find<T>(tag: tag));
    return _value.first;
  }

  @override
  Widget build(BuildContext context);
}

Here is my attempt to wrap it (Vp is my app prefix identifying that it was created by my app):

abstract class VpWidget<T extends DisposableInterface> extends GetWidget<T> {
  VpWidget({Key key}) : super(key: key);

  @override
  T get controller {
    return super.controller;
  }
}

It seems to work. The class is so small anyway so i don't think I can wrap anything more from it. Just wondering if this is an effective use of a wrapper for decoupling my app from the package, or if there is no use and I should just call the package class directly?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.