Commit bc00484b authored by Sarah Zakarias's avatar Sarah Zakarias

comments and formatting

parent 969397b7
......@@ -36,6 +36,7 @@ protoc_middleman_go: addressbook.proto
protoc_middleman_dart: addressbook.proto
mkdir -p dart_tutorial # make directory for the dart package
protoc $$PROTO_PATH --dart_out=dart_tutorial addressbook.proto
protoc -I../src/ --dart_out=dart_tutorial ../src/google/protobuf/timestamp.proto
pub get
@touch protoc_middleman_dart
......
......@@ -119,7 +119,7 @@ is created if it does not exist. To view the data, run:
./list_people_go addressbook.data
Observe that the C++, Python, and Java examples in this directory run in a
Observe that the C++, Python, Java, and Dart examples in this directory run in a
similar way and can view/modify files created by the Go example and vice
versa.
......@@ -134,9 +134,10 @@ Build the Dart samples in this directory with `make dart`.
To run the examples:
```sh
$ dart add_person.dart addessbook.data
$ dart list_people.dart addressbook.data
```
The two programs take a protocol buffer encoded file as their parameter.
The first can be used to add a person to the file. The file is created
......
......@@ -4,7 +4,6 @@ import 'dart_tutorial/addressbook.pb.dart';
// This function fills in a Person message based on user input.
Person promtForAddress() {
Person person = Person();
print('Enter person ID: ');
......@@ -20,9 +19,9 @@ Person promtForAddress() {
person.email = email;
}
while(true) {
while (true) {
print('Enter a phone number (or leave blank to finish): ');
String number = stdin. readLineSync();
String number = stdin.readLineSync();
if (number.isEmpty) break;
Person_PhoneNumber phoneNumber = Person_PhoneNumber();
......@@ -31,7 +30,7 @@ Person promtForAddress() {
print('Is this a mobile, home, or work phone? ');
String type = stdin.readLineSync();
switch(type) {
switch (type) {
case 'mobile':
phoneNumber.type = Person_PhoneType.MOBILE;
break;
......@@ -62,10 +61,10 @@ main(List<String> arguments) {
AddressBook addressBook;
if (!file.existsSync()) {
print('File not found. Creating new file.');
addressBook = AddressBook();
addressBook = AddressBook();
} else {
addressBook = AddressBook.fromBuffer(file.readAsBytesSync());
}
addressBook.people.add(promtForAddress());
file.writeAsBytes(addressBook.writeToBuffer());
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment