Reputation: 121
Is there a way in Flutter to get the latest commit sha? This would be useful to displaying a version number in app.
I have tried loading it from .git/ORIG_HEAD
like so:
final commitId = await rootBundle.loadString('.git/ORIG_HEAD');
but receive an error Could not open '.git/ORIG_HEAD'
I have also investigated whether it's possible to run a command line query like git rev-parse HEAD
but this doesn't seem possible in Flutter.
Is there a package or another way of doing this?
For reference - I have done a flutter clean
and flutter pub get
and get the same result
EDIT 1:
Here is my assets
when trying to import the .git/
directory:
flutter:
assets:
- .git/ORIG_HEAD
I have also tried with just .git/
and get the same result.
Upvotes: 1
Views: 617
Reputation: 33
The .git
folder is not bundled by default. If you want to add, you need to add .git
folder under the assets
of your pubspec.yaml
as you do with an image file. Also, if you're trying this on a Flutter Desktop app; you can use the run method from dart:io
. It let you run shell commands (depending on your OS you need to trick a little bit in configuration)
Upvotes: 1