2022-09-04 18:03:24 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:localization/localization.dart';
|
|
|
|
import 'package:loris/business_logic/account/account.dart';
|
|
|
|
import 'package:loris/partials/post.dart';
|
|
|
|
import 'package:loris/partials/post_text_renderer.dart';
|
|
|
|
import 'package:loris/global.dart' as global;
|
2022-09-04 14:20:42 +00:00
|
|
|
|
2022-09-04 18:03:24 +00:00
|
|
|
class ProfileView extends StatefulWidget {
|
|
|
|
const ProfileView({
|
|
|
|
super.key,
|
|
|
|
required this.model,
|
|
|
|
});
|
|
|
|
final AccountModel model;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<ProfileView> createState() => _ProfileViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ProfileViewState extends State<ProfileView> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SimpleDialog(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
contentPadding: const EdgeInsets.all(24),
|
|
|
|
children: [
|
2022-09-04 18:35:41 +00:00
|
|
|
DropdownButton(items: [], onChanged: null),
|
|
|
|
ProfileViewDisplay(
|
|
|
|
model: widget.model,
|
2022-09-04 18:03:24 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class StatusIndicators extends StatelessWidget {
|
|
|
|
const StatusIndicators({
|
|
|
|
super.key,
|
|
|
|
required this.model,
|
|
|
|
this.relationship,
|
|
|
|
});
|
|
|
|
final AccountModel model;
|
|
|
|
final RelationshipModel? relationship;
|
|
|
|
|
|
|
|
List<InlineSpan> getTextWithIcon(IconData icon, String t) {
|
|
|
|
return [
|
|
|
|
WidgetSpan(
|
|
|
|
child: Icon(icon),
|
|
|
|
alignment: PlaceholderAlignment.middle,
|
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text: t,
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
List<InlineSpan> c = [];
|
|
|
|
|
|
|
|
if (relationship == null) {
|
|
|
|
c.add(const WidgetSpan(child: LinearProgressIndicator()));
|
|
|
|
} else {
|
|
|
|
// follow relationship
|
|
|
|
if (relationship!.followedBy && relationship!.following) {
|
|
|
|
c.addAll(getTextWithIcon(Icons.group, "you-are-mufos".i18n()));
|
|
|
|
} else if (relationship!.followedBy) {
|
|
|
|
c.addAll(getTextWithIcon(Icons.group, "they-follow-you".i18n()));
|
|
|
|
} else if (relationship!.following) {
|
|
|
|
c.addAll(getTextWithIcon(Icons.group, "you-follow-them".i18n()));
|
|
|
|
} else {
|
|
|
|
c.addAll(getTextWithIcon(
|
|
|
|
Icons.group, "you-do-not-follow-each-other".i18n()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (relationship!.requested) {
|
|
|
|
c.addAll(
|
|
|
|
getTextWithIcon(Icons.group_add, "pending-follow-request".i18n()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// account is a bot
|
|
|
|
if (model.bot != null) {
|
|
|
|
if (model.bot!) {
|
|
|
|
c.addAll(getTextWithIcon(Icons.code, "user-is-bot".i18n()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SelectableText.rich(
|
|
|
|
TextSpan(children: c),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-09-04 18:35:41 +00:00
|
|
|
|
|
|
|
class ProfileViewDisplay extends StatefulWidget {
|
|
|
|
const ProfileViewDisplay({super.key, required this.model});
|
|
|
|
final AccountModel model;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<ProfileViewDisplay> createState() => _ProfileViewDisplayState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ProfileViewDisplayState extends State<ProfileViewDisplay> {
|
|
|
|
RelationshipModel? relationship;
|
|
|
|
|
|
|
|
static const d = SizedBox(
|
|
|
|
height: 8,
|
|
|
|
);
|
|
|
|
|
|
|
|
void update() async {
|
|
|
|
final r = await getRelationship(widget.model.identity, widget.model.id);
|
|
|
|
setState(() {
|
|
|
|
relationship = r.values.first;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
List<Widget> c = [
|
|
|
|
Image.network(
|
|
|
|
width: global.getWidth(context),
|
|
|
|
fit: BoxFit.fitWidth,
|
|
|
|
widget.model.header,
|
|
|
|
errorBuilder: (context, error, stackTrace) => const SizedBox.shrink(),
|
|
|
|
),
|
|
|
|
StatusIndicators(
|
|
|
|
model: widget.model,
|
|
|
|
relationship: relationship,
|
|
|
|
),
|
|
|
|
d,
|
|
|
|
DisplayName(
|
|
|
|
account: widget.model,
|
|
|
|
clickable: false,
|
|
|
|
),
|
|
|
|
d,
|
|
|
|
PostTextRenderer(input: widget.model.note),
|
|
|
|
];
|
|
|
|
return Container(
|
|
|
|
constraints: global.getConstraints(context),
|
|
|
|
width: global.getWidth(context),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: c,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|