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 createState() => _ProfileViewState(); } class _ProfileViewState extends State { 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 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 SimpleDialog( alignment: Alignment.center, contentPadding: const EdgeInsets.all(24), children: [ Container( constraints: global.getConstraints(context), width: global.getWidth(context), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: c, ), ) ], ); } } class StatusIndicators extends StatelessWidget { const StatusIndicators({ super.key, required this.model, this.relationship, }); final AccountModel model; final RelationshipModel? relationship; List getTextWithIcon(IconData icon, String t) { return [ WidgetSpan( child: Icon(icon), alignment: PlaceholderAlignment.middle, ), TextSpan( text: t, ) ]; } @override Widget build(BuildContext context) { List 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), ); } }