Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:App crash related to flutter_contacts #251

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scp/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
Expand Down
38 changes: 26 additions & 12 deletions scp/lib/ui/views/mentor_search/mentor_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,13 @@ class MentorDetails extends StatelessWidget {
shape: StadiumBorder(),
),
onPressed: () {
saveContact(Contact(
displayName: mentorName,
phones: [Phone(mentorContact)],
emails: [Email(mentorEmail)],
));
saveContact(
Contact(
displayName: mentorName,
phones: [Phone(mentorContact)],
emails: [Email(mentorEmail)],
),
context);
},
child: Text(
message,
Expand Down Expand Up @@ -333,12 +335,24 @@ class MentorDetails extends StatelessWidget {
});
}

void saveContact(Contact contact) async {
// save contact
final result = FlutterContacts.insertContact(contact).then((value) {
print('add contact dialog closed');
}).catchError((error) {
print('pata nai bhai kya error hai');
});
void saveContact(Contact contact, BuildContext context) async {
if (await FlutterContacts.requestPermission()) {
// save contact
final result = FlutterContacts.insertContact(contact)
.then((value) {})
.catchError((error) {
debugPrint(error);
});
} else {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"App need permission to create the contact",
style: TextStyle(color: Colors.amber),
),
),
);
}
}
}