1ffe3c632Sopenharmony_ciimport 'dart:io'; 2ffe3c632Sopenharmony_ci 3ffe3c632Sopenharmony_ciimport 'dart_tutorial/addressbook.pb.dart'; 4ffe3c632Sopenharmony_ciimport 'dart_tutorial/addressbook.pbenum.dart'; 5ffe3c632Sopenharmony_ci 6ffe3c632Sopenharmony_ci/// Iterates though all people in the AddressBook and prints info about them. 7ffe3c632Sopenharmony_civoid printAddressBook(AddressBook addressBook) { 8ffe3c632Sopenharmony_ci for (var person in addressBook.people) { 9ffe3c632Sopenharmony_ci print('Person ID: ${person.id}'); 10ffe3c632Sopenharmony_ci print(' Name: ${person.name}'); 11ffe3c632Sopenharmony_ci if (person.hasEmail()) { 12ffe3c632Sopenharmony_ci print(' E-mail address:${person.email}'); 13ffe3c632Sopenharmony_ci } 14ffe3c632Sopenharmony_ci 15ffe3c632Sopenharmony_ci for (var phoneNumber in person.phones) { 16ffe3c632Sopenharmony_ci switch (phoneNumber.type) { 17ffe3c632Sopenharmony_ci case Person_PhoneType.MOBILE: 18ffe3c632Sopenharmony_ci print(' Mobile phone #: '); 19ffe3c632Sopenharmony_ci break; 20ffe3c632Sopenharmony_ci case Person_PhoneType.HOME: 21ffe3c632Sopenharmony_ci print(' Home phone #: '); 22ffe3c632Sopenharmony_ci break; 23ffe3c632Sopenharmony_ci case Person_PhoneType.WORK: 24ffe3c632Sopenharmony_ci print(' Work phone #: '); 25ffe3c632Sopenharmony_ci break; 26ffe3c632Sopenharmony_ci default: 27ffe3c632Sopenharmony_ci print(' Unknown phone #: '); 28ffe3c632Sopenharmony_ci break; 29ffe3c632Sopenharmony_ci } 30ffe3c632Sopenharmony_ci print(phoneNumber.number); 31ffe3c632Sopenharmony_ci } 32ffe3c632Sopenharmony_ci } 33ffe3c632Sopenharmony_ci} 34ffe3c632Sopenharmony_ci 35ffe3c632Sopenharmony_ci/// Reads the entire address book from a file and prints all 36ffe3c632Sopenharmony_ci/// the information inside. 37ffe3c632Sopenharmony_civoid main(List<String> arguments) { 38ffe3c632Sopenharmony_ci if (arguments.length != 1) { 39ffe3c632Sopenharmony_ci print('Usage: list_person ADDRESS_BOOK_FILE'); 40ffe3c632Sopenharmony_ci exit(-1); 41ffe3c632Sopenharmony_ci } 42ffe3c632Sopenharmony_ci 43ffe3c632Sopenharmony_ci // Read the existing address book. 44ffe3c632Sopenharmony_ci final file = new File(arguments.first); 45ffe3c632Sopenharmony_ci final addressBook = new AddressBook.fromBuffer(file.readAsBytesSync()); 46ffe3c632Sopenharmony_ci printAddressBook(addressBook); 47ffe3c632Sopenharmony_ci} 48