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';
|
2022-08-06 14:50:30 +00:00
|
|
|
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-09-05 21:09:49 +00:00
|
|
|
const Thread({
|
|
|
|
required this.model,
|
|
|
|
Key? key,
|
|
|
|
this.constrained = true,
|
|
|
|
}) : super(key: key);
|
2022-08-01 08:29:43 +00:00
|
|
|
final logic.ThreadModel model;
|
2022-09-05 21:09:49 +00:00
|
|
|
final bool constrained;
|
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> {
|
2022-08-29 13:37:34 +00:00
|
|
|
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) {
|
2022-08-29 13:37:34 +00:00
|
|
|
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 == "");
|
|
|
|
|
2022-08-29 13:37:34 +00:00
|
|
|
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) {
|
2022-08-29 13:37:34 +00:00
|
|
|
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: [
|
2022-08-29 13:37:34 +00:00
|
|
|
Expanded(
|
|
|
|
child: SelectableText(s),
|
|
|
|
),
|
2022-09-05 19:29:35 +00:00
|
|
|
ElevatedButton.icon(
|
2022-08-28 18:55:23 +00:00
|
|
|
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-09-05 21:09:49 +00:00
|
|
|
if (!widget.constrained) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2022-09-11 20:29:41 +00:00
|
|
|
border: Border.all(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
width: 2,
|
|
|
|
),
|
2022-09-05 21:09:49 +00:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: c,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-03 13:47:24 +00:00
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2022-09-23 17:08:05 +00:00
|
|
|
Container(
|
|
|
|
clipBehavior: Clip.none,
|
|
|
|
foregroundDecoration: BoxDecoration(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
border: Border.all(
|
|
|
|
width: 2,
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2022-09-23 13:03:28 +00:00
|
|
|
),
|
2022-09-23 17:08:05 +00:00
|
|
|
),
|
|
|
|
width:
|
|
|
|
(MediaQuery.of(context).size.width * global.settings!.postWidth) -
|
|
|
|
56,
|
|
|
|
constraints: global.getConstraints(context),
|
|
|
|
child: Material(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
child: Column(
|
|
|
|
children: c,
|
2022-09-07 08:06:11 +00:00
|
|
|
),
|
2022-07-03 20:02:57 +00:00
|
|
|
),
|
2022-07-03 13:47:24 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|