Line data Source code
1 : import 'package:cwtch/models/profilelist.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(ProfileListState list) { 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 DropdownProfiles extends StatefulWidget { 18 : Widget? hint; 19 0 : DropdownProfiles({required this.onChanged, this.filter = noFilter, this.hint}); 20 : final Function(dynamic) onChanged; 21 : final bool Function(ProfileListState) filter; 22 : 23 0 : @override 24 0 : _DropdownProfilesState createState() => _DropdownProfilesState(); 25 : } 26 : 27 : class _DropdownProfilesState extends State<DropdownProfiles> { 28 : String? selected; 29 : 30 0 : @override 31 : Widget build(BuildContext context) { 32 0 : return DropdownButton( 33 : isExpanded: true, // magic property 34 0 : value: this.selected, 35 0 : hint: widget.hint, 36 0 : items: Provider.of<ProfileListState>(context, listen: false).profiles.map<DropdownMenuItem<String>>((ProfileInfoState profile) { 37 0 : return DropdownMenuItem<String>( 38 0 : value: profile.onion, 39 0 : child: Text(profile.nickname, style: Provider.of<Settings>(context).scaleFonts(defaultTextStyle)), 40 : ); 41 0 : }).toList(), 42 0 : onChanged: (String? newVal) { 43 0 : setState(() { 44 0 : this.selected = newVal; 45 : }); 46 0 : widget.onChanged(newVal); 47 : }, 48 : ); 49 : } 50 : }