flutter_bin 3.0.0
flutter_bin: ^3.0.0 copied to clipboard
A pure-Dart package to retrieve metadata (version, product name, and more) from binary files on desktop platforms. Supports Windows and macOS.
flutter_bin — Binary File Metadata #
A pure-Dart package to retrieve metadata from binary files (executable files) on desktop platforms. Supports Windows and macOS, and works in both Flutter and plain Dart projects. Windows reads the PE version resource via dart:ffi; macOS parses the app bundle's Info.plist. Calls on unsupported platforms throw UnsupportedError.
Features #
- Retrieve file version information from binary files
- Extract comprehensive metadata including:
- Version
- Product name
- File description
- Legal copyright
- Original filename
- Company name
- Easy integration with file pickers
Getting Started #
Add the package to your pubspec.yaml:
dependencies:
flutter_bin: ^3.0.0
Usage #
Basic Version Retrieval #
import 'package:flutter_bin/flutter_bin.dart';
// Create an instance
final flutterBin = FlutterBin();
// Get the version information
final String? version = await flutterBin.getBinaryFileVersion('C:\\path\\to\\file.exe');
print('File version: $version');
// On macOS
final String? macVersion = await flutterBin.getBinaryFileVersion('/Applications/Example.app');
print('macOS app version: $macVersion');
Full Metadata Retrieval #
import 'package:flutter_bin/flutter_bin.dart';
// Create an instance
final flutterBin = FlutterBin();
// Get comprehensive metadata (Windows)
final metadata = await flutterBin.getBinaryFileMetadata('C:\\path\\to\\file.exe');
// Or for macOS
final macMetadata = await flutterBin.getBinaryFileMetadata('/Applications/Example.app');
// Access specific properties
print('File version: ${metadata.version}');
print('Product name: ${metadata.productName}');
print('File description: ${metadata.fileDescription}');
print('Copyright: ${metadata.legalCopyright}');
print('Original filename: ${metadata.originalFilename}');
print('Company name: ${metadata.companyName}');
With FilePicker #
import 'package:flutter_bin/flutter_bin.dart';
import 'package:file_picker/file_picker.dart';
// Create an instance
final flutterBin = FlutterBin();
// Let the user select a file
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.any,
allowMultiple: false,
);
if (result != null && result.files.single.path != null) {
final filePath = result.files.single.path!;
// Get metadata for the selected file
final metadata = await flutterBin.getBinaryFileMetadata(filePath);
print('File version: ${metadata.version}');
}
Metadata Fields #
flutter_bin extracts the following metadata from binary files:
| Field | Description | Windows Source | macOS Source |
|---|---|---|---|
| version | Semantic version (e.g., 1.2.3) | FileVersion (major.minor.build) | CFBundleShortVersionString |
| productName | The product name | ProductName | CFBundleName |
| fileDescription | Description of the file | FileDescription | CFBundleGetInfoString |
| legalCopyright | Copyright information | LegalCopyright | NSHumanReadableCopyright |
| originalFilename | Original name of the file | OriginalFilename | CFBundleExecutable |
| companyName | Company or developer name | CompanyName | Not typically available |
Platform Support #
| Platform | Status |
|---|---|
| Windows | ✅ Supported |
| macOS | ✅ Supported |
| Linux | ❌ Planned |
File Path Formats #
Windows #
Use standard Windows paths with double backslashes or forward slashes:
C:\\Program Files\\Application\\app.exe
or
C:/Program Files/Application/app.exe
macOS #
For macOS applications (.app bundles):
/Applications/Example.app
or specific binaries within the bundle:
/Applications/Example.app/Contents/MacOS/Example
Example #
The package includes a full example showcasing all features. To run the example:
cd example
flutter run
License #
This project is licensed under the MIT License - see the LICENSE file for details.