Commit 795fb23f64f4c9e74ce05fd5c0b876b044768e39
1 parent
e0766888
feat:支付成功刷新用户数据
Showing
6 changed files
with
83 additions
and
43 deletions
lib/models/user_entity.dart
lib/pages/moduleSelect/view.dart
... | ... | @@ -4,6 +4,7 @@ import 'package:wow_english/common/core/app_config_helper.dart'; |
4 | 4 | import 'package:wow_english/common/extension/string_extension.dart'; |
5 | 5 | import 'package:wow_english/pages/moduleSelect/state.dart'; |
6 | 6 | import 'package:wow_english/pages/moduleSelect/widgets/BaseHomeHeaderWidget.dart'; |
7 | +import 'package:wow_english/pages/user/bloc/user_bloc.dart'; | |
7 | 8 | |
8 | 9 | import '../../common/core/user_util.dart'; |
9 | 10 | import '../../common/dialogs/show_dialog.dart'; |
... | ... | @@ -27,16 +28,18 @@ class ModuleSelectPage extends StatelessWidget { |
27 | 28 | class _HomePageView extends StatelessWidget { |
28 | 29 | @override |
29 | 30 | Widget build(BuildContext context) { |
30 | - final bloc = BlocProvider.of<ModuleSelectBloc>(context); | |
31 | - return BlocListener<ModuleSelectBloc, ModuleSelectState>( | |
32 | - listener: (context, state) {}, | |
33 | - child: _homeView(), | |
34 | - ); | |
31 | + return MultiBlocListener(listeners: [ | |
32 | + BlocListener<UserBloc, UserState>(listener: (context, state) { | |
33 | + debugPrint('WQF ModuleSelectPage BlocListener state: $state'); | |
34 | + }), | |
35 | + BlocListener<ModuleSelectBloc, ModuleSelectState>( | |
36 | + listener: (context, state) {}, | |
37 | + ), | |
38 | + ], child: _homeView()); | |
35 | 39 | } |
36 | 40 | |
37 | 41 | Widget _homeView() => BlocBuilder<ModuleSelectBloc, ModuleSelectState>( |
38 | 42 | builder: (context, state) { |
39 | - final bloc = BlocProvider.of<ModuleSelectBloc>(context); | |
40 | 43 | return Scaffold( |
41 | 44 | body: Container( |
42 | 45 | color: Colors.white, |
... | ... | @@ -79,46 +82,55 @@ class _HomePageView extends StatelessWidget { |
79 | 82 | ), |
80 | 83 | ), |
81 | 84 | Expanded( |
82 | - child: GestureDetector( | |
83 | - onTap: () { | |
84 | - //如果没登录先登录 | |
85 | - if (UserUtil.isLogined()) { | |
86 | - if (AppConfigHelper.shouldHidePay()) { | |
87 | - pushNamed(AppRouteName.games); | |
88 | - } else { | |
89 | - if (UserUtil.hasGamePermission()) { | |
85 | + child: BlocBuilder<UserBloc, UserState>( | |
86 | + builder: (context, userState) { | |
87 | + final userBloc = BlocProvider.of<UserBloc>(context); | |
88 | + debugPrint( | |
89 | + 'WQF ModuleSelectPage BlocBuilder state: $userState'); | |
90 | + return GestureDetector( | |
91 | + onTap: () { | |
92 | + //如果没登录先登录 | |
93 | + if (UserUtil.isLogined()) { | |
94 | + if (AppConfigHelper.shouldHidePay()) { | |
90 | 95 | pushNamed(AppRouteName.games); |
91 | 96 | } else { |
92 | - showTwoActionDialog( | |
93 | - '提示', '忽略', '去续费', | |
94 | - '您的课程已到期,请快快续费继续学习吧!', leftTap: () { | |
95 | - popPage(); | |
96 | - }, rightTap: () { | |
97 | - popPage(); | |
98 | - pushNamed(AppRouteName.shop); | |
99 | - }); | |
97 | + if (UserUtil.hasGamePermission()) { | |
98 | + pushNamed(AppRouteName.games); | |
99 | + } else { | |
100 | + showTwoActionDialog('提示', '忽略', '去续费', | |
101 | + '您的课程已到期,请快快续费继续学习吧!', leftTap: () { | |
102 | + popPage(); | |
103 | + }, rightTap: () { | |
104 | + popPage(); | |
105 | + pushNamed(AppRouteName.shop); | |
106 | + }); | |
107 | + } | |
100 | 108 | } |
109 | + } else { | |
110 | + pushNamed(AppRouteName.login); | |
101 | 111 | } |
102 | - } else { | |
103 | - pushNamed(AppRouteName.login); | |
104 | - } | |
105 | - }, | |
106 | - child: Column( | |
107 | - mainAxisAlignment: MainAxisAlignment.center, | |
108 | - children: [ | |
109 | - Stack( | |
110 | - alignment: AlignmentDirectional.center, | |
111 | - children: [ | |
112 | - Image.asset('bg_frame_module'.assetPng, | |
113 | - width: 162.5.w, height: 203.5.h), | |
114 | - Image.asset('pic_module_game'.assetPng, | |
115 | - width: 140.5.w, height: 172.h) | |
116 | - ]), | |
117 | - 10.verticalSpace, | |
118 | - Image.asset('label_module_game'.assetPng, | |
119 | - width: 124.w, height: 34.h), | |
120 | - ], | |
121 | - )), | |
112 | + }, | |
113 | + child: Column( | |
114 | + mainAxisAlignment: MainAxisAlignment.center, | |
115 | + children: [ | |
116 | + Stack( | |
117 | + alignment: AlignmentDirectional.center, | |
118 | + children: [ | |
119 | + Image.asset( | |
120 | + 'bg_frame_module'.assetPng, | |
121 | + width: 162.5.w, | |
122 | + height: 203.5.h), | |
123 | + Image.asset( | |
124 | + 'pic_module_game'.assetPng, | |
125 | + width: 140.5.w, | |
126 | + height: 172.h) | |
127 | + ]), | |
128 | + 10.verticalSpace, | |
129 | + Image.asset('label_module_game'.assetPng, | |
130 | + width: 124.w, height: 34.h), | |
131 | + ], | |
132 | + )); | |
133 | + }), | |
122 | 134 | ), |
123 | 135 | ], |
124 | 136 | ), | ... | ... |
lib/pages/shopping/view.dart
1 | -import 'package:cached_network_image/cached_network_image.dart'; | |
2 | 1 | import 'package:flutter/material.dart'; |
3 | 2 | import 'package:flutter_bloc/flutter_bloc.dart'; |
4 | 3 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
... | ... | @@ -8,6 +7,7 @@ import 'package:wow_english/models/product_entity.dart'; |
8 | 7 | import '../../common/core/assets_const.dart'; |
9 | 8 | import '../../common/widgets/we_app_bar.dart'; |
10 | 9 | import '../../utils/image_util.dart'; |
10 | +import '../user/bloc/user_bloc.dart'; | |
11 | 11 | import 'bloc.dart'; |
12 | 12 | import 'event.dart'; |
13 | 13 | import 'state.dart'; |
... | ... | @@ -65,9 +65,11 @@ class _ShoppingView extends StatelessWidget { |
65 | 65 | @override |
66 | 66 | Widget build(BuildContext context) { |
67 | 67 | final bloc = BlocProvider.of<ShoppingBloc>(context); |
68 | + final userBloc = BlocProvider.of<UserBloc>(context); | |
68 | 69 | return BlocListener<ShoppingBloc, ShoppingState>( |
69 | 70 | listener: (context, state) { |
70 | 71 | if (state is PaySuccessState) { |
72 | + userBloc.add(PayStateChangeEvent()); | |
71 | 73 | Navigator.pop(context); |
72 | 74 | } |
73 | 75 | }, | ... | ... |
lib/pages/user/bloc/user_bloc.dart
... | ... | @@ -12,12 +12,16 @@ part 'user_state.dart'; |
12 | 12 | class UserBloc extends Bloc<UserEvent, UserState> { |
13 | 13 | final TextEditingController modifyTextController = TextEditingController(); |
14 | 14 | int tempGender = 0; |
15 | + UserEntity? _userEntityForPay; | |
16 | + | |
17 | + UserEntity? get userEntityForPay => _userEntityForPay; | |
15 | 18 | |
16 | 19 | UserBloc() : super(UserInitial()) { |
17 | 20 | on<UserLogout>(_logout); |
18 | 21 | on<UserDelete>(_deleteAccount); |
19 | 22 | on<UserUpdate>(_updateUser); |
20 | 23 | on<UserUIUpdate>(_updateUIUser); |
24 | + on<PayStateChangeEvent>(_patStateChanged); | |
21 | 25 | } |
22 | 26 | |
23 | 27 | void _logout(UserLogout event, Emitter<UserState> emitter) async { |
... | ... | @@ -78,4 +82,17 @@ class UserBloc extends Bloc<UserEvent, UserState> { |
78 | 82 | Log.e('修改个人信息失败: $e'); |
79 | 83 | } |
80 | 84 | } |
85 | + | |
86 | + //支付状态变化 | |
87 | + void _patStateChanged(PayStateChangeEvent event, Emitter<UserState> emitter) async { | |
88 | + // 由于userInfo接口不会返回token,所以这里需要再次保存一下token | |
89 | + final token = UserUtil.getUser()?.token; | |
90 | + _userEntityForPay = await UserDao.getUserInfo(); | |
91 | + if (_userEntityForPay == null) { | |
92 | + return; | |
93 | + } | |
94 | + _userEntityForPay?.token = token; | |
95 | + UserUtil.saveUser(_userEntityForPay); | |
96 | + emitter(UserPayStateChangedState()); | |
97 | + } | |
81 | 98 | } | ... | ... |
lib/pages/user/bloc/user_event.dart