Trying to increment app versionname for flutter , based on versions passed to git commits.

Found a solution that does the same but only for native android apps , I want to be able to increment the version in pubspec.yml after merging to main , (only increment the version name , before the plus sign)


version: 1.0.0+2

I want to do it through ci/cd on gitlab this is my script for now :

image: "cirrusci/flutter:2.8.1"
before_script:
  - flutter pub get
variables:
  ANDROID_COMPILE_SDK: "28"
  ANDROID_BUILD_TOOLS: "28.0.3"
  ANDROID_SDK_TOOLS:   "4333796"

stages:
  - test # All jobs related for testing such as Unit Test
  - build
flutter_test: # Name of the lane
  stage: test # type of stage
  script:
    - flutter test # Run Flutter test
flutter_build_android: #Job name
  stage: build # kind of job
  variables:

  before_script:
    - flutter packages get
    - flutter clean
  script:
    - flutter build apk
  artifacts:
    paths:
      - build/app/outputs/apk/release/app-release.apk

I want to add a step which tags the commit (onlyduring merge request on main) and increments the version in pubspec.yaml automatically. I've tried working with Fastlane , but can't seem to wrap my head around how exactly it works. I'd be grateful for your help.