Code Monkey home page Code Monkey logo

flutter_contacts_list's Introduction

contacts_app

A new Flutter project to demonstrate how to implement a Contacts List via contacts_service package and how to search within that list using name or number.

Video Tutorials

Contacts List & Search Implementation in Flutter - Easy Peasy:

Contacts List & Search Implementation in Flutter - Easy Peasy

How to use a gradient background with CircleAvatar in Flutter

How to use a gradient background with CircleAvatar in Flutter

Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

flutter_contacts_list's People

Contributors

ahsanayaz avatar antonyleons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flutter_contacts_list's Issues

The app crashed

V/FA (28362): Inactivity, disconnecting from the service
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building:
A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 298 pos 10: 'data != null'

i used to codes and settings:
-----> contacts_service: ^0.3.10

`import 'dart:math';

import 'package:contacts_service/contacts_service.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Contacts'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@OverRide
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
List contacts = [];
List contactsFiltered = [];
Map<String, Color> contactsColorMap = new Map();
TextEditingController searchController = new TextEditingController();

@OverRide
void initState() {
super.initState();
getAllContacts();
searchController.addListener(() {
filterContacts();
});
}

String flattenPhoneNumber(String phoneStr) {
return phoneStr.replaceAllMapped(RegExp(r'^(+)|\D'), (Match m) {
return m[0] == "+" ? "+" : "";
});
}

getAllContacts() async {
List colors = [
Colors.green,
Colors.indigo,
Colors.yellow,
Colors.orange
];
int colorIndex = 0;
List _contacts = (await ContactsService.getContacts()).toList();
_contacts.forEach((contact) {
Color baseColor = colors[colorIndex];
contactsColorMap[contact.displayName] = baseColor;
colorIndex++;
if (colorIndex == colors.length) {
colorIndex = 0;
}
});
setState(() {
contacts = _contacts;
});
}

filterContacts() {
List _contacts = [];
_contacts.addAll(contacts);
if (searchController.text.isNotEmpty) {
_contacts.retainWhere((contact) {
String searchTerm = searchController.text.toLowerCase();
String searchTermFlatten = flattenPhoneNumber(searchTerm);
String contactName = contact.displayName.toLowerCase();
bool nameMatches = contactName.contains(searchTerm);
if (nameMatches == true) {
return true;
}

    if (searchTermFlatten.isEmpty) {
      return false;
    }

    var phone = contact.phones.firstWhere((phn) {
      String phnFlattened = flattenPhoneNumber(phn.value);
      return phnFlattened.contains(searchTermFlatten);
    }, orElse: () => null);

    return phone != null;
  });

  setState(() {
    contactsFiltered = _contacts;
  });
}

}

@OverRide
Widget build(BuildContext context) {
bool isSearching = searchController.text.isNotEmpty;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
padding: EdgeInsets.all(20),
child: Column(
children: [
Container(
child: TextField(
controller: searchController,
decoration: InputDecoration(
labelText: 'Search',
border: new OutlineInputBorder(
borderSide: new BorderSide(
color: Theme.of(context).primaryColor
)
),
prefixIcon: Icon(
Icons.search,
color: Theme.of(context).primaryColor
)
),
),
),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: isSearching == true ? contactsFiltered.length : contacts.length,
itemBuilder: (context, index) {
Contact contact = isSearching == true ? contactsFiltered[index] : contacts[index];

              var baseColor = contactsColorMap[contact.displayName] as dynamic;

              Color color1 = baseColor[800];
              Color color2 = baseColor[400];

              return ListTile(
                  title: Text(contact.displayName),
                  subtitle: Text(
                      contact.phones.elementAt(0).value
                  ),
                  leading: (contact.avatar != null && contact.avatar.length > 0) ?
                  CircleAvatar(
                    backgroundImage: MemoryImage(contact.avatar),
                  ) :
                  Container(
                      decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          gradient: LinearGradient(
                              colors: [
                                color1,
                                color2,
                              ],
                              begin: Alignment.bottomLeft,
                              end: Alignment.topRight
                          )
                      ),
                      child: CircleAvatar(
                          child: Text(
                              contact.initials(),
                              style: TextStyle(
                                  color: Colors.white
                              )
                          ),
                          backgroundColor: Colors.transparent
                      )
                  )
              );
            },
          ),
        )
      ],
    ),
  ),
);

}
}`

The app got crashed when launching on android phone

Hi!
I'm having an issue when trying to build the app on android. This is the log:

Launching lib\main.dart on Nokia 7 2 in debug mode...
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 17.5s
√ Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk... 4.8s
D/FlutterActivity(23291): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate(23291): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(23291): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate(23291): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView(23291): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@78b24b1
D/FlutterActivityAndFragmentDelegate(23291): Executing Dart entrypoint: main, and sending initial route: /
E/AndroidRuntime(23291): FATAL EXCEPTION: pool-2-thread-1
E/AndroidRuntime(23291): Process: com.example.contacts_app, PID: 23291
E/AndroidRuntime(23291): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(23291): at android.os.AsyncTask$4.done(AsyncTask.java:399)
E/AndroidRuntime(23291): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(23291): at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(23291): at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(23291): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(23291): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(23291): at java.lang.Thread.run(Thread.java:919)
E/AndroidRuntime(23291): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{37be599 23291:com.example.contacts_app/u0a223} (pid=23291, uid=10223) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
E/AndroidRuntime(23291): at android.os.Parcel.createException(Parcel.java:2071)
E/AndroidRuntime(23291): at android.os.Parcel.readException(Parcel.java:2039)
E/AndroidRuntime(23291): at android.os.Parcel.readException(Parcel.java:1987)
E/AndroidRuntime(23291): at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5054)
E/AndroidRuntime(23291): at android.app.ActivityThread.acquireProvider(ActivityThread.java:6602)
E/AndroidRuntime(23291): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2725)
E/AndroidRuntime(23291): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2120)
E/AndroidRuntime(23291): at android.content.ContentResolver.query(ContentResolver.java:930)
E/AndroidRuntime(23291): at android.content.ContentResolver.query(ContentResolver.java:881)
E/AndroidRuntime(23291): at android.content.ContentResolver.query(ContentResolver.java:837)
E/AndroidRuntime(23291): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.getCursor(ContactsServicePlugin.java:229)
E/AndroidRuntime(23291): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.access$200(ContactsServicePlugin.java:44)
E/AndroidRuntime(23291): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:170)
E/AndroidRuntime(23291): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:149)
E/AndroidRuntime(23291): at android.os.AsyncTask$3.call(AsyncTask.java:378)
E/AndroidRuntime(23291): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(23291): ... 3 more
E/AndroidRuntime(23291): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime(23291): at com.android.server.am.ActivityManagerService.getContentProviderImpl(ActivityManagerService.java:6954)
E/AndroidRuntime(23291): at com.android.server.am.ActivityManagerService.getContentProvider(ActivityManagerService.java:7374)
E/AndroidRuntime(23291): at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2078)
E/AndroidRuntime(23291): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2765)
E/AndroidRuntime(23291): at android.os.Binder.execTransactInternal(Binder.java:1021)
E/AndroidRuntime(23291):
Lost connection to device.
I/Process (23291): Sending signal. PID: 23291 SIG: 9
Syncing files to device Nokia 7 2...
Could not update files on device: HttpException: Connection closed before full header was received, uri =
http://127.0.0.1:53042/7bMByz4HsY4=/
Syncing files to device Nokia 7 2...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.