I'm approaching Flutter and Dart development as an after job activity, and I'm testing the framework capabilities. I have an Android app that I'd like to port to flutter, and I'd like to support all platforms (mobile, desktop, and web). Data on mobile+desktop versions would be handled in a sqlite database, so it can work offline, and it will handle synchronization with a server. In the web version, since it will be served by the same server holding the backend, I'd like to replace the database with rest calls to the backend. Being a Java developer, and thinking as one, I wanted to "code by interface". I would write an interface to wrap the DAO (Data Access Objects), and provide an implementation that calls the database for mobile+desktop platform, and rest calls for the web platform. At runtime I would check the current platform, and have a "DAO-factory" instantiate the correct class. This way, my business logic wouldn't care about details. Now, in Dart there are no interfaces, so I was thinking about replacing it with a super class that defines the methods (empty ones) and the actual classes would implement that class, basically achieving the same as coding to interface. Am I in the wrong track here, or could this be a viable solution? Anyone else had to tackle the same issue?
Thanks for any suggestion.
Right now I have a basic application that access the database using the Drift package (and Riverpod for state management), and it works fine (even in the browser). It's not optimal as I'd rather use live data from the server in web version.