如何将我的应用重定向到添加联系人部分
Posted
技术标签:
【中文标题】如何将我的应用重定向到添加联系人部分【英文标题】:How to redirect my app to the add contact section 【发布时间】:2022-01-20 14:22:27 【问题描述】:我正在创建一个项目,我从具有电话号码的客户模型中引入数据,并且我需要能够将该电话号码添加为新联系人,但我还没有找到重定向我的方法应用程序添加联系人。我只看到了如何重定向呼叫。
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: ()
,
),),
【问题讨论】:
【参考方案1】:要使用 Flutter 向您的手机添加新联系人,我建议使用来自 pub dev 的包
Klick here to view flutter_contact package
这个包有一个函数叫做:
等待 Contacts.addContact(newContact);
取决于您的目标等。 这是包中的完整示例:
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,
),
],
),
),
),
);
【讨论】:
以上是关于如何将我的应用重定向到添加联系人部分的主要内容,如果未能解决你的问题,请参考以下文章
将 http 重定向到 https AWS 应用程序负载均衡器
禁用 WKWebView 以打开链接以重定向到我的 iPhone 上安装的应用程序