-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathcompose_screen.dart
More file actions
220 lines (207 loc) · 7.75 KB
/
compose_screen.dart
File metadata and controls
220 lines (207 loc) · 7.75 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:stream_feed_flutter/src/widgets/activity/activity.dart';
import 'package:stream_feed_flutter/src/widgets/buttons/reactive_elevated_button.dart';
import 'package:stream_feed_flutter/stream_feed_flutter.dart';
/// A widget to react to an activity or compose a new activity.
class ComposeScreen extends StatefulWidget {
const ComposeScreen(
{Key? key,
this.parentActivity,
this.feedGroup = 'user',
this.nameJsonKey = 'full_name',
required this.textEditingController})
: super(key: key);
final TextEditingController textEditingController;
/// The activity to reply to.
final EnrichedActivity? parentActivity;
/// The feed group that the [parentActivity] belongs to.
final String feedGroup;
/// The json key for the user's name.
final String nameJsonKey;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<EnrichedActivity?>(
'parentActivity', parentActivity))
..add(StringProperty('feedGroup', feedGroup))
..add(StringProperty('nameJsonKey', nameJsonKey));
}
@override
State<ComposeScreen> createState() => _ComposeScreenState();
}
class _ComposeScreenState extends State<ComposeScreen> {
bool get _isReply => widget.parentActivity != null;
String get _hintText =>
_isReply ? 'What\'s on your mind?' : 'Post your reply...';
InputDecoration get _lightThemeInputDecoration => InputDecoration(
filled: true,
fillColor: Colors.grey.shade300,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
hintText: _hintText,
alignLabelWithHint: true,
);
InputDecoration get _darkThemeInputDecoration => InputDecoration(
filled: true,
fillColor: Colors.grey.shade800,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.grey.shade800,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.grey.shade800,
),
),
hintText: _hintText,
alignLabelWithHint: true,
);
@override
Widget build(BuildContext context) {
final uploadController = FeedProvider.of(context).bloc.uploadController;
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).canvasColor,
iconTheme: Theme.of(context).iconTheme,
titleTextStyle: Theme.of(context).textTheme.headline6,
elevation: 0,
title: Text(_isReply ? 'Reply' : 'Post'),
actions: [
ReactiveElevatedButton(
textEditingController: widget.textEditingController,
label: _isReply ? 'Reply' : 'Post',
buttonStyle: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
),
onSend: (inputText) async {
if (inputText.isNotEmpty) {
try {
final attachments =
uploadController.getMediaUris()?.toExtraData();
_isReply
? await FeedProvider.of(context).bloc.onAddReaction(
kind: 'comment',
data: {
'text': inputText.trim(),
if (attachments != null) ...attachments,
},
activity: widget.parentActivity!,
feedGroup: widget.feedGroup,
)
: FeedProvider.of(context).bloc.onAddActivity(
feedGroup: widget.feedGroup,
verb: 'post',
object: widget.textEditingController.text,
userId:
FeedProvider.of(context).bloc.currentUser!.id,
data: attachments,
);
uploadController.clear();
Navigator.of(context).pop();
} catch (e) {
debugPrint(e.toString());
}
}
},
),
],
),
body: SingleChildScrollView(
child: Column(
children: [
if (_isReply)
ActivityWidget(
activity: widget.parentActivity!,
nameJsonKey: widget.nameJsonKey,
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Avatar(
user: User(
data: FeedProvider.of(context).bloc.currentUser?.data,
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: TextField(
controller: widget.textEditingController,
autofocus: true,
maxLines: 5,
decoration:
Theme.of(context).brightness == Brightness.light
? _lightThemeInputDecoration
: _darkThemeInputDecoration,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expanded(
child: UploadListCore(
uploadController:
FeedProvider.of(context).bloc.uploadController,
uploadsBuilder: (context, uploads) {
return SizedBox(
height: 100,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: uploads.length,
itemBuilder: (context, index) =>
FileUploadStateWidget(
fileState: uploads[index],
onRemoveUpload: uploadController.removeUpload,
onCancelUpload: uploadController.cancelUpload,
onRetryUpload: (attachment) async {
return uploadController.uploadImage(attachment);
},
),
),
);
},
),
),
IconButton(
icon: const Icon(Icons.camera_alt_outlined),
onPressed: () async {
final _picker = ImagePicker();
final image =
await _picker.pickImage(source: ImageSource.gallery);
if (image != null) {
await FeedProvider.of(context)
.bloc
.uploadController
.uploadImage(AttachmentFile(path: image.path));
} else {
// User canceled the picker
}
},
),
],
),
],
),
),
);
}
}