/* * This file is part of wger Workout Manager . * Copyright (C) 2020, 2021 wger Team * * wger Workout Manager is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * wger Workout Manager is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:wger/helpers/consts.dart'; import 'package:wger/models/workouts/repetition_unit.dart'; import 'package:wger/models/workouts/weight_unit.dart'; /// Returns the text representation for a single setting, used in the gym mode String repText( num? repetitions, RepetitionUnit? repetitionUnitObj, num? weight, WeightUnit? weightUnitObj, num? rir, ) { // TODO(x): how to (easily?) translate strings like the units or 'RiR' final List out = []; if (repetitions != null) { out.add(formatNum(repetitions).toString()); // The default repetition unit is 'reps', which we don't show unless there // is no weight defined so that we don't just output something like "8" but // rather "8 repetitions". If there is weight we want to output "8 x 50kg", // since the repetitions are implied. If other units are used, we always // print them if (repetitionUnitObj != null && repetitionUnitObj.id != REP_UNIT_REPETITIONS_ID || weight == 0 || weight == null) { out.add(repetitionUnitObj!.name); } } if (weight != null && weight != 0) { out.add('×'); out.add(formatNum(weight).toString()); out.add(weightUnitObj!.name); } if (rir != null && rir != '') { out.add('\n'); out.add('($rir RiR)'); } return out.join(' '); } void launchURL(String url, BuildContext context) async { final scaffoldMessenger = ScaffoldMessenger.of(context); final launched = await launchUrl(Uri.parse(url)); if (!launched) { scaffoldMessenger.showSnackBar( SnackBar(content: Text('Could not open $url.')), ); } } /// Formats a number to an integer if it's a whole number num formatNum(num value) { if (value is double && value == value.toInt()) { return value.toInt(); } return value; }