2022-01-18 21:26:52 +00:00
|
|
|
import 'package:cwtch/models/contact.dart';
|
|
|
|
import 'package:cwtch/models/profile.dart';
|
2023-09-26 21:01:57 +00:00
|
|
|
import 'package:cwtch/themes/opaque.dart';
|
2021-06-24 23:10:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
bool noFilter(ContactInfoState peer) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dropdown menu populated from Provider.of<ProfileInfoState>'s contact list
|
|
|
|
// Includes both peers and groups; begins empty/nothing selected
|
|
|
|
// Displays nicknames to UI but uses handles as values
|
|
|
|
// Pass an onChanged handler to access value
|
|
|
|
class DropdownContacts extends StatefulWidget {
|
|
|
|
DropdownContacts({
|
|
|
|
required this.onChanged,
|
|
|
|
this.filter = noFilter,
|
|
|
|
});
|
|
|
|
final Function(dynamic) onChanged;
|
|
|
|
final bool Function(ContactInfoState) filter;
|
|
|
|
|
|
|
|
@override
|
|
|
|
_DropdownContactsState createState() => _DropdownContactsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DropdownContactsState extends State<DropdownContacts> {
|
|
|
|
String? selected;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return DropdownButton(
|
2022-07-04 21:32:53 +00:00
|
|
|
isExpanded: true, // magic property
|
2021-06-24 23:10:45 +00:00
|
|
|
value: this.selected,
|
|
|
|
items: Provider.of<ProfileInfoState>(context, listen: false).contactList.contacts.where(widget.filter).map<DropdownMenuItem<String>>((ContactInfoState contact) {
|
2023-09-26 21:01:57 +00:00
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
value: contact.onion,
|
|
|
|
child: Text(
|
|
|
|
contact.nickname,
|
|
|
|
style: defaultTextStyle,
|
|
|
|
));
|
2021-06-24 23:10:45 +00:00
|
|
|
}).toList(),
|
|
|
|
onChanged: (String? newVal) {
|
|
|
|
setState(() {
|
|
|
|
this.selected = newVal;
|
|
|
|
});
|
|
|
|
widget.onChanged(newVal);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|