首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将我的应用程序重定向到“添加联系人”部分

如何将我的应用程序重定向到“添加联系人”部分
EN

Stack Overflow用户
提问于 2021-12-17 17:37:02
回答 1查看 319关注 0票数 0

我正在创建一个项目,在这个项目中,我从一个有电话号码的客户模型中获取数据,我需要将这个电话号码作为一个新的联系人添加,但是我还没有找到一种方法来重定向我的应用程序来添加联系人。我只看过如何重定向电话。

代码语言:javascript
复制
Padding(
 padding: const EdgeInsets.only(left: 10.0),
 child: Container(
  width: 50,
  child: FlatButton(
   child: Icon(Icons.call, color: Color(0xFF7AAF00),),
   onPressed:() async{
   String url = 'tel:${model.cliente.telefono}'; 
   if (await canLaunch(url)) {
    await launch(url);
   }else{
    throw 'No se pudo $url';
   }
  }
 ),
),),


Container(
width: 50,
child: FlatButton(
 child: Icon(Icons.contact_page_outlined, color: Color(0xFF7AAF00),),
  onPressed: (){
  },
),),
EN

回答 1

Stack Overflow用户

发布于 2021-12-17 17:48:02

要想在你的手机上添加一个新的联系人,我建议使用pub dev的一个软件包。

接触包

该包具有一个名为:

等待Contacts.addContact(newContact);

取决于您的目标等等。下面是包中的完整示例:

代码语言:javascript
复制
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_contact/contacts.dart';
import 'package:flutter_contact/flutter_contact.dart';

class AddContactPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _AddContactPageState();
}

class _AddContactPageState extends State<AddContactPage> {
  Contact contact = Contact();
  PostalAddress address = PostalAddress(label: 'Home');
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Add a contact'),
        actions: <Widget>[
          TextButton(
            onPressed: () {
              _formKey.currentState!.save();
              contact.postalAddresses = [address];
              Contacts.addContact(contact);
              Navigator.of(context).pop();
            },
            child: Icon(Icons.save, color: Colors.white),
          )
        ],
      ),
      body: Container(
        padding: EdgeInsets.all(12.0),
        child: Form(
          key: _formKey,
          child: ListView(
            children: <Widget>[
              TextFormField(
                decoration: const InputDecoration(labelText: 'First name'),
                onSaved: (v) => contact.givenName = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Middle name'),
                onSaved: (v) => contact.middleName = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Last name'),
                onSaved: (v) => contact.familyName = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Prefix'),
                onSaved: (v) => contact.prefix = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Suffix'),
                onSaved: (v) => contact.suffix = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Phone'),
                onSaved: (v) => contact.phones = [
                  if (v != null && v.isNotEmpty) Item(label: 'mobile', value: v)
                ],
                keyboardType: TextInputType.phone,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'E-mail'),
                onSaved: (v) => contact.emails = [
                  if (v != null && v.isNotEmpty) Item(label: 'work', value: v)
                ],
                keyboardType: TextInputType.emailAddress,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Company'),
                onSaved: (v) => contact.company = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Job'),
                onSaved: (v) => contact.jobTitle = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Street'),
                onSaved: (v) => address.street = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'City'),
                onSaved: (v) => address.city = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Region'),
                onSaved: (v) => address.region = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Postal code'),
                onSaved: (v) => address.postcode = v,
              ),
              TextFormField(
                decoration: const InputDecoration(labelText: 'Country'),
                onSaved: (v) => address.country = v,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70396890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档