198 lines
5.0 KiB
Dart
198 lines
5.0 KiB
Dart
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;
|
|
|
|
class ProfileView extends StatefulWidget {
|
|
const ProfileView({
|
|
super.key,
|
|
required this.model,
|
|
});
|
|
final AccountModel model;
|
|
|
|
@override
|
|
State<ProfileView> createState() => _ProfileViewState();
|
|
}
|
|
|
|
class _ProfileViewState extends State<ProfileView> {
|
|
Map<String, AccountModel> identities = {};
|
|
String activeIdentity = "";
|
|
|
|
void update() async {
|
|
for (var element in global.settings!.identities.keys) {
|
|
final m = await searchModel(element, widget.model.url);
|
|
if (m.values.first != null) {
|
|
setState(() {
|
|
identities.addAll({element: m.values.first!});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
activeIdentity = widget.model.identity;
|
|
identities.addAll({widget.model.identity: widget.model});
|
|
super.initState();
|
|
update();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
List<DropdownMenuItem<String>> dmenuItems = [];
|
|
identities.forEach((key, value) {
|
|
dmenuItems.add(DropdownMenuItem(
|
|
alignment: Alignment.center,
|
|
value: key,
|
|
child: Text(
|
|
key,
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
),
|
|
));
|
|
});
|
|
return SimpleDialog(
|
|
contentPadding: const EdgeInsets.all(24),
|
|
children: [
|
|
DropdownButtonHideUnderline(
|
|
child: DropdownButton(
|
|
isExpanded: false,
|
|
alignment: Alignment.center,
|
|
iconEnabledColor: Theme.of(context).colorScheme.onSurface,
|
|
value: activeIdentity,
|
|
items: dmenuItems,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
activeIdentity = value.toString();
|
|
});
|
|
},
|
|
),
|
|
),
|
|
ProfileViewDisplay(
|
|
model: identities[activeIdentity]!,
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
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.smart_toy, "user-is-bot".i18n()));
|
|
}
|
|
}
|
|
|
|
return SelectableText.rich(
|
|
TextSpan(children: c),
|
|
);
|
|
}
|
|
}
|
|
|
|
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,
|
|
),
|
|
);
|
|
}
|
|
}
|