Skip to content

Commit

Permalink
contact list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruchi71 committed Dec 18, 2023
1 parent 619139b commit 799f2a7
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 17 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 33
ndkVersion flutter.ndkVersion

compileOptions {
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kilvish">
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<application
android:label="kilvish"
android:name="${applicationName}"
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>NSContactsUsageDescription</key>
<string>This app requires contacts access to function properly.</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
78 changes: 78 additions & 0 deletions lib/contact_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'package:contacts_service/contacts_service.dart';
import 'package:flutter/material.dart';
import 'package:kilvish/common_widgets.dart';
import 'package:kilvish/style.dart';
import 'package:permission_handler/permission_handler.dart';



class ContactScreen extends StatefulWidget {
const ContactScreen({Key? key}) : super(key: key);

@override
State<ContactScreen> createState() => _ContactScreenState();
}

class _ContactScreenState extends State<ContactScreen> {

List<Contact> contacts = [];
bool isLoading = true;

@override
void initState() {
// TODO: implement initState
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await getContactPermission();
});
}

Future<void> getContactPermission() async {
if (await Permission.contacts.request().isGranted) {
// Permission is granted, fetch contacts
fetchContacts();
} else {
await Permission.contacts.request();
// Permission is denied
print('Contact permission is denied');
}
}

Future fetchContacts() async {
contacts = await ContactsService.getContacts();
setState(() {
isLoading = false;
});

}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: appBarTitleText('Contact List'),
),
body:
isLoading?const Center(child: CircularProgressIndicator()):ListView.builder(
itemCount: contacts.length,
itemBuilder: (BuildContext context, int index) {
print("con-${contacts[index].phones}");
return
contacts[index].displayName == null?const SizedBox():
ListTile(
leading: CircleAvatar(
child: Text(contacts[index].displayName![0]??''),
),
title: Text(contacts[index].displayName??''),
subtitle: Text(
contacts[index].phones?.isNotEmpty == true
? contacts[index].phones![0].value ?? ''
: 'No phone number',
),

);
},
),
);
}
}
42 changes: 27 additions & 15 deletions lib/import_expense_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_picker/image_picker.dart';
import 'package:kilvish/constants/dimens_constants.dart';
import 'package:flutter/scheduler.dart';
import 'package:kilvish/contact_screen.dart';
import 'package:kilvish/home_screen.dart';
import 'package:kilvish/platform_functions.dart';
import 'package:kilvish/style.dart';
Expand Down Expand Up @@ -92,20 +93,23 @@ class _ImportExpensePageState extends State<ImportExpensePage> {
void initState() {
super.initState();
SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
if (widget.files!.isNotEmpty) {
setState(() {
_imageFile = XFile(widget.files!.first.path);
// var i = 0;
// widget.files?.forEach((element) {
// _galleryItems.add(MediaPreviewItem(
// id: i,
// resource: element,
// controller: TextEditingController(),
// isSelected: i == 0 ? true : false));
// i++;
// });
});
if(widget.files != null){
if (widget.files!.isNotEmpty) {
setState(() {
_imageFile = XFile(widget.files!.first.path);
// var i = 0;
// widget.files?.forEach((element) {
// _galleryItems.add(MediaPreviewItem(
// id: i,
// resource: element,
// controller: TextEditingController(),
// isSelected: i == 0 ? true : false));
// i++;
// });
});
}
}

});
}

Expand Down Expand Up @@ -160,7 +164,12 @@ class _ImportExpensePageState extends State<ImportExpensePage> {
});
}),
const Spacer(),
customContactUi(onTap: _contactFetchFn),
customContactUi(
onTap: (){
Navigator.push(context,MaterialPageRoute(builder: (context)=> ContactScreen()));
}
// onTap: _contactFetchFn
),
],
)
: TextFormField(
Expand All @@ -170,7 +179,10 @@ class _ImportExpensePageState extends State<ImportExpensePage> {
decoration: customUnderlineInputdecoration(
hintText: 'Enter Name or select from contact',
bordersideColor: primaryColor,
suffixicon: customContactUi(onTap: _contactFetchFn),
suffixicon: customContactUi(onTap:(){
Navigator.push(context,MaterialPageRoute(builder: (context)=> ContactScreen()));}
//_contactFetchFn
),
)),
/*
render Receipt/Screenshot
Expand Down
6 changes: 5 additions & 1 deletion lib/tag_edit_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:fluttercontactpicker/fluttercontactpicker.dart';
import 'package:kilvish/common_widgets.dart';
import 'package:kilvish/constants/dimens_constants.dart';
import 'package:kilvish/contact_screen.dart';
import 'package:kilvish/models.dart';
import 'package:kilvish/platform_functions.dart';
import 'package:kilvish/style.dart';
Expand Down Expand Up @@ -87,7 +88,10 @@ class _TagEditPageState extends State<TagEditPage> {
});
}),
const Spacer(),
customContactUi(onTap: _contactFetchFn),
customContactUi(onTap: () {
Navigator.push(context,MaterialPageRoute(builder: (context)=> ContactScreen()));
// _contactFetchFn
}),
],
)
]))),
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ dependencies:
fluttercontactpicker: ^4.7.0
image_picker: ^1.0.5
fluttertoast: ^8.2.4
contacts_service: ^0.6.3
permission_handler: ^11.1.0

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h"

#include <file_selector_windows/file_selector_windows.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
permission_handler_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 799f2a7

Please sign in to comment.