feat(locale): 实现 App 启动时语言和时区自动设置
- 新增系统语言/时区读取工具函数 - SessionStore 扩展支持时区存储 - 启动流程自动检测并保存系统语言/时区 - 注册时传递语言/时区到后端 - 登录后从服务器同步语言/时区
This commit is contained in:
@@ -19,10 +19,18 @@ class AuthApi {
|
||||
Future<SessionResponse> createEmailSession({
|
||||
required String email,
|
||||
required String token,
|
||||
String? language,
|
||||
String? timezone,
|
||||
}) async {
|
||||
final data = <String, dynamic>{
|
||||
'email': email,
|
||||
'token': token,
|
||||
};
|
||||
if (language != null) data['language'] = language;
|
||||
if (timezone != null) data['timezone'] = timezone;
|
||||
final json = await _apiClient.postJson(
|
||||
'/api/v1/auth/email-session',
|
||||
data: {'email': email, 'token': token},
|
||||
data: data,
|
||||
);
|
||||
return SessionResponse.fromJson(json);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ abstract class AuthRepository {
|
||||
Future<AuthUser> loginWithEmailOtp({
|
||||
required String email,
|
||||
required String otp,
|
||||
String? language,
|
||||
String? timezone,
|
||||
});
|
||||
|
||||
Future<AuthUser?> recoverSession();
|
||||
@@ -37,8 +39,15 @@ class AuthRepositoryImpl implements AuthRepository {
|
||||
Future<AuthUser> loginWithEmailOtp({
|
||||
required String email,
|
||||
required String otp,
|
||||
String? language,
|
||||
String? timezone,
|
||||
}) async {
|
||||
final session = await _authApi.createEmailSession(email: email, token: otp);
|
||||
final session = await _authApi.createEmailSession(
|
||||
email: email,
|
||||
token: otp,
|
||||
language: language,
|
||||
timezone: timezone,
|
||||
);
|
||||
await _sessionStore.saveToken(session.accessToken);
|
||||
await _sessionStore.saveRefreshToken(session.refreshToken);
|
||||
await _sessionStore.saveEmail(email);
|
||||
|
||||
@@ -50,8 +50,15 @@ class AuthBloc extends ChangeNotifier {
|
||||
Future<void> loginWithOtp({
|
||||
required String email,
|
||||
required String otp,
|
||||
String? language,
|
||||
String? timezone,
|
||||
}) async {
|
||||
final user = await _repository.loginWithEmailOtp(email: email, otp: otp);
|
||||
final user = await _repository.loginWithEmailOtp(
|
||||
email: email,
|
||||
otp: otp,
|
||||
language: language,
|
||||
timezone: timezone,
|
||||
);
|
||||
_logger.info(message: 'User logged in', extra: {'user_id': user.id});
|
||||
_state = AuthState(status: AuthStatus.authenticated, user: user);
|
||||
notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user