我正在创建一个项目,在这个项目中,我从一个有电话号码的客户模型中获取数据,我需要将这个电话号码作为一个新的联系人添加,但是我还没有找到一种方法来重定向我的应用程序来添加联系人。我只看过如何重定向电话。
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: (){
},
),),发布于 2021-12-17 17:48:02
要想在你的手机上添加一个新的联系人,我建议使用pub dev的一个软件包。
接触包
该包具有一个名为:
等待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,
),
],
),
),
),
);
}
}https://stackoverflow.com/questions/70396890
复制相似问题