解决解析 TOKEN 类型报错问题
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_riverpod/legacy.dart';
|
||||
import 'package:jwt_decoder/jwt_decoder.dart';
|
||||
@@ -49,17 +50,16 @@ class AuthViewModel extends StateNotifier<AuthState> {
|
||||
/// 解析 TOKEN,并更新状态
|
||||
Future<bool> parseTokenSetState(String token) async {
|
||||
final decoded = JwtDecoder.decode(token);
|
||||
if (decoded['data'] != null && decoded['data'] is Map<String, dynamic>) {
|
||||
try {
|
||||
final data = JwtDecodedData.fromJson(decoded['data']);
|
||||
state = state.copyWith(jwtDecodedData: data);
|
||||
} catch (error) {
|
||||
state = const AuthState(errorMessage: '认证失败,请重试');
|
||||
return false;
|
||||
}
|
||||
final rawData = decoded['data'];
|
||||
if (rawData is! Map) return false;
|
||||
try {
|
||||
final data = JwtDecodedData.fromJson(Map<String, dynamic>.from(rawData));
|
||||
state = state.copyWith(jwtDecodedData: data);
|
||||
return true;
|
||||
} catch (error) {
|
||||
debugPrint('认证失败,请重试: $error');
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// 获取赛事列表
|
||||
|
||||
Reference in New Issue
Block a user