Skip to content

Commit

Permalink
✨ added the option to change reference player
Browse files Browse the repository at this point in the history
  • Loading branch information
adeeteya committed May 1, 2023
1 parent e4bb99f commit a4540d3
Show file tree
Hide file tree
Showing 6 changed files with 3,904 additions and 3,879 deletions.
20 changes: 19 additions & 1 deletion lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:tennis_serve_analysis/finals.dart';
import 'package:tennis_serve_analysis/models/serve_result.dart';
import 'package:tennis_serve_analysis/utility/classifier.dart';
import 'package:tennis_serve_analysis/utility/isolate_utils.dart';

final selectedPlayerProvider = StateProvider<int>((ref) => 0);
final selectedPlayerProvider =
StateProvider.family<ServeResult, int?>((ref, index) {
final userServeResult = ref.watch(userServeDataProvider);
if (index == null) {
if (userServeResult.isLeftHanded) {
return rafaelNadal;
} else if (userServeResult.height > 180) {
return rogerFederer;
} else {
return fabioFognini;
}
}
return availableReferencePlayers[index];
});

final userServeDataProvider =
NotifierProvider<UserServeResultNotifier, ServeResult>(
Expand All @@ -21,6 +35,10 @@ class UserServeResultNotifier extends Notifier<ServeResult> {
return ServeResult("User", 185, false);
}

void reset() {
state = ServeResult("User", state.height, state.isLeftHanded);
}

void onHeightChanged(int newHeight) {
state = state.copyWith(height: newHeight);
}
Expand Down
Loading

0 comments on commit a4540d3

Please sign in to comment.