hide cw if post is not sensitive

This commit is contained in:
zoe 2022-08-01 10:59:30 +02:00
parent 6c53fcbe30
commit e1af1295e7
1 changed files with 35 additions and 17 deletions

View File

@ -17,7 +17,9 @@ class _PostState extends State<Post> {
children: [
const DisplayName(),
PostBody(
sensitive: widget.model.sensitive,
content: widget.model.content,
spoilerText: widget.model.spoilerText,
),
postActionBar(context),
],
@ -58,8 +60,15 @@ class DisplayName extends StatelessWidget {
}
class PostBody extends StatefulWidget {
const PostBody({required this.content, Key? key}) : super(key: key);
const PostBody({
required this.sensitive,
required this.spoilerText,
required this.content,
Key? key,
}) : super(key: key);
final String content;
final String spoilerText;
final bool sensitive;
@override
State<PostBody> createState() => _PostBodyState();
@ -71,28 +80,37 @@ class _PostBodyState extends State<PostBody> {
Icon cwButtonIcon = const Icon(Icons.visibility);
@override
Widget build(BuildContext context) {
if (!widget.sensitive) {
visible = true;
}
return Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(0, 6, 0, 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.content),
OutlinedButton.icon(
onPressed: () {
setState(() {
visible = !visible;
if (visible) {
cwButtonIcon = const Icon(Icons.visibility_off);
cwButtonText = "hide".i18n();
} else {
cwButtonText = "show".i18n();
cwButtonIcon = const Icon(Icons.visibility);
}
});
},
icon: cwButtonIcon,
label: Text(cwButtonText)),
Visibility(
visible: widget.sensitive,
child: Text(widget.spoilerText),
),
Visibility(
visible: widget.sensitive,
child: OutlinedButton.icon(
onPressed: () {
setState(() {
visible = !visible;
if (visible) {
cwButtonIcon = const Icon(Icons.visibility_off);
cwButtonText = "hide".i18n();
} else {
cwButtonText = "show".i18n();
cwButtonIcon = const Icon(Icons.visibility);
}
});
},
icon: cwButtonIcon,
label: Text(cwButtonText)),
),
Visibility(
visible: visible,
child: RichText(