Allow passing the language to the fetch request

This allows us to use the trophy translations from the server.
This commit is contained in:
Roland Geider
2025-12-22 13:03:24 +01:00
parent 536f18805b
commit 52892db9b1
25 changed files with 202 additions and 121 deletions

View File

@@ -29,9 +29,10 @@ class DashboardTrophiesWidget extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final provider = ref.watch(trophyStateProvider.notifier);
final languageCode = Localizations.localeOf(context).languageCode;
return FutureBuilder(
future: provider.fetchUserTrophies(),
future: provider.fetchUserTrophies(language: languageCode),
builder: (context, asyncSnapshot) {
if (asyncSnapshot.connectionState != ConnectionState.done) {
return const Card(child: BoxedProgressIndicator());

View File

@@ -549,6 +549,9 @@ class _LogFormWidgetState extends ConsumerState<LogFormWidget> {
_weightController = TextEditingController();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) {
return;
}
_syncControllersWithWidget();
});
}

View File

@@ -38,7 +38,6 @@ import '../logs/muscle_groups.dart';
class WorkoutSummary extends ConsumerStatefulWidget {
final _logger = Logger('WorkoutSummary');
final PageController _controller;
WorkoutSummary(this._controller);
@@ -51,14 +50,24 @@ class _WorkoutSummaryState extends ConsumerState<WorkoutSummary> {
late Future<void> _initData;
late Routine _routine;
late List<UserTrophy> _userPrTrophies;
bool _didInit = false;
@override
void initState() {
super.initState();
_initData = _reloadRoutineData();
}
Future<void> _reloadRoutineData() async {
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (!_didInit) {
final languageCode = Localizations.localeOf(context).languageCode;
_initData = _reloadRoutineData(languageCode);
_didInit = true;
}
}
Future<void> _reloadRoutineData(String languageCode) async {
widget._logger.fine('Loading routine data');
final gymState = ref.read(gymStateProvider);
@@ -67,7 +76,7 @@ class _WorkoutSummaryState extends ConsumerState<WorkoutSummary> {
);
final trophyNotifier = ref.read(trophyStateProvider.notifier);
_userPrTrophies = await trophyNotifier.fetchUserPRTrophies();
_userPrTrophies = await trophyNotifier.fetchUserPRTrophies(language: languageCode);
}
@override
@@ -86,7 +95,9 @@ class _WorkoutSummaryState extends ConsumerState<WorkoutSummary> {
if (snapshot.connectionState == ConnectionState.waiting) {
return const BoxedProgressIndicator();
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}: ${snapshot.stackTrace}'));
widget._logger.warning(snapshot.error);
widget._logger.warning(snapshot.stackTrace);
return Center(child: Text('Error: ${snapshot.error}'));
} else if (snapshot.connectionState == ConnectionState.done) {
final apiSession = _routine.sessions.firstWhereOrNull(
(s) => s.session.date.isSameDayAs(clock.now()),

View File

@@ -29,6 +29,7 @@ class TrophiesOverview extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final notifier = ref.watch(trophyStateProvider.notifier);
final languageCode = Localizations.localeOf(context).languageCode;
// Responsive grid: determine columns based on screen width
final width = MediaQuery.widthOf(context);
@@ -44,7 +45,7 @@ class TrophiesOverview extends ConsumerWidget {
}
return FutureBuilder<List<UserTrophyProgression>>(
future: notifier.fetchTrophyProgression(),
future: notifier.fetchTrophyProgression(language: languageCode),
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Card(child: BoxedProgressIndicator());