Commit 089ccd5cb04ef094ffaa6ff39c26adb0da053a45

Authored by Key
1 parent 94342c3f

fixed: user util init

lib/app/splash_page.dart
... ... @@ -45,7 +45,11 @@ class _TransitionViewState extends State<TransitionView> {
45 45 @override
46 46 void initState() {
47 47 super.initState();
48   - SpUtil.preInit();
  48 + init();
  49 + }
  50 +
  51 + void init() async {
  52 + await SpUtil.preInit();
49 53 startTime();
50 54 }
51 55  
... ...
lib/common/core/user_util.dart
... ... @@ -9,9 +9,9 @@ import 'package:wow_english/utils/sp_util.dart';
9 9 class UserUtil {
10 10 static String token = '';
11 11  
12   - static saveUser(UserEntity user) {
  12 + static void saveUser(UserEntity user) {
13 13 token = user.token;
14   - SpUtil.getInstance().setData(SpConst.prefsKeyUserInfo, user.toString());
  14 + saveUserJson(user.toString());
15 15 }
16 16  
17 17 static UserEntity? getUser() {
... ... @@ -30,7 +30,7 @@ class UserUtil {
30 30 return null;
31 31 }
32 32  
33   - static saveUserJson(String userJson) {
  33 + static void saveUserJson(String userJson) {
34 34 SpUtil.getInstance().setData(SpConst.prefsKeyUserInfo, userJson);
35 35 }
36 36  
... ... @@ -38,12 +38,12 @@ class UserUtil {
38 38 return SpUtil.getInstance().get<String>(SpConst.prefsKeyUserInfo);
39 39 }
40 40  
41   - static clearUserSp() {
  41 + static void clearUserSp() {
42 42 token = '';
43 43 SpUtil.getInstance().remove(SpConst.prefsKeyUserInfo);
44 44 }
45 45  
46   - static logout() {
  46 + static void logout() {
47 47 clearUserSp();
48 48 Navigator.of(AppRouter.context).push(AppRouteName.login as Route<Object?>);
49 49 }
... ...
lib/pages/user/user_page.dart
1 1 import 'package:flutter/material.dart';
  2 +import 'package:flutter_bloc/flutter_bloc.dart';
  3 +import 'package:wow_english/common/blocs/cachebloc/cache_bloc.dart';
2 4 import 'package:wow_english/common/widgets/we_app_bar.dart';
3   -
  5 +import 'package:wow_english/models/user_entity.dart';
4 6  
5 7 class UserPage extends StatelessWidget {
6 8 const UserPage({super.key});
7 9  
8 10 @override
9 11 Widget build(BuildContext context) {
10   - return const Scaffold(
  12 + UserEntity? user = context.read<CacheBloc>().userEntity;
  13 + return Scaffold(
11 14 backgroundColor: Colors.white,
12 15 appBar: WEAppBar(
13   - titleText: '1',
  16 + titleText: user?.name ?? '????',
14 17 ),
15 18 body: Row(),
16 19 );
... ...