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