Blame view

lib/pages/user/modify/modify_user_information_page.dart 6.84 KB
c9df43c8   Key   feat: 修改个人信息、接口
1
  import 'package:flutter/cupertino.dart';
49e626e9   Key   feat: log_util.dart
2
  import 'package:flutter/material.dart';
c9df43c8   Key   feat: 修改个人信息、接口
3
  import 'package:flutter/services.dart';
49e626e9   Key   feat: log_util.dart
4
  import 'package:flutter_bloc/flutter_bloc.dart';
c9df43c8   Key   feat: 修改个人信息、接口
5
6
  import 'package:flutter_screenutil/flutter_screenutil.dart';
  import 'package:wow_english/common/core/assets_const.dart';
e6a4e63c   Key   fixed: 修改个人信息性别
7
  import 'package:wow_english/common/core/user_util.dart';
c9df43c8   Key   feat: 修改个人信息、接口
8
  import 'package:wow_english/common/widgets/textfield_customer_widget.dart';
49e626e9   Key   feat: log_util.dart
9
10
  import 'package:wow_english/common/widgets/we_app_bar.dart';
  import 'package:wow_english/pages/user/bloc/user_bloc.dart';
23b46e8e   Key   feat: 修改个人信息性别
11
  import 'package:wow_english/utils/log_util.dart';
49e626e9   Key   feat: log_util.dart
12
13
  
  enum ModifyUserInformationType {
c9df43c8   Key   feat: 修改个人信息、接口
14
15
16
17
    avatar('头像'),
    name('名字'),
    age('年龄'),
    gender('性别');
49e626e9   Key   feat: log_util.dart
18
19
20
21
22
23
24
25
26
27
28
  
    const ModifyUserInformationType(this.title);
  
    final String title;
  }
  
  class ModifyUserInformationPage extends StatelessWidget {
    final ModifyUserInformationType type;
  
    const ModifyUserInformationPage({super.key, required this.type});
  
c9df43c8   Key   feat: 修改个人信息、接口
29
30
31
32
33
34
    static push(BuildContext context, ModifyUserInformationType type) {
      Navigator.of(context).push(CupertinoPageRoute(builder: (context) {
        return ModifyUserInformationPage(type: type);
      }));
    }
  
49e626e9   Key   feat: log_util.dart
35
36
37
38
39
40
41
    @override
    Widget build(BuildContext context) {
      return BlocProvider(
        create: (context) => UserBloc(),
        child: Scaffold(
          backgroundColor: Colors.white,
          appBar: WEAppBar(
c9df43c8   Key   feat: 修改个人信息、接口
42
43
44
            titleText: '修改${type.title}',
          ),
          body: BlocListener<UserBloc, UserState>(
23b46e8e   Key   feat: 修改个人信息性别
45
            listener: (context, state) {},
c9df43c8   Key   feat: 修改个人信息、接口
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
            child: BlocBuilder<UserBloc, UserState>(builder: (context, state) {
              //final bloc = context.read<UserBloc>();
              // 区别是什么?
              //BlocProvider.of<UserBloc>(context);
              return SingleChildScrollView(
                  child: Column(
                children: [
                  Padding(
                      padding: EdgeInsets.only(left: 65.w, right: 55.w, top: 38.h),
                      child: Row(
                        children: [
                          Text(
                            type.title,
                            style: TextStyle(
                              fontWeight: FontWeight.w700,
                              color: const Color(0xFF333333),
                              fontSize: 21.sp,
                            ),
                          ),
                          20.horizontalSpace,
23b46e8e   Key   feat: 修改个人信息性别
66
67
68
                          // 输入框 or 选择框
                          _buildTextFieldWidget(context),
                          // 占位
c9df43c8   Key   feat: 修改个人信息、接口
69
70
71
72
73
74
75
                          Expanded(
                            child: Container(),
                          ),
                          // 按钮
                          GestureDetector(
                            onTap: () {
                              // 更新type类型的字段
23b46e8e   Key   feat: 修改个人信息性别
76
                              context.read<UserBloc>().add(UserUpdate(type));
c9df43c8   Key   feat: 修改个人信息、接口
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: 90.w,
                              height: 44.h,
                              decoration: BoxDecoration(
                                image: DecorationImage(image: AssetImage(AssetsConst.bgButtonBlue), fit: BoxFit.fill),
                              ),
                              child: Text(
                                '确定',
                                style: TextStyle(fontSize: 17.sp, color: Colors.white),
                              ),
                            ),
                          )
                        ],
                      )),
e6a4e63c   Key   fixed: 修改个人信息性别
93
94
95
96
97
98
99
100
101
102
103
104
105
106
                  Stack(
                    alignment: Alignment.topRight,
                    children: [
                      Image.asset(
                        AssetsConst.bgEditUserInformation,
                        width: double.infinity,
                      ),
                      Positioned(
                        right: 125.w,
                        top: 10.h,
                        child: Image.asset(AssetsConst.bgIcSteveWrite, width: 161.w, height: 249.w),
                      ),
                    ],
                  ),
c9df43c8   Key   feat: 修改个人信息、接口
107
108
109
                ],
              ));
            }),
49e626e9   Key   feat: log_util.dart
110
111
112
113
          ),
        ),
      );
    }
23b46e8e   Key   feat: 修改个人信息性别
114
115
  
    Widget _buildTextFieldWidget(BuildContext context) {
e6a4e63c   Key   fixed: 修改个人信息性别
116
117
      var userBloc = context.read<UserBloc>();
      var user = UserUtil.getUser()!;
01e73e19   Key   暂时关闭修改个人信息
118
      userBloc.tempGender = user.gender ?? 0;
e6a4e63c   Key   fixed: 修改个人信息性别
119
      Log.d('user = $user');
23b46e8e   Key   feat: 修改个人信息性别
120
121
122
      if (type == ModifyUserInformationType.gender) {
        return Row(
          children: <Widget>[
cc3bbe3d   吴启风   feat:性别编辑页报错解决
123
            SizedBox(
e6a4e63c   Key   fixed: 修改个人信息性别
124
              width: 100.w,
cc3bbe3d   吴启风   feat:性别编辑页报错解决
125
              child: RadioListTile(
e6a4e63c   Key   fixed: 修改个人信息性别
126
127
128
129
130
131
132
133
134
                title: Text(
                  '男',
                  style: TextStyle(
                    fontWeight: FontWeight.w700,
                    color: const Color(0xFF333333),
                    fontSize: 21.sp,
                  ),
                ),
                activeColor: const Color(0xFF0E89BA),
cc3bbe3d   吴启风   feat:性别编辑页报错解决
135
                value: 0,
e6a4e63c   Key   fixed: 修改个人信息性别
136
                //selected: user.gender == 0,
01e73e19   Key   暂时关闭修改个人信息
137
                groupValue: userBloc.tempGender,
cc3bbe3d   吴启风   feat:性别编辑页报错解决
138
139
                onChanged: (value) {
                  Log.d('男value = $value');
01e73e19   Key   暂时关闭修改个人信息
140
141
142
143
                  if (value != null) {
                    userBloc.tempGender = value;
                  }
                  userBloc.add(UserUIUpdate(type));
cc3bbe3d   吴启风   feat:性别编辑页报错解决
144
145
                },
              ),
23b46e8e   Key   feat: 修改个人信息性别
146
            ),
cc3bbe3d   吴启风   feat:性别编辑页报错解决
147
            SizedBox(
e6a4e63c   Key   fixed: 修改个人信息性别
148
              width: 100.w,
01e73e19   Key   暂时关闭修改个人信息
149
              child: RadioListTile<int>(
e6a4e63c   Key   fixed: 修改个人信息性别
150
151
152
153
154
155
156
157
158
159
                //selected: user.gender == 1,
                title: Text(
                  '女',
                  style: TextStyle(
                    fontWeight: FontWeight.w700,
                    color: const Color(0xFF333333),
                    fontSize: 21.sp,
                  ),
                ),
                activeColor: const Color(0xFF0E89BA),
cc3bbe3d   吴启风   feat:性别编辑页报错解决
160
                value: 1,
01e73e19   Key   暂时关闭修改个人信息
161
162
                groupValue: userBloc.tempGender,
                onChanged: (int? value) {
cc3bbe3d   吴启风   feat:性别编辑页报错解决
163
                  Log.d('女value = $value');
01e73e19   Key   暂时关闭修改个人信息
164
165
166
167
                  if (value != null) {
                    userBloc.tempGender = value;
                  }
                  userBloc.add(UserUIUpdate(type));
cc3bbe3d   吴启风   feat:性别编辑页报错解决
168
169
                },
              ),
23b46e8e   Key   feat: 修改个人信息性别
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
            ),
          ],
        );
      }
  
      var formatters = [
        LengthLimitingTextInputFormatter(12),
        FilteringTextInputFormatter.deny(RegExp('[ ]')),
      ];
      var inputType = TextInputType.name;
      // 当输入年龄时
      if (type == ModifyUserInformationType.age) {
        formatters = [
          LengthLimitingTextInputFormatter(2),
          FilteringTextInputFormatter.deny(RegExp('[ ]')),
        ];
        inputType = TextInputType.number;
      }
e6a4e63c   Key   fixed: 修改个人信息性别
188
  
23b46e8e   Key   feat: 修改个人信息性别
189
190
191
      return TextFieldCustomerWidget(
        height: 65.h,
        width: 222.w,
e6a4e63c   Key   fixed: 修改个人信息性别
192
193
194
195
196
        textStyle: TextStyle(
          fontWeight: FontWeight.w700,
          color: const Color(0xFF333333),
          fontSize: 21.sp,
        ),
23b46e8e   Key   feat: 修改个人信息性别
197
198
199
        bgImageName: 'Input_layer_up',
        textInputType: inputType,
        inputFormatters: formatters,
e6a4e63c   Key   fixed: 修改个人信息性别
200
        controller: userBloc.modifyTextController,
23b46e8e   Key   feat: 修改个人信息性别
201
202
203
204
205
        /*onChangeValue: (String value) {
                            bloc.add(CodeNumberChangeEvent());
                          },*/
      );
    }
49e626e9   Key   feat: log_util.dart
206
  }