Infrastructure SDKs
package_info_provider Free
- Tier
- Freeversion 1.1.4
- Command
archipelago generate package_info_provider- Generates
infrastructure/package_info_provider
- Generates first
- test_prereqwhen needed and missing, so there is nothing to install first
- Used by
- utilities_sdk, rating_review_sdk, feedback_sdk
Centralizes
PackageInforegistration so no two features collide on the same GetIt type. Depend on this instead of callingPackageInfo.fromPlatform()yourself. You rarely generate this directly —feedback_sdkandrating_review_sdkself-generate it as a hard dependency.
Variables
This brick has no generation-time variables.
Install
Interactive
archipelago generate package_info_providerNon-interactive (CI)
archipelago generate package_info_provider --config my_config.jsonfeedback_sdk and rating_review_sdk self-generate this brick first via SubBrickGenerator if it isn't already installed — you only need to run this yourself if some other, not-yet-migrated feature needs PackageInfo directly.
pre_gen also self-generates test_prereq if utilities/test_prereq is missing, because this package's lib/testing.dart implements its TestPrerequisite contract.
Why This Exists
feedback_impl and rating_review_impl each used to independently @preResolve-register their own PackageInfo singleton. GetIt's allowReassignment defaults to false, so a duplicate type registration throws ArgumentError: Type PackageInfo is already registered — installing both features together crashed at app boot. This brick fixes it at the root: exactly one package registers PackageInfo, and every feature that needs app metadata depends on this package instead.
Generated Package
| Package | Purpose |
|---|---|
package_info_provider | Registers PackageInfo exactly once, globally; re-exports package_info_plus |
Generated Structure
infrastructure/
└── package_info_provider/
├── lib/
│ ├── package_info_provider.dart # exports package_info_plus + injector.module.dart
│ ├── testing.dart # test-only entry point
│ └── src/
│ ├── di/
│ └── testing/ # PackageInfoProviderTestPrerequisite
└── test/testing/Public API
// Resolve the already-registered singleton directly:
final info = getIt<PackageInfo>();
info.version; // e.g. "1.2.3"
info.buildNumber;
// Or as a constructor parameter, resolved by injectable:
class MyFeature {
MyFeature({required PackageInfo packageInfo}) : _info = packageInfo;
final PackageInfo _info;
}package_info_provider.dart re-exports package:package_info_plus/package_info_plus.dart, so importing this one package is enough — no separate package_info_plus import needed.
DI & Wiring
PackageInfoProviderPackageModule's RegisterModule exposes a single @preResolve Future<PackageInfo> get packageInfo => PackageInfo.fromPlatform(); — resolved once, asynchronously, during $initGetIt, before any consumer can request it. The generated module is registered as an external module in the app's injector.dart.
Testing
PackageInfo.fromPlatform() runs inside $initGetIt (it is @preResolve), so under plain flutter test it throws a MissingPluginException before any test code runs. The package ships the fix as a TestPrerequisite and declares it in its own pubspec.yaml:
archipelago:
test_prerequisites:
- class: PackageInfoProviderTestPrerequisite
reason: >-
RegisterModule's @preResolve packageInfo getter calls
PackageInfo.fromPlatform() during $initGetIt.The composition-root harness generator reads this declaration. Until that harness ships, install it yourself before initializeInjector():
import 'package:package_info_provider/testing.dart';
setUpAll(() async {
await PackageInfoProviderTestPrerequisite().install();
await initializeInjector();
});install() seeds PackageInfo.setMockInitialValues with placeholders (appName: 'app', packageName: 'com.example.app', version: '1.0.0', buildNumber: '1'). It runs once per process: a second call does nothing, so values a test sets afterwards with PackageInfo.setMockInitialValues are kept. Import testing.dart only from test code.
Dependencies
package_info_plus ^10.2.1, test_prereq (path dependency on utilities/test_prereq). No other vendor dependencies.
Platform Setup
None — package_info_plus works out of the box on both platforms.
Limitations
- The test prerequisite has no real teardown:
uninstall()does nothing, and the mock values stay for the rest of the test process.
Changelog
Run archipelago brick info package_info_provider to see the latest published version. Enterprise customers can read the full CHANGELOG.md in the brick source repository.