fixed msg.

This commit is contained in:
Livinglist
2022-02-27 19:52:42 -08:00
parent 1719036d18
commit ddb437cd60
4 changed files with 46 additions and 58 deletions

View File

@ -16,7 +16,7 @@ class EditState extends Equatable {
final Item? replyingTo;
final Item? itemBeingEdited;
bool get showReplyBox => replyingTo != null;
bool get showReplyBox => replyingTo != null || itemBeingEdited != null;
EditState copyWith({String? text}) {
return EditState(

View File

@ -31,9 +31,6 @@ class PostCubit extends Cubit<PostState> {
emit(state.copyWith(status: PostStatus.loading));
final successful = await _postRepository.edit(id: id, text: text);
// final successful =
// await Future<bool>.delayed(const Duration(seconds: 2), () => true);
if (successful) {
emit(state.copyWith(status: PostStatus.successful));
} else {

View File

@ -143,15 +143,13 @@ class _StoryScreenState extends State<StoryScreen> {
return BlocConsumer<PostCubit, PostState>(
listener: (context, postState) {
if (postState.status == PostStatus.successful) {
editCubit.onReplySubmittedSuccessfully();
final verb =
editCubit.state.replyingTo == null ? 'updated' : 'submitted';
final msg = 'Comment $verb! ${(happyFaces..shuffle()).first}';
focusNode.unfocus();
HapticFeedback.lightImpact();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Comment submitted! ${(happyFaces..shuffle()).first}',
),
backgroundColor: Colors.orange,
));
showSnackBar(content: msg);
editCubit.onReplySubmittedSuccessfully();
context.read<PostCubit>().reset();
} else if (postState.status == PostStatus.failure) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
@ -179,10 +177,12 @@ class _StoryScreenState extends State<StoryScreen> {
builder: (context, state) {
return BlocConsumer<EditCubit, EditState>(
listenWhen: (previous, current) {
return previous.replyingTo != current.replyingTo;
return previous.replyingTo != current.replyingTo ||
previous.itemBeingEdited != current.itemBeingEdited;
},
listener: (context, editState) {
if (editState.replyingTo != null) {
if (editState.replyingTo != null ||
editState.itemBeingEdited != null) {
if (editState.text == null) {
commentEditingController.clear();
} else {
@ -198,6 +198,7 @@ class _StoryScreenState extends State<StoryScreen> {
},
builder: (context, editState) {
final replyingTo = editCubit.state.replyingTo;
final editing = editCubit.state.itemBeingEdited;
return Scaffold(
extendBodyBehindAppBar: true,
resizeToAvoidBottomInset: true,
@ -507,11 +508,7 @@ class _StoryScreenState extends State<StoryScreen> {
if (cmt.deleted || cmt.dead) {
return;
}
if (cmt != replyingTo) {
commentEditingController.clear();
}
commentEditingController.clear();
editCubit.onEditTapped(cmt);
focusNode.requestFocus();
},
@ -557,6 +554,7 @@ class _StoryScreenState extends State<StoryScreen> {
child: ReplyBox(
focusNode: focusNode,
textEditingController: commentEditingController,
editing: editing,
replyingTo: replyingTo,
isLoading: postState.status == PostStatus.loading,
onSendTapped: onSendTapped,
@ -781,10 +779,7 @@ class _StoryScreenState extends State<StoryScreen> {
}).then((yesTapped) {
if (yesTapped ?? false) {
context.read<AuthBloc>().add(AuthFlag(item: item));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Comment flagged!'),
backgroundColor: Colors.orange,
));
showSnackBar(content: 'Comment flagged!');
}
});
}
@ -853,10 +848,7 @@ class _StoryScreenState extends State<StoryScreen> {
} else {
context.read<BlocklistCubit>().addToBlocklist(item.by);
}
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('User ${isBlocked ? 'unblocked' : 'blocked'}!'),
backgroundColor: Colors.orange,
));
showSnackBar(content: 'User ${isBlocked ? 'unblocked' : 'blocked'}!');
}
});
}
@ -897,12 +889,7 @@ class _StoryScreenState extends State<StoryScreen> {
listener: (context, state) {
if (state.isLoggedIn) {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Logged in successfully! $happyFace'),
backgroundColor: Colors.orange,
),
);
showSnackBar(content: 'Logged in successfully! $happyFace');
}
},
builder: (context, state) {

View File

@ -11,6 +11,7 @@ class ReplyBox extends StatefulWidget {
required this.focusNode,
required this.textEditingController,
required this.replyingTo,
required this.editing,
required this.onSendTapped,
required this.onCloseTapped,
required this.onChanged,
@ -20,6 +21,7 @@ class ReplyBox extends StatefulWidget {
final FocusNode focusNode;
final TextEditingController textEditingController;
final Item? replyingTo;
final Item? editing;
final VoidCallback onSendTapped;
final VoidCallback onCloseTapped;
final ValueChanged<String> onChanged;
@ -66,42 +68,44 @@ class _ReplyBoxState extends State<ReplyBox> {
),
child: Text(
widget.replyingTo == null
? ''
? 'Editing'
: 'Replying '
'${widget.replyingTo?.by}',
style: const TextStyle(color: Colors.grey),
),
),
const Spacer(),
if (widget.replyingTo != null && !widget.isLoading) ...[
AnimatedOpacity(
opacity: expanded ? 1 : 0,
duration: const Duration(milliseconds: 300),
child: IconButton(
key: const Key('quote'),
icon: const Icon(
FeatherIcons.code,
if (!widget.isLoading) ...[
if (widget.replyingTo != null) ...[
AnimatedOpacity(
opacity: expanded ? 1 : 0,
duration: const Duration(milliseconds: 300),
child: IconButton(
key: const Key('quote'),
icon: const Icon(
FeatherIcons.code,
color: Colors.orange,
size: 18,
),
onPressed: expanded ? showTextPopup : null,
),
),
IconButton(
key: const Key('expand'),
icon: Icon(
expanded
? FeatherIcons.minimize2
: FeatherIcons.maximize2,
color: Colors.orange,
size: 18,
),
onPressed: expanded ? showTextPopup : null,
onPressed: () {
setState(() {
expanded = !expanded;
});
},
),
),
IconButton(
key: const Key('expand'),
icon: Icon(
expanded
? FeatherIcons.minimize2
: FeatherIcons.maximize2,
color: Colors.orange,
size: 18,
),
onPressed: () {
setState(() {
expanded = !expanded;
});
},
),
],
IconButton(
key: const Key('close'),
icon: const Icon(