loris/lib/partials/post.dart

134 lines
3.3 KiB
Dart
Raw Normal View History

2022-07-03 13:47:24 +00:00
import 'package:flutter/material.dart';
2022-07-04 17:37:53 +00:00
import 'package:localization/localization.dart';
2022-08-01 08:29:43 +00:00
import '../business_logic/timeline/timeline.dart' as tl;
2022-07-03 13:47:24 +00:00
class Post extends StatefulWidget {
2022-08-01 08:29:43 +00:00
const Post({required this.model, Key? key}) : super(key: key);
final tl.PostModel model;
2022-07-03 13:47:24 +00:00
@override
State<Post> createState() => _PostState();
}
class _PostState extends State<Post> {
@override
Widget build(BuildContext context) {
return Column(
children: [
2022-07-03 14:56:41 +00:00
const DisplayName(),
2022-08-01 08:29:43 +00:00
PostBody(
content: widget.model.content,
),
2022-07-03 14:56:41 +00:00
postActionBar(context),
],
);
}
}
class DisplayName extends StatelessWidget {
const DisplayName({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
const Icon(
Icons.face,
size: 64,
),
Column(
2022-07-03 20:02:57 +00:00
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2022-07-03 14:56:41 +00:00
crossAxisAlignment: CrossAxisAlignment.start,
2022-07-03 13:47:24 +00:00
children: [
2022-07-03 14:56:41 +00:00
Text(
"first name display last name name",
style: Theme.of(context).textTheme.titleMedium,
2022-07-03 13:47:24 +00:00
),
2022-07-03 14:56:41 +00:00
Text(
"@alice_exampleuser@example.com",
style: Theme.of(context).textTheme.bodySmall,
2022-07-03 13:47:24 +00:00
),
],
),
],
);
}
}
2022-07-03 20:02:57 +00:00
class PostBody extends StatefulWidget {
2022-08-01 08:29:43 +00:00
const PostBody({required this.content, Key? key}) : super(key: key);
final String content;
2022-07-03 20:02:57 +00:00
@override
State<PostBody> createState() => _PostBodyState();
}
class _PostBodyState extends State<PostBody> {
bool visible = false;
2022-07-04 17:37:53 +00:00
String cwButtonText = "show".i18n();
Icon cwButtonIcon = const Icon(Icons.visibility);
2022-07-03 20:02:57 +00:00
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(0, 6, 0, 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2022-08-01 08:29:43 +00:00
Text(widget.content),
2022-07-04 17:37:53 +00:00
OutlinedButton.icon(
2022-07-03 20:02:57 +00:00
onPressed: () {
setState(() {
visible = !visible;
2022-07-04 17:37:53 +00:00
if (visible) {
cwButtonIcon = const Icon(Icons.visibility_off);
cwButtonText = "hide".i18n();
} else {
cwButtonText = "show".i18n();
cwButtonIcon = const Icon(Icons.visibility);
}
2022-07-03 20:02:57 +00:00
});
},
2022-07-04 17:37:53 +00:00
icon: cwButtonIcon,
label: Text(cwButtonText)),
2022-07-03 20:02:57 +00:00
Visibility(
visible: visible,
child: RichText(
textAlign: TextAlign.start,
text: TextSpan(
style: Theme.of(context).textTheme.bodyMedium,
2022-08-01 08:29:43 +00:00
text: widget.content),
2022-07-03 20:02:57 +00:00
),
),
],
2022-07-03 13:47:24 +00:00
),
2022-07-03 20:02:57 +00:00
);
}
2022-07-03 13:47:24 +00:00
}
Widget postActionBar(context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.reply),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.repeat),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.favorite_outline),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.more_horiz),
)
],
);
}