native_contact_dialog 0.2.2 copy "native_contact_dialog: ^0.2.2" to clipboard
native_contact_dialog: ^0.2.2 copied to clipboard

Edit contacts using the platform's native contact dialogs. Supports Android and iOS 9+, no permissions required.

example/lib/main.dart

import 'dart:typed_data';

import 'dart:async';
import 'package:native_contact_dialog/native_contact_dialog.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Native Contacts View Plugin Example App'),
        ),
        body: Column(
          children: [
            ContactButton(),
            Center(child: FlatButton.icon(
              icon: Icon(Icons.insert_link, color: Colors.black87, size: 32,),
              label: Text('Test Url_launcher', 
                style: TextStyle(
                  color: Colors.black87,
                  // fontSize: 2,
                ),
              ),
              color: Color(0xFF69F0AE),
              onPressed: () {
                launch('https://www.google.com/');
              },
            ),)
          ]
        ),
      ),
    );
  }
}

final imageDataController = StreamController<Uint8List>();
Stream<Uint8List> get outImageData => imageDataController.stream;
Sink<Uint8List> get inImageData => imageDataController.sink;

class ContactButton extends StatelessWidget {

  Future<Null> _getImageUInt8List() async {
    // TODO: Find a way to convert a network image to a Uint8List for ios and android
    // With the current implementation, the image can  be shown when adding a contact in ios; however,
    // that image will somehow cause the contact to not be added to the address book when pressing 'Done'
    final image = NetworkImage("https://ui-avatars.com/api/?name=Andrew+Fulton");
    image.obtainKey(ImageConfiguration()).then((obtainedKey) {
      final loadedImage = image.load(obtainedKey);
      loadedImage.addListener((listener, error) {
          listener.image.toByteData().then((imageData) {
              final imageDataList = imageData.buffer.asUint8List();
              inImageData.add(imageDataList);
          });
      });
    });

    return null;
  }

  @override
  StatelessElement createElement() {
    _getImageUInt8List();
    return super.createElement();
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: outImageData,
      builder: (context, AsyncSnapshot<Uint8List> snapshot) {
        if (snapshot.hasData) {
          return FlatButton.icon(
            icon: Icon(Icons.person_add, color: Colors.white,),
            color: Colors.black87,
            textColor: Colors.white,
            label: Text("Add to contacts"),
            onPressed: () {
              debugPrint("Pressed add to contacts!");
                NativeContactDialog.addContact(Contact(
                  company: "The Testing Company",
                  familyName: "Testers",
                  givenName: "Test",
                  prefix: "Mr",
                  jobTitle: "Tester",
                  middleName: "Is",
                  avatar: snapshot.data,
                  phones: [
                    Item(label: 'Mobile', value: '999999999')
                  ],
                  emails: [
                    Item(label: 'School', value: 'email@email.com')
                  ]
                ));
            },
          );
        } else {
          return Center(
            child: CircularProgressIndicator(),
          );
        }
      }
    );
  }

}
0
likes
40
pub points
27%
popularity

Publisher

unverified uploader

Edit contacts using the platform's native contact dialogs. Supports Android and iOS 9+, no permissions required.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on native_contact_dialog