|
@@ -4,7 +4,6 @@ import 'dart_tutorial/addressbook.pb.dart';
|
|
|
|
|
|
// This function fills in a Person message based on user input.
|
|
// This function fills in a Person message based on user input.
|
|
Person promtForAddress() {
|
|
Person promtForAddress() {
|
|
-
|
|
|
|
Person person = Person();
|
|
Person person = Person();
|
|
|
|
|
|
print('Enter person ID: ');
|
|
print('Enter person ID: ');
|
|
@@ -20,9 +19,9 @@ Person promtForAddress() {
|
|
person.email = email;
|
|
person.email = email;
|
|
}
|
|
}
|
|
|
|
|
|
- while(true) {
|
|
|
|
|
|
+ while (true) {
|
|
print('Enter a phone number (or leave blank to finish): ');
|
|
print('Enter a phone number (or leave blank to finish): ');
|
|
- String number = stdin. readLineSync();
|
|
|
|
|
|
+ String number = stdin.readLineSync();
|
|
if (number.isEmpty) break;
|
|
if (number.isEmpty) break;
|
|
|
|
|
|
Person_PhoneNumber phoneNumber = Person_PhoneNumber();
|
|
Person_PhoneNumber phoneNumber = Person_PhoneNumber();
|
|
@@ -31,7 +30,7 @@ Person promtForAddress() {
|
|
print('Is this a mobile, home, or work phone? ');
|
|
print('Is this a mobile, home, or work phone? ');
|
|
|
|
|
|
String type = stdin.readLineSync();
|
|
String type = stdin.readLineSync();
|
|
- switch(type) {
|
|
|
|
|
|
+ switch (type) {
|
|
case 'mobile':
|
|
case 'mobile':
|
|
phoneNumber.type = Person_PhoneType.MOBILE;
|
|
phoneNumber.type = Person_PhoneType.MOBILE;
|
|
break;
|
|
break;
|
|
@@ -62,10 +61,10 @@ main(List<String> arguments) {
|
|
AddressBook addressBook;
|
|
AddressBook addressBook;
|
|
if (!file.existsSync()) {
|
|
if (!file.existsSync()) {
|
|
print('File not found. Creating new file.');
|
|
print('File not found. Creating new file.');
|
|
- addressBook = AddressBook();
|
|
|
|
|
|
+ addressBook = AddressBook();
|
|
} else {
|
|
} else {
|
|
addressBook = AddressBook.fromBuffer(file.readAsBytesSync());
|
|
addressBook = AddressBook.fromBuffer(file.readAsBytesSync());
|
|
}
|
|
}
|
|
addressBook.people.add(promtForAddress());
|
|
addressBook.people.add(promtForAddress());
|
|
file.writeAsBytes(addressBook.writeToBuffer());
|
|
file.writeAsBytes(addressBook.writeToBuffer());
|
|
-}
|
|
|
|
|
|
+}
|