Open feinstein opened 7 months ago
You can use extension or mixin
extension BitbucketRestDataSourceEx on BitbucketRestDataSource { void test() { print("test"); } }
I want access to the dio
instance, the only way I could find so far is by doing this ugly hack:
factory AuthRemoteDataSource(Dio dio, {String? baseUrl}) => _AuthRemoteDataSource._(dio, dio, baseUrl: baseUrl);
const AuthRemoteDataSource._(this.dio);
final Dio dio;
...
Future<Uint8List?> getImage(String url) async {
// add code here that uses the dio instance.
}
This declares a private constructor, and then I need to call the generated constructor repeting the dio twice, because it creates a dynamic parameter that's forwarded into the private constructor.
I want to add a helper method to my api class, but if I try I get an error message from my compiler saying that method's implementation could not be found in the generated class that implements the abstract class I defined.
I got it to work by doing this:
I am basically creating a private constructor and calling the new generated constructor.
This works, but it's not documented anywhere, so it feels like a hack, and this functionality could cease to work at any time.
Could you please document how we can add helper methods to our API classes? Is this the best way to do it?