I think, you know while creating instance of Position object in "geolocator" package , you can specify heading parameter of it. There is already ready method to calculate it:
https://pub.dev/documentation/geolocator/latest/geolocator/Geolocator/bearingBetween.html
It is scientific explanation of how heading is calculated:
Let ‘R’ be the radius of Earth,
‘L’ be the longitude,
‘θ’ be latitude,
‘β‘ be Bearing.
Denote point A and B as two different points, where ‘La’ is point A longitude and ‘θa’ is point A latitude, similarly assume for point B. Bearing would be measured from North direction i.e 0° bearing means North, 90° bearing is East, 180° bearing is measured to be South, and 270° to be West.
Formula to find Bearing, when two different points latitude, longitude is given:
Bearing from point A to B, can be calculated as,
β = atan2(X,Y),
where, X and Y are two quantities and can be calculated as:
X = cos θb * sin ∆L
Y = cos θa * sin θb – sin θa * cos θb * cos ∆L
Lets us take an example to calculate bearing between the two different points with the formula:
Kansas City: 39.099912, -94.581213
St Louis: 38.627089, -90.200203
So X and Y can be calculated as,
X = cos(38.627089) * sin(4.38101)
X = 0.05967668696
And
Y = cos(39.099912) * sin(38.627089) – sin(39.099912) * cos(38.627089) * cos(4.38101)
Y = 0.77604737571 * 0.62424902378 – 0.6306746155 * 0.78122541965 * 0.99707812506
Y = -0.00681261948
Convert θ into radians
So as, β = atan2(X,Y) = atan2(0.05967668696, -0.00681261948) = 1.684463062558 radians
This means, from Kansas City if we move in 96.51° bearing direction, we will reach St Louis.