loris/lib/partials/thread.dart

104 lines
2.8 KiB
Dart
Raw Normal View History

2022-07-03 13:47:24 +00:00
import 'package:flutter/material.dart';
2022-08-28 18:55:23 +00:00
import 'package:localization/localization.dart';
import 'package:loris/partials/post.dart';
2022-08-01 08:29:43 +00:00
import '../business_logic/timeline/timeline.dart' as logic;
2022-08-14 18:02:42 +00:00
import '../global.dart' as global;
2022-07-03 13:47:24 +00:00
2022-08-28 18:55:23 +00:00
class Thread extends StatefulWidget {
2022-08-01 08:29:43 +00:00
const Thread({required this.model, Key? key}) : super(key: key);
final logic.ThreadModel model;
2022-07-03 13:47:24 +00:00
2022-08-28 18:55:23 +00:00
@override
State<Thread> createState() => _ThreadState();
}
class _ThreadState extends State<Thread> {
Set<String> contentWarnings = {};
int sensitivePosts = 0;
2022-08-28 18:55:23 +00:00
bool showSensitive = false;
2022-07-03 13:47:24 +00:00
@override
Widget build(BuildContext context) {
2022-08-28 18:55:23 +00:00
List<Widget> c = [];
for (var element in widget.model.posts) {
c.add(Post(
model: element,
hideSensitive: !showSensitive,
));
if (element.sensitive) {
sensitivePosts += 1;
contentWarnings.add(element.spoilerText);
2022-08-28 18:55:23 +00:00
}
}
2022-09-04 14:20:42 +00:00
contentWarnings.map(
(e) => e.trim(),
);
contentWarnings.removeWhere((element) => element == "");
if (sensitivePosts > 1 && c.length > 1) {
String s = "";
int i = 0;
for (var element in contentWarnings) {
2022-09-04 14:20:42 +00:00
if (i == 0 && i < contentWarnings.length - 1) {
s = "$element;";
} else if (i < contentWarnings.length - 1) {
s = "$s $element;";
} else {
s = "$s $element";
}
i++;
}
2022-08-28 18:55:23 +00:00
c.insert(
0,
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expanded(
child: SelectableText(s),
),
2022-08-28 18:55:23 +00:00
OutlinedButton.icon(
onPressed: () {
setState(() {
showSensitive = !showSensitive;
});
},
icon:
Icon(showSensitive ? Icons.visibility_off : Icons.visibility),
label: Text(showSensitive ? "hide".i18n() : "show".i18n()),
),
],
),
);
2022-08-01 08:29:43 +00:00
}
2022-07-03 13:47:24 +00:00
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
2022-07-03 20:02:57 +00:00
Padding(
padding: const EdgeInsets.all(4),
child: Container(
padding: const EdgeInsets.all(24),
2022-08-14 18:02:42 +00:00
width: (MediaQuery.of(context).size.width *
2022-08-14 20:43:36 +00:00
global.settings!.postWidth) -
2022-08-14 18:02:42 +00:00
56,
2022-08-14 20:43:36 +00:00
constraints: BoxConstraints(
maxWidth: global.settings!.maxPostWidth,
2022-08-28 10:14:49 +00:00
minWidth: 375,
2022-08-14 20:43:36 +00:00
),
2022-07-03 20:02:57 +00:00
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
border:
Border.all(color: Theme.of(context).colorScheme.secondary),
borderRadius: BorderRadius.circular(8),
),
child: Column(
2022-08-28 18:55:23 +00:00
children: c,
2022-07-03 20:02:57 +00:00
),
2022-07-03 13:47:24 +00:00
),
),
],
);
}
}