LCOV - code coverage report
Current view: top level - lib/widgets - membersdrawer.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 51 0.0 %
Date: 2026-09-01 20:55:37 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:cwtch/l10n/app_localizations.dart';
       2             : import 'package:cwtch/models/contact.dart';
       3             : import 'package:cwtch/models/contactlist.dart';
       4             : import 'package:cwtch/models/groupmembers.dart';
       5             : import 'package:cwtch/models/profile.dart';
       6             : import 'package:cwtch/models/redaction.dart';
       7             : import 'package:cwtch/widgets/cwtchlabel.dart';
       8             : import 'package:cwtch/widgets/profileimage.dart';
       9             : import 'package:flutter/material.dart';
      10             : import 'package:provider/provider.dart';
      11             : 
      12             : import '../cwtch_icons_icons.dart';
      13             : import '../settings.dart';
      14             : import '../themes/opaque.dart';
      15             : 
      16             : class MembersDrawer extends StatefulWidget {
      17             :   BuildContext? provCon = null;
      18           0 :   MembersDrawer(this.provCon);
      19             : 
      20           0 :   @override
      21           0 :   MembersDrawerState createState() => MembersDrawerState();
      22             : }
      23             : 
      24             : class MembersDrawerState extends State<MembersDrawer> {
      25           0 :   @override
      26             :   Widget build(BuildContext context) {
      27           0 :     return Scaffold(
      28           0 :       backgroundColor: Provider.of<Settings>(context).theme.backgroundMainColor,
      29           0 :       body: Padding(
      30           0 :         padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 8.0),
      31           0 :         child: Column(mainAxisAlignment: MainAxisAlignment.start, spacing: 24.0, children: [_buildHeader(), _buildMembersList()]),
      32             :       ),
      33             :     );
      34             :   }
      35             : 
      36           0 :   Widget _buildHeader() {
      37           0 :     return Column(
      38           0 :       children: [
      39           0 :         Text(
      40           0 :           Provider.of<ContactInfoState>(widget.provCon ?? context).nickname,
      41           0 :           style: TextStyle(
      42           0 :             fontSize: Provider.of<Settings>(widget.provCon ?? context).fontScaling * 14.0,
      43             :             fontFamily: "Inter",
      44             :             fontWeight: FontWeight.bold,
      45           0 :             color: Provider.of<Settings>(widget.provCon ?? context).theme.mainTextColor,
      46             :           ),
      47             :         ),
      48           0 :         Text(Provider.of<ContactInfoState>(widget.provCon ?? context).attributes[0] ?? ""),
      49           0 :         Text("+" + Provider.of<ContactInfoState>(widget.provCon ?? context).modeLine),
      50             :       ],
      51             :     );
      52             :   }
      53             : 
      54           0 :   Widget _buildMembersList() {
      55           0 :     List<Widget> rolesLists = List<Widget>.empty(growable: true);
      56           0 :     rolesLists.addAll(_buildRolesBox("admin", AppLocalizations.of(context)!.roleAdminPlural));
      57           0 :     rolesLists.addAll(_buildRolesBox("op", AppLocalizations.of(context)!.roleOpPlural));
      58           0 :     rolesLists.addAll(_buildRolesBox("mod", AppLocalizations.of(context)!.roleModPlural));
      59           0 :     rolesLists.addAll(_buildRolesBox("voice", AppLocalizations.of(context)!.roleVoicePlural));
      60           0 :     rolesLists.addAll(_buildRolesBox("user", AppLocalizations.of(context)!.roleUserPlural));
      61             : 
      62           0 :     return Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: rolesLists, spacing: 8.0);
      63             :   }
      64             : 
      65           0 :   List<Widget> _buildRolesBox(String role, String header) {
      66           0 :     List<GroupMember> members = Provider.of<ContactInfoState>(widget.provCon ?? context).getMembersOfRole(role);
      67           0 :     List<Widget> retVal = List<Widget>.empty(growable: true);
      68           0 :     if (members.length == 0) return retVal;
      69             : 
      70           0 :     retVal.addAll(
      71           0 :       members.map((ev) {
      72           0 :         return _contactEntry(ev.onion, ev.role);
      73           0 :       }).toList(),
      74             :     );
      75             : 
      76             :     return retVal;
      77             :   }
      78             : 
      79             :   // note this method closely resembles MembershipView::_memberListEntry
      80           0 :   Widget _contactEntry(String onion, String role) {
      81           0 :     bool isMe = onion == Provider.of<ProfileInfoState>(widget.provCon ?? context).onion;
      82           0 :     var contact = Provider.of<ProfileInfoState>(widget.provCon ?? context).contactList.findContact(onion);
      83             :     if (contact == null) {
      84           0 :       contact = ContactInfoState(onion, -1, onion); //cheeky
      85             :     }
      86             :     String name = isMe
      87           0 :         ? redactedNick(context, Provider.of<ProfileInfoState>(widget.provCon ?? context).onion, Provider.of<ProfileInfoState>(widget.provCon ?? context).nickname)
      88           0 :         : redactedNick(context, contact.onion, contact.nickname);
      89             : 
      90           0 :     return Row(
      91             :       spacing: 8.0,
      92           0 :       children: [
      93             :         isMe
      94           0 :             ? ProfileImage.fromProfile(
      95           0 :                 Provider.of<Settings>(widget.provCon ?? context),
      96           0 :                 Provider.of<ProfileInfoState>(widget.provCon ?? context),
      97             :                 28.0, //diameter
      98             :               )
      99           0 :             : ProfileImage.fromContact(
     100           0 :                 Provider.of<Settings>(widget.provCon ?? context),
     101             :                 contact!,
     102             :                 28.0, //diameter
     103             :               ),
     104           0 :         GroupMember.roleIcon(role, 16.0, fgColor: Provider.of<Settings>(widget.provCon ?? context).theme.mainTextColor),
     105           0 :         Flexible(
     106           0 :           child: Text(name, overflow: TextOverflow.ellipsis, softWrap: false, textWidthBasis: TextWidthBasis.parent),
     107             :         ),
     108             :       ],
     109             :     );
     110             :   }
     111             : }

Generated by: LCOV version 1.14