modify_user_information_page.dart
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wow_english/common/core/assets_const.dart';
import 'package:wow_english/common/widgets/textfield_customer_widget.dart';
import 'package:wow_english/common/widgets/we_app_bar.dart';
import 'package:wow_english/pages/user/bloc/user_bloc.dart';
import 'package:wow_english/utils/log_util.dart';
enum ModifyUserInformationType {
avatar('头像'),
name('名字'),
age('年龄'),
gender('性别');
const ModifyUserInformationType(this.title);
final String title;
}
class ModifyUserInformationPage extends StatelessWidget {
final ModifyUserInformationType type;
const ModifyUserInformationPage({super.key, required this.type});
static push(BuildContext context, ModifyUserInformationType type) {
Navigator.of(context).push(CupertinoPageRoute(builder: (context) {
return ModifyUserInformationPage(type: type);
}));
}
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => UserBloc(),
child: Scaffold(
backgroundColor: Colors.white,
appBar: WEAppBar(
titleText: '修改${type.title}',
),
body: BlocListener<UserBloc, UserState>(
listener: (context, state) {},
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,
// 输入框 or 选择框
_buildTextFieldWidget(context),
// 占位
Expanded(
child: Container(),
),
// 按钮
GestureDetector(
onTap: () {
// 更新type类型的字段
context.read<UserBloc>().add(UserUpdate(type));
},
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),
),
),
)
],
)),
],
));
}),
),
),
);
}
Widget _buildTextFieldWidget(BuildContext context) {
if (type == ModifyUserInformationType.gender) {
return Row(
children: <Widget>[
RadioListTile(
title: const Text('男'),
value: 0,
groupValue: type,
onChanged: (value) {
Log.d('男value = $value');
},
),
RadioListTile(
title: const Text('女'),
value: 1,
groupValue: type,
onChanged: (value) {
Log.d('女value = $value');
},
),
],
);
}
var formatters = [
LengthLimitingTextInputFormatter(12),
FilteringTextInputFormatter.deny(RegExp('[ ]')),
];
var inputType = TextInputType.name;
// 当输入年龄时
if (type == ModifyUserInformationType.age) {
formatters = [
LengthLimitingTextInputFormatter(2),
FilteringTextInputFormatter.deny(RegExp('[ ]')),
];
inputType = TextInputType.number;
}
return TextFieldCustomerWidget(
height: 65.h,
width: 222.w,
bgImageName: 'Input_layer_up',
textInputType: inputType,
inputFormatters: formatters,
controller: context.read<UserBloc>().modifyTextController,
/*onChangeValue: (String value) {
bloc.add(CodeNumberChangeEvent());
},*/
);
}
}