LCOV - code coverage report
Current view: top level - lib/views - contactsview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 356 0.0 %
Date: 2024-09-24 21:50:54 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:io';
       2             : 
       3             : import 'package:cwtch/cwtch/cwtch.dart';
       4             : import 'package:cwtch/cwtch_icons_icons.dart';
       5             : import 'package:cwtch/models/appstate.dart';
       6             : import 'package:cwtch/models/contact.dart';
       7             : import 'package:cwtch/models/contactlist.dart';
       8             : import 'package:cwtch/models/profile.dart';
       9             : import 'package:cwtch/models/profilelist.dart';
      10             : import 'package:cwtch/models/search.dart';
      11             : import 'package:cwtch/views/globalsettingsview.dart';
      12             : import 'package:cwtch/views/profileserversview.dart';
      13             : import 'package:flutter/material.dart';
      14             : import 'package:cwtch/widgets/contactrow.dart';
      15             : import 'package:cwtch/widgets/profileimage.dart';
      16             : import 'package:cwtch/widgets/textfield.dart';
      17             : import 'package:flutter/services.dart';
      18             : import 'package:provider/provider.dart';
      19             : import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
      20             : import '../config.dart';
      21             : import '../main.dart';
      22             : import '../models/redaction.dart';
      23             : import '../settings.dart';
      24             : import '../themes/opaque.dart';
      25             : import 'addcontactview.dart';
      26             : import 'package:flutter_gen/gen_l10n/app_localizations.dart';
      27             : import 'package:qr_flutter/qr_flutter.dart';
      28             : 
      29             : import 'addeditprofileview.dart';
      30             : import 'messageview.dart';
      31             : 
      32             : enum ShareMenu { copyCode, qrcode }
      33             : 
      34             : enum ProfileStatusMenu { available, away, busy, appearOnline, appearOffline, allowUnknownContacts, blockUnknownContacts, enableProfile, disableProfile, editProfile }
      35             : 
      36             : class ContactsView extends StatefulWidget {
      37           0 :   const ContactsView({Key? key}) : super(key: key);
      38             : 
      39           0 :   @override
      40           0 :   _ContactsViewState createState() => _ContactsViewState();
      41             : }
      42             : 
      43             : // selectConversation can be called from anywhere to set the active conversation
      44           0 : void selectConversation(BuildContext context, int handle, int? messageIndex) {
      45             :   int? index;
      46             : 
      47             :   if (messageIndex != null) {
      48             :     // this message is loaded
      49           0 :     Provider.of<AppState>(context, listen: false).selectedSearchMessage = messageIndex;
      50           0 :     Provider.of<AppState>(context, listen: false).initialScrollIndex = messageIndex;
      51           0 :     EnvironmentConfig.debugLog("Looked up index $messageIndex");
      52             :   }
      53             : 
      54           0 :   if (handle == Provider.of<AppState>(context, listen: false).selectedConversation) {
      55             :     if (messageIndex != null) {
      56           0 :       Provider.of<ContactInfoState>(context, listen: false).messageScrollController.scrollTo(index: messageIndex, duration: Duration(milliseconds: 100));
      57             :     }
      58             :     return;
      59             :   }
      60             : 
      61             :   // requery instead of using contactinfostate directly because sometimes listview gets confused about data that resorts
      62           0 :   var unread = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(handle)!.unreadMessages;
      63           0 :   var previouslySelected = Provider.of<AppState>(context, listen: false).selectedConversation;
      64             :   if (previouslySelected != null) {
      65           0 :     Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(previouslySelected)!.unselected();
      66             :   }
      67           0 :   Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(handle)!.selected();
      68             : 
      69             :   // triggers update in Double/TripleColumnView
      70           0 :   Provider.of<ContactInfoState>(context, listen: false).hoveredIndex = -1;
      71           0 :   Provider.of<AppState>(context, listen: false).selectedConversation = handle;
      72             : 
      73             :   // if in singlepane mode, push to the stack
      74           0 :   var isLandscape = Provider.of<AppState>(context, listen: false).isLandscape(context);
      75           0 :   if (Provider.of<Settings>(context, listen: false).uiColumns(isLandscape).length == 1) _pushMessageView(context, handle);
      76             : 
      77             :   // Set last message seen time in backend
      78           0 :   Provider.of<FlwtchState>(context, listen: false)
      79           0 :       .cwtch
      80           0 :       .SetConversationAttribute(Provider.of<ProfileInfoState>(context, listen: false).onion, handle, LastMessageSeenTimeKey, DateTime.now().toUtc().toIso8601String());
      81             : }
      82             : 
      83           0 : void _pushMessageView(BuildContext context, int handle) {
      84           0 :   var profileOnion = Provider.of<ProfileInfoState>(context, listen: false).onion;
      85             : 
      86           0 :   Navigator.of(context).push(
      87           0 :     PageRouteBuilder(
      88           0 :       settings: RouteSettings(name: "messages"),
      89           0 :       pageBuilder: (builderContext, a1, a2) {
      90           0 :         var profile = Provider.of<FlwtchState>(builderContext).profs.getProfile(profileOnion)!;
      91           0 :         return MultiProvider(
      92           0 :           providers: [
      93           0 :             ChangeNotifierProvider.value(value: profile),
      94           0 :             ChangeNotifierProvider.value(value: profile.contactList.getContact(handle)!),
      95             :           ],
      96           0 :           builder: (context, child) => MessageView(),
      97             :         );
      98             :       },
      99           0 :       transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
     100           0 :       transitionDuration: Duration(milliseconds: 200),
     101             :     ),
     102             :   );
     103             : }
     104             : 
     105             : class _ContactsViewState extends State<ContactsView> {
     106             :   late TextEditingController ctrlrFilter;
     107             :   bool showSearchBar = false;
     108             :   final scaffoldKey = GlobalKey<ScaffoldMessengerState>();
     109             : 
     110           0 :   @override
     111             :   void initState() {
     112           0 :     super.initState();
     113           0 :     ctrlrFilter = new TextEditingController(text: Provider.of<ContactListState>(context, listen: false).filter);
     114             :   }
     115             : 
     116           0 :   @override
     117             :   Widget build(BuildContext context) {
     118           0 :     var enabled = Provider.of<ProfileInfoState>(context, listen: false).enabled;
     119           0 :     var appearOffline = Provider.of<ProfileInfoState>(context, listen: false).appearOffline;
     120           0 :     var settings = Provider.of<Settings>(context, listen: false);
     121           0 :     return ScaffoldMessenger(
     122           0 :         key: scaffoldKey,
     123           0 :         child: Scaffold(
     124           0 :             backgroundColor: Provider.of<Settings>(context).theme.backgroundMainColor,
     125             :             endDrawerEnableOpenDragGesture: false,
     126             :             drawerEnableOpenDragGesture: false,
     127           0 :             appBar: AppBar(
     128           0 :               leading: Stack(children: [
     129           0 :                 Align(
     130             :                     alignment: Alignment.center,
     131           0 :                     child: IconButton(
     132           0 :                       icon: Icon(Icons.arrow_back),
     133           0 :                       tooltip: MaterialLocalizations.of(context).backButtonTooltip,
     134           0 :                       onPressed: () {
     135           0 :                         Provider.of<ProfileInfoState>(context, listen: false).recountUnread();
     136           0 :                         Provider.of<AppState>(context, listen: false).selectedProfile = "";
     137           0 :                         Navigator.of(context).pop();
     138             :                       },
     139             :                     )),
     140           0 :                 Positioned(
     141             :                   bottom: 5.0,
     142             :                   right: 5.0,
     143           0 :                   child: StreamBuilder<bool>(
     144           0 :                       stream: Provider.of<AppState>(context).getUnreadProfileNotifyStream(),
     145           0 :                       builder: (BuildContext context, AsyncSnapshot<bool> unreadCountSnapshot) {
     146           0 :                         int unreadCount = Provider.of<ProfileListState>(context).generateUnreadCount(Provider.of<AppState>(context).selectedProfile ?? "");
     147             : 
     148           0 :                         return Visibility(
     149           0 :                             visible: unreadCount > 0,
     150           0 :                             child: CircleAvatar(
     151             :                               radius: 10.0,
     152           0 :                               backgroundColor: Provider.of<Settings>(context).theme.portraitProfileBadgeColor,
     153             :                               child:
     154           0 :                                   Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of<Settings>(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)),
     155             :                             ));
     156             :                       }),
     157             :                 )
     158             :               ]),
     159           0 :               title: Row(children: [
     160           0 :                 PopupMenuButton<ProfileStatusMenu>(
     161           0 :                   icon: ProfileImage(
     162           0 :                     imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment)
     163           0 :                         ? Provider.of<ProfileInfoState>(context).imagePath
     164           0 :                         : Provider.of<ProfileInfoState>(context).defaultImagePath,
     165             :                     diameter: 42,
     166           0 :                     border: Provider.of<ProfileInfoState>(context).getBorderColor(Provider.of<Settings>(context).theme),
     167             :                     badgeTextColor: Colors.red,
     168             :                     badgeColor: Colors.red,
     169             :                   ),
     170             :                   iconSize: 42,
     171           0 :                   tooltip: AppLocalizations.of(context)!.availabilityStatusTooltip,
     172           0 :                   splashRadius: Material.defaultSplashRadius / 2,
     173           0 :                   onSelected: (ProfileStatusMenu item) {
     174           0 :                     String onion = Provider.of<ProfileInfoState>(context, listen: false).onion;
     175             :                     switch (item) {
     176           0 :                       case ProfileStatusMenu.available:
     177           0 :                         Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.profile-status", "available");
     178             :                         break;
     179           0 :                       case ProfileStatusMenu.away:
     180           0 :                         Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.profile-status", "away");
     181             :                         break;
     182           0 :                       case ProfileStatusMenu.busy:
     183           0 :                         Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.profile-status", "busy");
     184             :                         break;
     185           0 :                       case ProfileStatusMenu.appearOffline:
     186           0 :                         Provider.of<ProfileInfoState>(context, listen: false).appearOffline = true;
     187           0 :                         Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
     188           0 :                         Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false);
     189             :                         break;
     190           0 :                       case ProfileStatusMenu.editProfile:
     191           0 :                         Navigator.of(context).push(
     192           0 :                           PageRouteBuilder(
     193           0 :                             pageBuilder: (bcontext, a1, a2) {
     194           0 :                               return MultiProvider(
     195           0 :                                 providers: [
     196           0 :                                   ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context, listen: false)),
     197             :                                 ],
     198           0 :                                 builder: (context, widget) => AddEditProfileView(key: Key('addprofile')),
     199             :                               );
     200             :                             },
     201           0 :                             transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
     202           0 :                             transitionDuration: Duration(milliseconds: 200),
     203             :                           ),
     204             :                         );
     205             :                         break;
     206           0 :                       case ProfileStatusMenu.appearOnline:
     207           0 :                         Provider.of<ProfileInfoState>(context, listen: false).appearOffline = false;
     208             :                         // we only need to toggle all connections on here..
     209           0 :                         Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, true, true, true);
     210             :                         break;
     211           0 :                       case ProfileStatusMenu.allowUnknownContacts:
     212           0 :                         settings.blockUnknownConnections = false;
     213           0 :                         saveSettings(context);
     214             :                         break;
     215           0 :                       case ProfileStatusMenu.blockUnknownContacts:
     216           0 :                         settings.blockUnknownConnections = true;
     217           0 :                         saveSettings(context);
     218             :                         break;
     219           0 :                       case ProfileStatusMenu.enableProfile:
     220           0 :                         Provider.of<ProfileInfoState>(context, listen: false).enabled = true;
     221           0 :                         if (Provider.of<ProfileInfoState>(context, listen: false).appearOffline) {
     222           0 :                           Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false);
     223             :                         } else {
     224           0 :                           Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, true, true, true);
     225             :                         }
     226             :                         break;
     227           0 :                       case ProfileStatusMenu.disableProfile:
     228           0 :                         Provider.of<ProfileInfoState>(context, listen: false).enabled = false;
     229           0 :                         Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
     230             :                         break;
     231             :                     }
     232             :                   },
     233           0 :                   itemBuilder: (BuildContext context) => <PopupMenuEntry<ProfileStatusMenu>>[
     234           0 :                     PopupMenuItem<ProfileStatusMenu>(
     235             :                       value: ProfileStatusMenu.available,
     236             :                       enabled: enabled,
     237           0 :                       child: Row(children: [
     238           0 :                         Icon(
     239             :                           CwtchIcons.account_circle_24px,
     240             :                           color: Colors.white,
     241             :                         ),
     242           0 :                         Expanded(
     243           0 :                             child: Text(AppLocalizations.of(context)!.availabilityStatusAvailable,
     244           0 :                                 textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)))
     245             :                       ]),
     246             :                     ),
     247           0 :                     PopupMenuItem<ProfileStatusMenu>(
     248             :                       value: ProfileStatusMenu.away,
     249             :                       enabled: enabled,
     250           0 :                       child: Row(children: [
     251           0 :                         Icon(
     252             :                           CwtchIcons.account_circle_24px,
     253             :                           color: Colors.yellowAccent,
     254             :                         ),
     255           0 :                         Expanded(
     256           0 :                             child: Text(AppLocalizations.of(context)!.availabilityStatusAway,
     257           0 :                                 textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)))
     258             :                       ]),
     259             :                     ),
     260           0 :                     PopupMenuItem<ProfileStatusMenu>(
     261             :                       value: ProfileStatusMenu.busy,
     262             :                       enabled: enabled,
     263           0 :                       child: Row(children: [
     264           0 :                         Icon(
     265             :                           CwtchIcons.account_circle_24px,
     266             :                           color: Colors.redAccent,
     267             :                         ),
     268           0 :                         Expanded(
     269           0 :                             child: Text(AppLocalizations.of(context)!.availabilityStatusBusy,
     270           0 :                                 textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)))
     271             :                       ]),
     272             :                     ),
     273           0 :                     PopupMenuDivider(),
     274           0 :                     PopupMenuItem<ProfileStatusMenu>(
     275             :                       value: ProfileStatusMenu.appearOffline,
     276             :                       enabled: enabled && !appearOffline,
     277           0 :                       child: Row(children: [
     278           0 :                         Icon(CwtchIcons.disconnect_from_contact),
     279           0 :                         Expanded(
     280           0 :                             child: Text(AppLocalizations.of(context)!.profileAppearOffline,
     281           0 :                                 textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)))
     282             :                       ]),
     283             :                     ),
     284           0 :                     PopupMenuItem<ProfileStatusMenu>(
     285             :                       value: ProfileStatusMenu.appearOnline,
     286             :                       enabled: enabled && appearOffline,
     287           0 :                       child: Row(children: [
     288           0 :                         Icon(CwtchIcons.disconnect_from_contact),
     289           0 :                         Expanded(
     290           0 :                             child: Text(AppLocalizations.of(context)!.profileAppearOnline,
     291           0 :                                 textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)))
     292             :                       ]),
     293             :                     ),
     294           0 :                     PopupMenuDivider(),
     295           0 :                     PopupMenuItem<ProfileStatusMenu>(
     296           0 :                       value: !settings.blockUnknownConnections ? ProfileStatusMenu.blockUnknownContacts : ProfileStatusMenu.allowUnknownContacts,
     297           0 :                       child: Row(children: [
     298           0 :                         Icon(
     299             :                           CwtchIcons.block_unknown,
     300           0 :                           color: settings.theme.mainTextColor,
     301             :                         ),
     302           0 :                         Expanded(
     303           0 :                             child: Text((settings.blockUnknownConnections ? AppLocalizations.of(context)!.profileAllowUnknownContacts : AppLocalizations.of(context)!.profileBlockUnknownContacts),
     304           0 :                                 textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)))
     305             :                       ]),
     306             :                     ),
     307           0 :                     PopupMenuDivider(),
     308           0 :                     PopupMenuItem<ProfileStatusMenu>(
     309             :                       value: enabled ? ProfileStatusMenu.disableProfile : ProfileStatusMenu.enableProfile,
     310           0 :                       child: Row(children: [
     311           0 :                         Icon(CwtchIcons.favorite_24dp, color: settings.theme.mainTextColor),
     312           0 :                         Expanded(
     313           0 :                             child: Text((enabled ? AppLocalizations.of(context)!.profileDisableProfile : AppLocalizations.of(context)!.profileEnableProfile),
     314           0 :                                 textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)))
     315             :                       ]),
     316             :                     ),
     317           0 :                     PopupMenuItem<ProfileStatusMenu>(
     318             :                       value: ProfileStatusMenu.editProfile,
     319             :                       enabled: true,
     320           0 :                       child: Row(children: [
     321           0 :                         Icon(
     322             :                           CwtchIcons.edit_24px,
     323           0 :                           color: settings.theme.mainTextColor,
     324             :                         ),
     325           0 :                         Expanded(
     326           0 :                             child: Text(AppLocalizations.of(context)!.editProfile, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)))
     327             :                       ]),
     328             :                     ),
     329             :                   ],
     330             :                 ),
     331           0 :                 SizedBox(
     332             :                   width: 10,
     333             :                 ),
     334           0 :                 Expanded(
     335           0 :                     child: Text(
     336             :                         "%1 ยป %2"
     337           0 :                             .replaceAll("%1", redactedNick(context, Provider.of<ProfileInfoState>(context).onion, Provider.of<ProfileInfoState>(context).nickname))
     338           0 :                             .replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts),
     339             :                         overflow: TextOverflow.ellipsis,
     340           0 :                         style: TextStyle(
     341           0 :                             color: Provider.of<Settings>(context).current().mainTextColor,
     342             :                             fontFamily: "Inter",
     343             :                             fontWeight: FontWeight.bold,
     344           0 :                             fontSize: 14.0 * Provider.of<Settings>(context).fontScaling))),
     345             :               ]),
     346           0 :               actions: getActions(context),
     347             :             ),
     348           0 :             floatingActionButton: FloatingActionButton(
     349           0 :               onPressed: _modalAddImportChoice,
     350           0 :               tooltip: AppLocalizations.of(context)!.tooltipAddContact,
     351           0 :               child: Icon(
     352             :                 CwtchIcons.person_add_alt_1_24px,
     353           0 :                 color: Provider.of<Settings>(context).theme.defaultButtonTextColor,
     354             :               ),
     355             :             ),
     356           0 :             body: showSearchBar || Provider.of<ContactListState>(context).isFiltered ? _buildFilterable() : _buildContactList()));
     357             :   }
     358             : 
     359           0 :   List<Widget> getActions(context) {
     360           0 :     var actions = List<Widget>.empty(growable: true);
     361           0 :     if (Provider.of<Settings>(context).blockUnknownConnections) {
     362           0 :       actions.add(Tooltip(message: AppLocalizations.of(context)!.blockUnknownConnectionsEnabledDescription, child: Icon(CwtchIcons.block_unknown)));
     363             :     }
     364             : 
     365           0 :     if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(QRCodeExperiment)) {
     366           0 :       actions.add(PopupMenuButton<ShareMenu>(
     367           0 :         icon: Icon(CwtchIcons.address_copy),
     368           0 :         tooltip: AppLocalizations.of(context)!.shareProfileMenuTooltop,
     369           0 :         splashRadius: Material.defaultSplashRadius / 2,
     370           0 :         onSelected: (ShareMenu item) {
     371             :           switch (item) {
     372           0 :             case ShareMenu.copyCode:
     373             :               {
     374           0 :                 Clipboard.setData(new ClipboardData(text: Provider.of<ProfileInfoState>(context, listen: false).onion));
     375           0 :                 final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedToClipboardNotification));
     376           0 :                 scaffoldKey.currentState?.showSnackBar(snackBar);
     377             :               }
     378             :               break;
     379           0 :             case ShareMenu.qrcode:
     380             :               {
     381           0 :                 _showQRCode("cwtch:" + Provider.of<ProfileInfoState>(context, listen: false).onion);
     382             :               }
     383             :               break;
     384             :           }
     385             :         },
     386           0 :         itemBuilder: (BuildContext context) => <PopupMenuEntry<ShareMenu>>[
     387           0 :           PopupMenuItem<ShareMenu>(
     388             :             value: ShareMenu.copyCode,
     389           0 :             child: Text(AppLocalizations.of(context)!.copyAddress, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
     390             :           ),
     391           0 :           PopupMenuItem<ShareMenu>(
     392             :             value: ShareMenu.qrcode,
     393           0 :             child: Text(AppLocalizations.of(context)!.shareMenuQRCode, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
     394             :           ),
     395             :         ],
     396             :       ));
     397             :     } else {
     398           0 :       actions.add(IconButton(
     399           0 :           icon: Icon(CwtchIcons.address_copy),
     400           0 :           tooltip: AppLocalizations.of(context)!.copyAddress,
     401           0 :           splashRadius: Material.defaultSplashRadius / 2,
     402           0 :           onPressed: () {
     403           0 :             Clipboard.setData(new ClipboardData(text: Provider.of<ProfileInfoState>(context, listen: false).onion));
     404           0 :             final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedToClipboardNotification));
     405           0 :             scaffoldKey.currentState?.showSnackBar(snackBar);
     406             :           }));
     407             :     }
     408             : 
     409             :     // Manage known Servers
     410           0 :     if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment) || Provider.of<Settings>(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) {
     411           0 :       actions.add(IconButton(
     412           0 :           icon: Icon(CwtchIcons.dns_24px),
     413           0 :           tooltip: AppLocalizations.of(context)!.manageKnownServersButton,
     414           0 :           splashRadius: Material.defaultSplashRadius / 2,
     415           0 :           onPressed: () {
     416           0 :             _pushServers();
     417             :           }));
     418             :     }
     419             : 
     420             :     // Search contacts
     421           0 :     actions.add(IconButton(
     422             :         // need both conditions for displaying initial empty textfield and also allowing filters to be cleared if this widget gets lost/reset
     423           0 :         icon: Icon(showSearchBar || Provider.of<ContactListState>(context).isFiltered ? Icons.search_off : Icons.search),
     424           0 :         splashRadius: Material.defaultSplashRadius / 2,
     425           0 :         onPressed: () {
     426           0 :           Provider.of<ContactListState>(context, listen: false).filter = "";
     427           0 :           setState(() {
     428           0 :             showSearchBar = !showSearchBar;
     429             :           });
     430             :         }));
     431             :     return actions;
     432             :   }
     433             : 
     434           0 :   Widget _buildFilterable() {
     435           0 :     Widget txtfield = CwtchTextField(
     436           0 :       controller: ctrlrFilter,
     437           0 :       hintText: AppLocalizations.of(context)!.search,
     438           0 :       onChanged: (newVal) {
     439           0 :         String profileHandle = Provider.of<ProfileInfoState>(context, listen: false).onion;
     440           0 :         Provider.of<FlwtchState>(context, listen: false).cwtch.SearchConversations(profileHandle, newVal).then((value) {
     441           0 :           Provider.of<ProfileInfoState>(context, listen: false).newSearch(value);
     442             :         });
     443           0 :         Provider.of<ContactListState>(context, listen: false).filter = newVal;
     444             :       },
     445             :     );
     446           0 :     return Column(children: [Padding(padding: EdgeInsets.all(8), child: txtfield), Expanded(child: _buildContactList())]);
     447             :   }
     448             : 
     449           0 :   Widget _buildContactList() {
     450           0 :     var tilesSearchResult = Provider.of<ContactListState>(context).filteredList().map((ContactInfoState contact) {
     451           0 :       return MultiProvider(
     452           0 :         providers: [
     453           0 :           ChangeNotifierProvider.value(value: contact),
     454           0 :           ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).serverList),
     455             :         ],
     456           0 :         builder: (context, child) => ContactRow(),
     457             :       );
     458             :     });
     459             : 
     460             :     var initialScroll =
     461           0 :         Provider.of<ProfileInfoState>(context, listen: false).contactList.filteredList().indexWhere((element) => element.identifier == Provider.of<AppState>(context).selectedConversation);
     462           0 :     if (initialScroll < 0) {
     463             :       initialScroll = 0;
     464             :     }
     465             : 
     466           0 :     if (showSearchBar) {
     467           0 :       List<SearchResult> searchResults = Provider.of<ProfileInfoState>(context).activeSearchResults;
     468           0 :       tilesSearchResult = searchResults.map((SearchResult searchResult) {
     469           0 :         return MultiProvider(
     470           0 :           providers: [
     471           0 :             ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).contactList.getContact(searchResult.conversationIdentifier)),
     472           0 :             ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).serverList),
     473             :           ],
     474           0 :           builder: (context, child) => ContactRow(messageIndex: searchResult.messageIndex),
     475             :         );
     476             :       });
     477             :     } else {}
     478             : 
     479           0 :     var contactList = ScrollablePositionedList.separated(
     480           0 :       itemScrollController: Provider.of<ProfileInfoState>(context).contactListScrollController,
     481           0 :       itemCount: tilesSearchResult.length,
     482             :       initialScrollIndex: initialScroll,
     483             :       shrinkWrap: true,
     484           0 :       physics: BouncingScrollPhysics(),
     485           0 :       semanticChildCount: tilesSearchResult.length,
     486           0 :       itemBuilder: (context, index) {
     487           0 :         if (tilesSearchResult.length > index) {
     488           0 :           return tilesSearchResult.elementAt(index);
     489             :         }
     490           0 :         return Container();
     491             :       },
     492           0 :       separatorBuilder: (BuildContext context, int index) {
     493           0 :         return Divider(height: 1);
     494             :       },
     495             :     );
     496             : 
     497             :     return contactList;
     498             :   }
     499             : 
     500           0 :   void _pushAddContact(bool newGroup) {
     501             :     // close modal
     502           0 :     Navigator.popUntil(context, (route) => route.settings.name == "conversations");
     503             : 
     504           0 :     Navigator.of(context).push(
     505           0 :       PageRouteBuilder(
     506           0 :         settings: RouteSettings(name: "addcontact"),
     507           0 :         pageBuilder: (builderContext, a1, a2) {
     508           0 :           return MultiProvider(
     509           0 :             providers: [
     510           0 :               ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context)),
     511             :             ],
     512           0 :             child: AddContactView(newGroup: newGroup),
     513             :           );
     514             :         },
     515           0 :         transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
     516           0 :         transitionDuration: Duration(milliseconds: 200),
     517             :       ),
     518             :     );
     519             :   }
     520             : 
     521           0 :   void _pushServers() {
     522           0 :     var profileInfoState = Provider.of<ProfileInfoState>(context, listen: false);
     523             : 
     524           0 :     Navigator.of(context).push(
     525           0 :       PageRouteBuilder(
     526           0 :         settings: RouteSettings(name: "profileremoteservers"),
     527           0 :         pageBuilder: (bcontext, a1, a2) {
     528           0 :           return MultiProvider(
     529           0 :             providers: [ChangeNotifierProvider.value(value: profileInfoState), Provider.value(value: Provider.of<FlwtchState>(context))],
     530           0 :             child: ProfileServersView(),
     531             :           );
     532             :         },
     533           0 :         transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
     534           0 :         transitionDuration: Duration(milliseconds: 200),
     535             :       ),
     536             :     );
     537             :   }
     538             : 
     539           0 :   void _modalAddImportChoice() {
     540           0 :     bool groupsEnabled = Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment);
     541             : 
     542           0 :     showModalBottomSheet<void>(
     543           0 :         context: context,
     544             :         isScrollControlled: true,
     545           0 :         builder: (BuildContext context) {
     546           0 :           return Padding(
     547           0 :               padding: MediaQuery.of(context).viewInsets,
     548           0 :               child: RepaintBoundary(
     549           0 :                   child: Container(
     550           0 :                 height: Platform.isAndroid ? 250 : 200, // bespoke value courtesy of the [TextField] docs
     551           0 :                 child: Center(
     552           0 :                     child: Padding(
     553           0 :                         padding: EdgeInsets.all(2.0),
     554           0 :                         child: Column(
     555             :                           mainAxisAlignment: MainAxisAlignment.center,
     556             :                           crossAxisAlignment: CrossAxisAlignment.center,
     557             :                           mainAxisSize: MainAxisSize.max,
     558           0 :                           children: <Widget>[
     559           0 :                             SizedBox(
     560             :                               height: 20,
     561             :                             ),
     562           0 :                             Expanded(
     563           0 :                                 child: Tooltip(
     564           0 :                                     message: AppLocalizations.of(context)!.tooltipAddContact,
     565           0 :                                     child: ElevatedButton(
     566           0 :                                       style: ElevatedButton.styleFrom(
     567           0 :                                         minimumSize: Size.fromWidth(399),
     568           0 :                                         maximumSize: Size.fromWidth(400),
     569           0 :                                         shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180))),
     570             :                                       ),
     571           0 :                                       child: Text(
     572           0 :                                         AppLocalizations.of(context)!.addContact,
     573           0 :                                         semanticsLabel: AppLocalizations.of(context)!.addContact,
     574             :                                         textAlign: TextAlign.center,
     575           0 :                                         style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
     576             :                                       ),
     577           0 :                                       onPressed: () {
     578           0 :                                         _pushAddContact(false);
     579             :                                       },
     580             :                                     ))),
     581           0 :                             SizedBox(
     582             :                               height: 20,
     583             :                             ),
     584           0 :                             Expanded(
     585           0 :                               child: Tooltip(
     586           0 :                                   message: groupsEnabled ? AppLocalizations.of(context)!.addServerTooltip : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled,
     587           0 :                                   child: ElevatedButton(
     588           0 :                                     style: ElevatedButton.styleFrom(
     589           0 :                                       minimumSize: Size.fromWidth(399),
     590           0 :                                       maximumSize: Size.fromWidth(400),
     591           0 :                                       shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180))),
     592             :                                     ),
     593           0 :                                     child: Text(
     594           0 :                                       AppLocalizations.of(context)!.addServerTitle,
     595           0 :                                       semanticsLabel: AppLocalizations.of(context)!.addServerTitle,
     596             :                                       textAlign: TextAlign.center,
     597           0 :                                       style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
     598             :                                     ),
     599             :                                     onPressed: groupsEnabled
     600           0 :                                         ? () {
     601           0 :                                             _pushAddContact(false);
     602             :                                           }
     603             :                                         : null,
     604             :                                   )),
     605             :                             ),
     606           0 :                             SizedBox(
     607             :                               height: 20,
     608             :                             ),
     609           0 :                             Expanded(
     610           0 :                                 child: Tooltip(
     611           0 :                                     message: groupsEnabled ? AppLocalizations.of(context)!.createGroupTitle : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled,
     612           0 :                                     child: ElevatedButton(
     613           0 :                                       style: ElevatedButton.styleFrom(
     614           0 :                                         minimumSize: Size.fromWidth(399),
     615           0 :                                         maximumSize: Size.fromWidth(400),
     616           0 :                                         shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180))),
     617             :                                       ),
     618           0 :                                       child: Text(
     619           0 :                                         AppLocalizations.of(context)!.createGroupTitle,
     620           0 :                                         semanticsLabel: AppLocalizations.of(context)!.createGroupTitle,
     621             :                                         textAlign: TextAlign.center,
     622           0 :                                         style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
     623             :                                       ),
     624             :                                       onPressed: groupsEnabled
     625           0 :                                           ? () {
     626           0 :                                               _pushAddContact(true);
     627             :                                             }
     628             :                                           : null,
     629             :                                     ))),
     630           0 :                             SizedBox(
     631             :                               height: 20,
     632             :                             ),
     633             :                           ],
     634             :                         ))),
     635             :               )));
     636             :         });
     637             :   }
     638             : 
     639           0 :   void _showQRCode(String profileCode) {
     640           0 :     showModalBottomSheet<dynamic>(
     641           0 :       context: context,
     642           0 :       builder: (BuildContext context) {
     643           0 :         return Wrap(children: <Widget>[
     644           0 :           Center(
     645           0 :             child: QrImageView(
     646             :               data: profileCode,
     647             :               version: QrVersions.auto,
     648             :               size: 400.0,
     649           0 :               backgroundColor: Provider.of<Settings>(context).theme.backgroundPaneColor,
     650           0 :               foregroundColor: Provider.of<Settings>(context).theme.mainTextColor,
     651             :               gapless: false,
     652             :             ),
     653             :           )
     654             :         ]);
     655             :       },
     656             :     );
     657             :   }
     658             : }

Generated by: LCOV version 1.14