mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-19 07:50:52 +01:00
Start Time Validator
Implemented start time validator to ensure start time is not ahead of end time in gym mode.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/models/workouts/repetition_unit.dart';
|
||||
import 'package:wger/models/workouts/weight_unit.dart';
|
||||
@@ -69,3 +70,19 @@ List<DateTime> daysInRange(DateTime first, DateTime last) {
|
||||
(index) => DateTime.utc(first.year, first.month, first.day + index),
|
||||
);
|
||||
}
|
||||
|
||||
extension TimeOfDayExtension on TimeOfDay {
|
||||
bool isAfter(TimeOfDay other) {
|
||||
if(toMinutes() > other.toMinutes()) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool isBefore(TimeOfDay other) {
|
||||
if(toMinutes() < other.toMinutes()) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
int toMinutes() {
|
||||
return ((hour*60) + minute);
|
||||
}
|
||||
}
|
||||
@@ -274,6 +274,7 @@
|
||||
"@timeEnd": {
|
||||
"description": "The end time of a workout"
|
||||
},
|
||||
"timeStartAhead": "Start time cannot be ahead of end time",
|
||||
"ingredient": "Ingredient",
|
||||
"@ingredient": {},
|
||||
"energy": "Energy",
|
||||
|
||||
@@ -27,6 +27,7 @@ import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/gym_mode.dart';
|
||||
import 'package:wger/helpers/json.dart';
|
||||
import 'package:wger/helpers/ui.dart';
|
||||
import 'package:wger/helpers/misc.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
import 'package:wger/models/http_exception.dart';
|
||||
import 'package:wger/models/workouts/day.dart';
|
||||
@@ -823,6 +824,14 @@ class _SessionPageState extends State<SessionPage> {
|
||||
onSaved: (newValue) {
|
||||
_session.timeStart = stringToTime(newValue);
|
||||
},
|
||||
validator: (_) {
|
||||
TimeOfDay startTime = stringToTime(timeStartController.text);
|
||||
TimeOfDay endTime = stringToTime(timeEndController.text);
|
||||
if(startTime.isAfter(endTime)) {
|
||||
return AppLocalizations.of(context).timeStartAhead;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
@@ -842,7 +851,7 @@ class _SessionPageState extends State<SessionPage> {
|
||||
initialTime: TimeOfDay.now(),
|
||||
);
|
||||
|
||||
timeStartController.text = timeToString(pickedTime)!;
|
||||
timeEndController.text = timeToString(pickedTime)!;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
_session.timeEnd = stringToTime(newValue);
|
||||
|
||||
Reference in New Issue
Block a user