0

I am creating a flutter app which enables a user to select a contact and display the selected contact before navigating back from the list of contact.

 class ContactsList extends StatelessWidget {
      final List<AppContact> contacts;
      Function() reloadContacts;
      ContactsList({Key? key, required this.contacts, required this.reloadContacts})
          : super(key: key);
      @override
      Widget build(BuildContext context) {
        return Expanded(
          child: ListView.builder(
            shrinkWrap: true,
            itemCount: contacts.length,
            itemBuilder: (context, index) {
              AppContact contact = contacts[index];
    
              return ListTile(
                  onTap: () {
                    Get.back(result:contact.info.phones!.elementAt(0).value!);
                  },
                  title: Text(contact.info.displayName!),
                  subtitle: Text(contact.info.phones!.length > 0
                      ? contact.info.phones!.elementAt(0).value!
                      : ''),
                  leading: ContactAvatar(contact, 36));
            },
          ),
        );
      }
    }

2 Answers2

0

I'm not sure you want this but, you can just use await keyword with navigate function.

For example;

final data = await Get.to(Payment());

if you want to learn some information about navigation with getx you can visit documentation

Salih Can
  • 1,562
  • 1
  • 9
  • 18
0

Simple, use the result parameter in the back method of Getx Wait for your data like this

var data = await Get.to(()=>Screen());

And send back the data like this

Get.back(result: some_data);

MUHINDO
  • 788
  • 6
  • 10