-
Notifications
You must be signed in to change notification settings - Fork 0
/
about_me_screen.dart
164 lines (151 loc) · 4.53 KB
/
about_me_screen.dart
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import 'package:elementary/elementary.dart';
import 'package:flutter/material.dart';
import 'package:profile/assets/colors/colors.dart';
import 'package:profile/assets/strings/about_me_screen_strings.dart';
import 'package:profile/assets/strings/test_keys.dart';
import 'package:profile/features/profile/domain/profile.dart';
import 'package:profile/features/profile/screens/about_me_screen/about_me_screen_widget_model.dart';
import 'package:profile/features/profile/widgets/cancel_button/cancel_button.dart';
/// Widget screen with user info screen.
class AboutMeScreen extends ElementaryWidget<AboutMeScreenWidgetModel> {
/// Create an instance [AboutMeScreen].
const AboutMeScreen({
Key? key,
WidgetModelFactory wmFactory = aboutMeScreenWidgetModelFactory,
}) : super(wmFactory, key: key);
@override
Widget build(IAboutMeScreenWidgetModel wm) {
return Scaffold(
appBar: AppBar(
title: const Text(AboutMeScreenStrings.aboutMeTitle),
actions: const [
CancelButton(),
],
),
body: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 16.0,
),
child: EntityStateNotifierBuilder<Profile>(
listenableEntityState: wm.saveEntityState,
builder: (_, __) {
return _AboutMeWidget(
focusNode: wm.focusNode,
controller: wm.controller,
buttonState: wm.buttonState,
onPressedElevatedButton: wm.updateAboutMe,
);
},
loadingBuilder: (_, __) {
return Column(
children: [
const SizedBox(height: 16.0),
const LinearProgressIndicator(),
const SizedBox(height: 16.0),
_AboutMeWidget(
controller: wm.controller,
readOnly: true,
buttonState: wm.buttonState,
),
],
);
},
),
),
);
}
}
class _AboutMeWidget extends StatelessWidget {
final FocusNode? focusNode;
final TextEditingController? controller;
final ListenableState<String> buttonState;
final VoidCallback? onPressedElevatedButton;
final bool? readOnly;
const _AboutMeWidget({
required this.buttonState,
this.focusNode,
this.controller,
this.onPressedElevatedButton,
this.readOnly,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
_AboutMeField(
focusNode: focusNode,
controller: controller,
readOnly: readOnly,
),
const SizedBox(height: 16.0),
_OkOrSaveButton(
buttonState: buttonState,
onPressedElevatedButton: onPressedElevatedButton,
),
],
);
}
}
class _AboutMeField extends StatelessWidget {
final FocusNode? focusNode;
final TextEditingController? controller;
final bool? readOnly;
const _AboutMeField({
required this.focusNode,
required this.controller,
required this.readOnly,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextFormField(
key: TestKeys.aboutMeField,
readOnly: readOnly ?? false,
focusNode: focusNode,
controller: controller,
textCapitalization: TextCapitalization.sentences,
minLines: 6,
maxLines: 12,
decoration: const InputDecoration(
hintText: AboutMeScreenStrings.fewWordsAboutYourselfHint,
hintStyle: TextStyle(
fontSize: 18.0,
color: textFieldBorderColor,
),
border: OutlineInputBorder(
borderSide: BorderSide(color: textFieldBorderColor),
),
),
);
}
}
class _OkOrSaveButton extends StatelessWidget {
final ListenableState<String> buttonState;
final VoidCallback? onPressedElevatedButton;
const _OkOrSaveButton({
required this.buttonState,
required this.onPressedElevatedButton,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return StateNotifierBuilder<String>(
listenableState: buttonState,
builder: (context, text) {
return ElevatedButton(
onPressed: onPressedElevatedButton,
child: SizedBox(
width: 100.0,
child: Center(
child: Text(text ?? AboutMeScreenStrings.okButtonTitle),
key: TestKeys.saveBtn,
),
),
);
},
);
}
}