Skip to content

Conversion from route duration to time #6

Description

@AlysonTrizotto

Hello how are you?
I'm having difficulties in getting the time conversion of the route returned by the library that is returned by "road.duration" right.

I have done so to convert
ValueNotifier<String> tempoRota = ValueNotifier('00:00');

Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( tempoRota.value, style: TextStyle(fontSize: 30), ), ], ),

tempoRota.value = getStringToTime(road.duration);

`String getStringToTime(double valor) {
if (valor < 0) return 'Tempo inválido';

valor = valor / 60;

int flooredValue = valor.floor();
double decimalValor = valor - flooredValue;
String hourValor = getHourString(flooredValue);
String minuteString = getMinuteString(decimalValor);

print('${hourValor}:${minuteString} min');

return '${hourValor}:${minuteString} min';

}

String getMinuteString(double decimalValue) {
return '${(decimalValue / 60).toInt()}'.padLeft(2, '0');
}

String getHourString(int flooredValue) {
return '${flooredValue % 24}'.padLeft(2, '0');
}
`

However, it always gives me a value in hours, and depending on the length of the route, it doesn't give me the right travel time. So it only works for short routes. Routes that are longer in duration do not work.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions