diff --git a/lib/i18n/app_en.arb b/lib/i18n/app_en.arb index 9a2cca5..4f8cffe 100644 --- a/lib/i18n/app_en.arb +++ b/lib/i18n/app_en.arb @@ -13,6 +13,8 @@ "delete": "Delete", "action": "Action", "report": "Report", + "reaction": "Reaction", + "reactVerb": "React", "post": "Post", "postVerb": "Post", "comment": "Comment", @@ -23,5 +25,7 @@ "newComment": "Leave a comment", "postIdentityNotify": "You will create this post as", "postContentPlaceholder": "What's happened?!", - "postDeleteConfirm": "Are you sure you want to delete this post? This operation cannot be revert!" + "postDeleteConfirm": "Are you sure you want to delete this post? This operation cannot be revert!", + "reactionAdded": "Your reaction has been added.", + "reactionRemoved": "Your reaction has been removed." } diff --git a/lib/i18n/app_zh.arb b/lib/i18n/app_zh.arb index 3935588..6a80f51 100644 --- a/lib/i18n/app_zh.arb +++ b/lib/i18n/app_zh.arb @@ -13,6 +13,8 @@ "delete": "删除", "action": "操作", "report": "举报", + "reaction": "反应", + "reactVerb": "作出反应", "post": "帖子", "postVerb": "发表", "comment": "评论", @@ -23,5 +25,7 @@ "newComment": "留下评论", "postIdentityNotify": "你将会以该身份发表本帖子", "postContentPlaceholder": "发生什么事了?!", - "postDeleteConfirm": "你确定要删除这篇帖子吗?这意味着这个帖子将永远被我们丢弃在硬盘海中!该操作不可被反转!" + "postDeleteConfirm": "你确定要删除这篇帖子吗?这意味着这个帖子将永远被我们丢弃在硬盘海中!该操作不可被反转!", + "reactionAdded": "你的反应已被添加。", + "reactionRemoved": "你的反应已被移除。" } \ No newline at end of file diff --git a/lib/models/reaction.dart b/lib/models/reaction.dart index 985d931..6b534e5 100644 --- a/lib/models/reaction.dart +++ b/lib/models/reaction.dart @@ -7,6 +7,7 @@ class ReactInfo { final Map reactions = { 'thumb_up': ReactInfo(icon: '👍', attitude: 1), - 'thumb_down': ReactInfo(icon: '👎', attitude: -1), + 'thumb_down': ReactInfo(icon: '👎', attitude: 2), + 'just_okay': ReactInfo(icon: '😅', attitude: 0), 'clap': ReactInfo(icon: '👏', attitude: 1), }; diff --git a/lib/widgets/posts/item.dart b/lib/widgets/posts/item.dart index 5bf5518..7310211 100644 --- a/lib/widgets/posts/item.dart +++ b/lib/widgets/posts/item.dart @@ -62,26 +62,22 @@ class _PostItemState extends State { } Widget renderReactions() { - if (reactionList != null && reactionList!.isNotEmpty) { - return Container( - height: 48, - padding: const EdgeInsets.only(top: 8, left: 4, right: 4), - child: ReactionList( - item: widget.item, - reactionList: reactionList, - onReact: (symbol, changes) { - setState(() { - if (!reactionList!.containsKey(symbol)) { - reactionList![symbol] = 0; - } - reactionList![symbol] += changes; - }); - }, - ), - ); - } else { - return Container(); - } + return Container( + height: 48, + padding: const EdgeInsets.only(top: 8, left: 4, right: 4), + child: ReactionList( + item: widget.item, + reactionList: reactionList, + onReact: (symbol, changes) { + setState(() { + if (!reactionList!.containsKey(symbol)) { + reactionList![symbol] = 0; + } + reactionList![symbol] += changes; + }); + }, + ), + ); } String getAuthorDescribe() => widget.item.author.description.isNotEmpty diff --git a/lib/widgets/posts/reaction_action.dart b/lib/widgets/posts/reaction_action.dart index 81b9cb3..3a1cba3 100644 --- a/lib/widgets/posts/reaction_action.dart +++ b/lib/widgets/posts/reaction_action.dart @@ -5,6 +5,7 @@ import 'package:provider/provider.dart'; import 'package:solian/models/reaction.dart'; import 'package:solian/providers/auth.dart'; import 'package:solian/utils/service_url.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; Future doReact( String dataset, @@ -36,19 +37,19 @@ Future doReact( if (res.statusCode == 201) { onReact(symbol, 1); ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text("Your reaction has been added onto this post."), + SnackBar( + content: Text(AppLocalizations.of(context)!.reactionAdded), ), ); } else if (res.statusCode == 204) { onReact(symbol, -1); ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text("Your reaction has been removed from this post."), + SnackBar( + content: Text(AppLocalizations.of(context)!.reactionRemoved), ), ); } else { - var message = utf8.decode(res.bodyBytes); + final message = utf8.decode(res.bodyBytes); ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text("Something went wrong... $message")), ); @@ -112,7 +113,7 @@ class _ReactionActionPopupState extends State { vertical: 12, ), child: Text( - 'Add a reaction', + AppLocalizations.of(context)!.reaction, style: Theme.of(context).textTheme.headlineSmall, ), ), diff --git a/lib/widgets/posts/reaction_list.dart b/lib/widgets/posts/reaction_list.dart index def4c41..62b6dc7 100644 --- a/lib/widgets/posts/reaction_list.dart +++ b/lib/widgets/posts/reaction_list.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:solian/models/post.dart'; import 'package:solian/models/reaction.dart'; import 'package:solian/widgets/posts/reaction_action.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class ReactionList extends StatefulWidget { final Post item; @@ -79,7 +80,7 @@ class _ReactionListState extends State { }), ActionChip( avatar: const Icon(Icons.add_reaction, color: Colors.teal), - label: const Text("React"), + label: Text(AppLocalizations.of(context)!.reactVerb), visualDensity: density, onPressed: () => viewReactMenu(context), ),