This is code for my class...
class List extends StatefulWidget {
@override
_ListState createState() => _ListState();
}
class _ListState extends State<List> {
Future<void> _makePhoneCall(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: customAppbar('Contact Us'),
body: ListView(children: <Widget>[
_listTile('1234-1234567-123', 'Exam Enquiry', Icons.call,
_makePhoneCall('tel:12345'))
]));
}
}
And I want to pass _makePhoneCall Function to a Widget _listTile but got an error:
The argument type 'Future' can't be assigned to the parameter type 'Future Function(String)'
Code for _listTile widget is follow:
Widget _listTile(String title, String subTitle, IconData iconData,
Future<void> _makePhoneCall(String url)) {
return Padding(
padding: EdgeInsets.only(left: 24.0),
child: ListTile(
title: Text(title),
subtitle: Text(subTitle),
trailing: Padding(
padding: const EdgeInsets.all(0.0),
child: RawMaterialButton(
onPressed: () => _makePhoneCall,
child: Icon(
iconData,
color: Colors.white,
),
elevation: 2,
shape: CircleBorder(),
fillColor: Color(0xff7061aa),
),
),
),
);
}
Here are the necessary changes:
body: ListView(children: <Widget>[
_listTile('1234-1234567-123', 'Exam Enquiry', Icons.call,
_makePhoneCall)
]));
child: RawMaterialButton(
onPressed: () => _makePhoneCall('tel:12345'),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.