如何将联系人的显示名称显示为文本?
How to show displayName of contact as text?
我想从联系人列表中随机选择一个号码并将其显示为文本。下面是我想出的但是当我在 main.dart
上的某处插入 showNext()
作为文本时,我得到 Closure: () => Future from Function 'showNext': static。 () 而不是数字。如何显示号码?
Future<void> showNext() async {
var status = await Permission.contacts.status;
if (status.isGranted) {
var contacts = await ContactsService.getContacts;
var list = contacts;
list.shuffle();
randomNum= (list.first.phones?.first.value ?? '');
Text('$randomNum');
Future<Widget> showNext() async {
var status = await Permission.contacts.status;
if (status.isGranted) {
final Iterable<Contact> contacts = (await ContactsService.getContacts(withThumbnails: false));
var list = contacts.toList();
list=list.shuffle();
randomNum= (list.first.phones?.first.value ?? '');
return Text('$randomNum');
}
何时使用:
FutureBuilder<String>(
future: showNext(),
builder: (context, snapShot) {
if (!snapShot.hasData) {
return Container();
}
return snapShot.data;
},
)
我想从联系人列表中随机选择一个号码并将其显示为文本。下面是我想出的但是当我在 main.dart
上的某处插入 showNext()
作为文本时,我得到 Closure: () => Future from Function 'showNext': static。 () 而不是数字。如何显示号码?
Future<void> showNext() async {
var status = await Permission.contacts.status;
if (status.isGranted) {
var contacts = await ContactsService.getContacts;
var list = contacts;
list.shuffle();
randomNum= (list.first.phones?.first.value ?? '');
Text('$randomNum');
Future<Widget> showNext() async {
var status = await Permission.contacts.status;
if (status.isGranted) {
final Iterable<Contact> contacts = (await ContactsService.getContacts(withThumbnails: false));
var list = contacts.toList();
list=list.shuffle();
randomNum= (list.first.phones?.first.value ?? '');
return Text('$randomNum');
}
何时使用:
FutureBuilder<String>(
future: showNext(),
builder: (context, snapShot) {
if (!snapShot.hasData) {
return Container();
}
return snapShot.data;
},
)