feat: sync device timezone to backend on startup

On shell mount, reads the IANA timezone from the device via
flutter_timezone and POSTs it to PUT /api/settings as user_timezone.
Mirrors the web app's App.vue behaviour so briefing events and the
chat route use the correct local time on Android.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-26 17:24:59 -04:00
parent 9f1d2317af
commit 45294ade31
5 changed files with 102 additions and 7 deletions
+19 -7
View File
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_timezone/flutter_timezone.dart';
import 'core/constants.dart';
import 'core/exceptions.dart';
import 'core/theme.dart';
@@ -159,19 +161,29 @@ class _ShellState extends ConsumerState<_Shell> {
@override
void initState() {
super.initState();
// Silent update check — only if we haven't already checked this session.
// Skipping when status is not idle/error prevents the dialog from
// re-appearing every time the shell re-mounts (e.g. after visiting settings).
WidgetsBinding.instance.addPostFrameCallback((_) {
// Silent update check — only if we haven't already checked this session.
final repoUrl = ref.read(forgejoRepoUrlProvider);
if (repoUrl == null || repoUrl.isEmpty) return;
final status = ref.read(updateProvider).status;
if (status == UpdateStatus.idle || status == UpdateStatus.error) {
ref.read(updateProvider.notifier).check(repoUrl);
if (repoUrl != null && repoUrl.isNotEmpty) {
final status = ref.read(updateProvider).status;
if (status == UpdateStatus.idle || status == UpdateStatus.error) {
ref.read(updateProvider.notifier).check(repoUrl);
}
}
// Sync device timezone to backend so briefing and chat use local time.
_syncTimezone();
});
}
Future<void> _syncTimezone() async {
try {
final tzInfo = await FlutterTimezone.getLocalTimezone();
await ref.read(settingsApiProvider).syncTimezone(tzInfo.identifier);
} catch (_) {
// Best-effort — failure is non-critical.
}
}
int _tabIndex(String location) {
for (var i = 0; i < _tabs.length; i++) {
if (location.startsWith(_tabs[i])) return i;