99 lines
2.7 KiB
Dart
99 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:localization/localization.dart';
|
|
import 'package:loris/partials/post.dart';
|
|
import '../business_logic/timeline/timeline.dart' as logic;
|
|
import '../global.dart' as global;
|
|
|
|
class Thread extends StatefulWidget {
|
|
const Thread({required this.model, Key? key}) : super(key: key);
|
|
final logic.ThreadModel model;
|
|
|
|
@override
|
|
State<Thread> createState() => _ThreadState();
|
|
}
|
|
|
|
class _ThreadState extends State<Thread> {
|
|
Set<String> contentWarnings = {};
|
|
int sensitivePosts = 0;
|
|
bool showSensitive = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
if (sensitivePosts > 1 && c.length > 1) {
|
|
String s = "";
|
|
int i = 0;
|
|
for (var element in contentWarnings) {
|
|
if (i == 0) {
|
|
s = "$element;";
|
|
} else if (i < contentWarnings.length - 1) {
|
|
s = "$s $element;";
|
|
} else {
|
|
s = "$s $element";
|
|
}
|
|
i++;
|
|
}
|
|
c.insert(
|
|
0,
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
Expanded(
|
|
child: SelectableText(s),
|
|
),
|
|
OutlinedButton.icon(
|
|
onPressed: () {
|
|
setState(() {
|
|
showSensitive = !showSensitive;
|
|
});
|
|
},
|
|
icon:
|
|
Icon(showSensitive ? Icons.visibility_off : Icons.visibility),
|
|
label: Text(showSensitive ? "hide".i18n() : "show".i18n()),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(4),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(24),
|
|
width: (MediaQuery.of(context).size.width *
|
|
global.settings!.postWidth) -
|
|
56,
|
|
constraints: BoxConstraints(
|
|
maxWidth: global.settings!.maxPostWidth,
|
|
minWidth: 375,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
border:
|
|
Border.all(color: Theme.of(context).colorScheme.secondary),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Column(
|
|
children: c,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|