upgrader
upgrader copied to clipboard
Avoid exposing `version` dependency to client app since PR #513
Hello @larryaasen,
Since PR #513, the client application is required to explicitly add the version package as a dependency in order to use UpgraderAppcastStore, due to the osVersion parameter expecting a Version object.
This creates an unnecessary burden on the client, as the parsing could be handled internally within the library.
Suggested Improvement
To avoid forcing the client app to import the version package, consider handling the version parsing internally.
For example, this logic could be encapsulated inside UpgraderAppcastStore:
Future<Version> getCurrentOSVersion(String? osVersionString) async {
Version osVersion;
try {
osVersion = osVersionString?.isNotEmpty == true
? Version.parse(osVersionString!)
: Version(0, 0, 0);
} catch (e) {
osVersion = Version(0, 0, 0);
}
return osVersion;
}
Then, from the client side, we could simply pass the string:
_upgrader = Upgrader(
debugLogging: kDebugMode,
storeController: UpgraderStoreController(
onAndroid: () => UpgraderAppcastStore(
appcastURL: '$baseUrl/$languageCode/appcast/android.xml',
osVersion: osVersionString, // Just a String
),
oniOS: () => UpgraderAppcastStore(
appcastURL: '$baseUrl/$languageCode/appcast/ios.xml',
osVersion: osVersionString,
),
),
);
Benefits
- Keeps the
versiondependency internal to theupgraderpackage - Simplifies integration for consumers
- Improves encapsulation and usability
Thanks