mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Fixed 100 characters limit in code
This commit is contained in:
@@ -95,10 +95,7 @@ class AuthProvider with ChangeNotifier {
|
||||
|
||||
// Register
|
||||
try {
|
||||
final Map<String, String> data = {
|
||||
'username': username,
|
||||
'password': password
|
||||
};
|
||||
final Map<String, String> data = {'username': username, 'password': password};
|
||||
if (email != '') {
|
||||
data['email'] = email;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
List<WeightUnit> _weightUnits = [];
|
||||
List<RepetitionUnit> _repetitionUnit = [];
|
||||
|
||||
WorkoutPlansProvider(
|
||||
AuthProvider auth, ExercisesProvider exercises, List<WorkoutPlan> entries,
|
||||
WorkoutPlansProvider(AuthProvider auth, ExercisesProvider exercises, List<WorkoutPlan> entries,
|
||||
[http.Client? client])
|
||||
: _exercises = exercises,
|
||||
_workoutPlans = entries,
|
||||
@@ -78,8 +77,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Return the default weight unit (kg)
|
||||
WeightUnit get defaultWeightUnit {
|
||||
return _weightUnits
|
||||
.firstWhere((element) => element.id == DEFAULT_WEIGHT_UNIT);
|
||||
return _weightUnits.firstWhere((element) => element.id == DEFAULT_WEIGHT_UNIT);
|
||||
}
|
||||
|
||||
List<RepetitionUnit> get repetitionUnits {
|
||||
@@ -88,8 +86,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Return the default weight unit (reps)
|
||||
RepetitionUnit get defaultRepetitionUnit {
|
||||
return _repetitionUnit
|
||||
.firstWhere((element) => element.id == DEFAULT_REPETITION_UNIT);
|
||||
return _repetitionUnit.firstWhere((element) => element.id == DEFAULT_REPETITION_UNIT);
|
||||
}
|
||||
|
||||
WorkoutPlan findById(int id) {
|
||||
@@ -144,8 +141,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Fetches all workout plan sparsely, i.e. only with the data on the plan
|
||||
/// object itself and no child attributes
|
||||
Future<void> fetchAndSetAllPlansSparse() async {
|
||||
final data =
|
||||
await fetch(makeUrl(_workoutPlansUrlPath, query: {'limit': '1000'}));
|
||||
final data = await fetch(makeUrl(_workoutPlansUrlPath, query: {'limit': '1000'}));
|
||||
for (final workoutPlanData in data['results']) {
|
||||
final plan = WorkoutPlan.fromJson(workoutPlanData);
|
||||
_workoutPlans.add(plan);
|
||||
@@ -187,15 +183,13 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
// Days
|
||||
final List<Day> days = [];
|
||||
final daysData = await fetch(
|
||||
makeUrl(_daysUrlPath, query: {'training': plan.id.toString()}));
|
||||
final daysData = await fetch(makeUrl(_daysUrlPath, query: {'training': plan.id.toString()}));
|
||||
for (final dayEntry in daysData['results']) {
|
||||
final day = Day.fromJson(dayEntry);
|
||||
|
||||
// Sets
|
||||
final List<Set> sets = [];
|
||||
final setData = await fetch(
|
||||
makeUrl(_setsUrlPath, query: {'exerciseday': day.id.toString()}));
|
||||
final setData = await fetch(makeUrl(_setsUrlPath, query: {'exerciseday': day.id.toString()}));
|
||||
for (final setEntry in setData['results']) {
|
||||
final workoutSet = Set.fromJson(setEntry);
|
||||
|
||||
@@ -203,14 +197,12 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
// Settings
|
||||
final List<Setting> settings = [];
|
||||
final settingData =
|
||||
allSettingsData['results'].where((s) => s['set'] == workoutSet.id);
|
||||
final settingData = allSettingsData['results'].where((s) => s['set'] == workoutSet.id);
|
||||
|
||||
for (final settingEntry in settingData) {
|
||||
final workoutSetting = Setting.fromJson(settingEntry);
|
||||
|
||||
workoutSetting.exercise =
|
||||
await _exercises.fetchAndSetExercise(workoutSetting.exerciseId);
|
||||
workoutSetting.exercise = await _exercises.fetchAndSetExercise(workoutSetting.exerciseId);
|
||||
workoutSetting.weightUnit = _weightUnits.firstWhere(
|
||||
(e) => e.id == workoutSetting.weightUnitId,
|
||||
);
|
||||
@@ -249,10 +241,8 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
for (final entry in logData['results']) {
|
||||
try {
|
||||
final log = Log.fromJson(entry);
|
||||
log.weightUnit =
|
||||
_weightUnits.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.repetitionUnit =
|
||||
_repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.weightUnit = _weightUnits.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.repetitionUnit = _repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.exercise = await _exercises.fetchAndSetExercise(log.exerciseId);
|
||||
plan.logs.add(log);
|
||||
} catch (e) {
|
||||
@@ -282,14 +272,12 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> editWorkout(WorkoutPlan workout) async {
|
||||
await patch(
|
||||
workout.toJson(), makeUrl(_workoutPlansUrlPath, id: workout.id));
|
||||
await patch(workout.toJson(), makeUrl(_workoutPlansUrlPath, id: workout.id));
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> deleteWorkout(int id) async {
|
||||
final existingWorkoutIndex =
|
||||
_workoutPlans.indexWhere((element) => element.id == id);
|
||||
final existingWorkoutIndex = _workoutPlans.indexWhere((element) => element.id == id);
|
||||
final existingWorkout = _workoutPlans[existingWorkoutIndex];
|
||||
_workoutPlans.removeAt(existingWorkoutIndex);
|
||||
notifyListeners();
|
||||
@@ -303,8 +291,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> fetchLogData(
|
||||
WorkoutPlan workout, Exercise exercise) async {
|
||||
Future<Map<String, dynamic>> fetchLogData(WorkoutPlan workout, Exercise exercise) async {
|
||||
final data = await fetch(
|
||||
makeUrl(
|
||||
_workoutPlansUrlPath,
|
||||
@@ -354,8 +341,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
unitData['weightUnit'].forEach(
|
||||
(e) => _weightUnits.add(WeightUnit.fromJson(e)),
|
||||
);
|
||||
dev.log(
|
||||
"Read workout units data from cache. Valid till ${unitData['expiresIn']}");
|
||||
dev.log("Read workout units data from cache. Valid till ${unitData['expiresIn']}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -367,8 +353,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
// Save the result to the cache
|
||||
final exerciseData = {
|
||||
'date': DateTime.now().toIso8601String(),
|
||||
'expiresIn':
|
||||
DateTime.now().add(Duration(days: DAYS_TO_CACHE)).toIso8601String(),
|
||||
'expiresIn': DateTime.now().add(Duration(days: DAYS_TO_CACHE)).toIso8601String(),
|
||||
'repetitionUnits': _repetitionUnit.map((e) => e.toJson()).toList(),
|
||||
'weightUnit': _weightUnits.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
@@ -513,8 +498,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
log.id = newLog.id;
|
||||
log.weightUnit = _weightUnits.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.repetitionUnit =
|
||||
_repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.repetitionUnit = _repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.exercise = await _exercises.fetchAndSetExercise(log.exerciseId);
|
||||
|
||||
final plan = findById(log.workoutPlan);
|
||||
|
||||
@@ -35,8 +35,7 @@ class ExerciseLogChart extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _workoutPlansData =
|
||||
Provider.of<WorkoutPlansProvider>(context, listen: false);
|
||||
final _workoutPlansData = Provider.of<WorkoutPlansProvider>(context, listen: false);
|
||||
final _workout = _workoutPlansData.currentPlan;
|
||||
|
||||
Future<Map<String, dynamic>> _getChartEntries(BuildContext context) async {
|
||||
@@ -45,8 +44,7 @@ class ExerciseLogChart extends StatelessWidget {
|
||||
|
||||
return FutureBuilder(
|
||||
future: _getChartEntries(context),
|
||||
builder: (context, AsyncSnapshot<Map<String, dynamic>> snapshot) =>
|
||||
SizedBox(
|
||||
builder: (context, AsyncSnapshot<Map<String, dynamic>> snapshot) => SizedBox(
|
||||
height: 150,
|
||||
child: snapshot.connectionState == ConnectionState.waiting
|
||||
? Center(child: CircularProgressIndicator())
|
||||
@@ -79,8 +77,7 @@ class _DayLogWidgetState extends State<DayLogWidget> {
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(widget._date),
|
||||
DateFormat.yMd(Localizations.localeOf(context).languageCode).format(widget._date),
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
if (widget._session != null) Text('Session data here'),
|
||||
@@ -108,32 +105,25 @@ class _DayLogWidgetState extends State<DayLogWidget> {
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(context)
|
||||
.confirmDelete(exercise.name),
|
||||
AppLocalizations.of(context).confirmDelete(exercise.name),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
MaterialLocalizations.of(context)
|
||||
.cancelButtonLabel),
|
||||
onPressed: () =>
|
||||
Navigator.of(contextDialog).pop(),
|
||||
MaterialLocalizations.of(context).cancelButtonLabel),
|
||||
onPressed: () => Navigator.of(contextDialog).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
AppLocalizations.of(context).delete,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.errorColor),
|
||||
style: TextStyle(color: Theme.of(context).errorColor),
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
widget._exerciseData[exercise]!
|
||||
.removeWhere(
|
||||
(el) => el.id == log.id);
|
||||
.removeWhere((el) => el.id == log.id);
|
||||
});
|
||||
Provider.of<WorkoutPlansProvider>(
|
||||
context,
|
||||
Provider.of<WorkoutPlansProvider>(context,
|
||||
listen: false)
|
||||
.deleteLog(
|
||||
log,
|
||||
@@ -141,12 +131,10 @@ class _DayLogWidgetState extends State<DayLogWidget> {
|
||||
|
||||
Navigator.of(contextDialog).pop();
|
||||
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context)
|
||||
.successfullyDeleted,
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user