LCOV - code coverage report
Current view: top level - lib/widgets - DropdownContacts.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 18 0.0 %
Date: 2024-08-19 21:58:30 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:cwtch/models/contact.dart';
       2             : import 'package:cwtch/models/profile.dart';
       3             : import 'package:cwtch/themes/opaque.dart';
       4             : import 'package:flutter/material.dart';
       5             : import 'package:provider/provider.dart';
       6             : 
       7             : import '../settings.dart';
       8             : 
       9           0 : bool noFilter(ContactInfoState peer) {
      10             :   return true;
      11             : }
      12             : 
      13             : // Dropdown menu populated from Provider.of<ProfileInfoState>'s contact list
      14             : // Includes both peers and groups; begins empty/nothing selected
      15             : // Displays nicknames to UI but uses handles as values
      16             : // Pass an onChanged handler to access value
      17             : class DropdownContacts extends StatefulWidget {
      18           0 :   DropdownContacts({
      19             :     required this.onChanged,
      20             :     this.filter = noFilter,
      21             :   });
      22             :   final Function(dynamic) onChanged;
      23             :   final bool Function(ContactInfoState) filter;
      24             : 
      25           0 :   @override
      26           0 :   _DropdownContactsState createState() => _DropdownContactsState();
      27             : }
      28             : 
      29             : class _DropdownContactsState extends State<DropdownContacts> {
      30             :   String? selected;
      31             : 
      32           0 :   @override
      33             :   Widget build(BuildContext context) {
      34           0 :     return DropdownButton(
      35             :         isExpanded: true, // magic property
      36           0 :         value: this.selected,
      37           0 :         items: Provider.of<ProfileInfoState>(context, listen: false).contactList.contacts.where(widget.filter).map<DropdownMenuItem<String>>((ContactInfoState contact) {
      38           0 :           return DropdownMenuItem<String>(
      39           0 :               value: contact.onion,
      40           0 :               child: Text(
      41           0 :                 contact.nickname,
      42           0 :                 style: Provider.of<Settings>(context).scaleFonts(defaultTextStyle),
      43             :               ));
      44           0 :         }).toList(),
      45           0 :         onChanged: (String? newVal) {
      46           0 :           setState(() {
      47           0 :             this.selected = newVal;
      48             :           });
      49           0 :           widget.onChanged(newVal);
      50             :         });
      51             :   }
      52             : }

Generated by: LCOV version 1.14