【发布时间】:2020-11-02 21:03:25
【问题描述】:
你好新来这里。在按下定位内的 Flatbutton 的呼叫按钮后,我试图用预定义的电话号码打开电话拨号器,但它不起作用,也没有显示任何错误。我也尝试在 onpressed 上打印一些值,但它没有打印任何值。我已经在另一个 dart 文件中调用了这个小部件。
这里我使用 url_launcher 包来启动电话对话框。 如果有其他替代方法,请提供帮助。
(删除了下面一些不重要的设计代码)
class CallCard extends StatefulWidget {
@override
_CallCardState createState() => _CallCardState();
}
class _CallCardState extends State<CallCard> {
@override
Widget build(BuildContext context) {
return Positioned(
bottom: -170,
child: Container(
child: Column(
children: <Widget>[
SizedBox(
height: 15,
),
Text(
'Are you feeling well today?',
style: TextStyle(
fontSize: 24.0,
),
),
Text(
'Give us a call or visit our website.',
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w300,
),
),
SizedBox(
height: 23.0,
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
color: Color(0xff9ce47c),
onPressed: () {
final String phone = "01-4441577";
launch(phone);
print('here');
},
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(50),
),
child: Row(
children: <Widget>[
Icon(
LineAwesomeIcons.phone,
size: 22,
),
SizedBox(
width: 5.0,
),
Text(
'Call Now',
style: TextStyle(
fontSize: 16,
),
),
],
),
),
SizedBox(
width: 1.0,
),
],
),
),
],
)
],
),
));
}
}
这是我调用这个小部件的代码(在堆栈内)
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Stack(
alignment: Alignment.topCenter,
overflow: Overflow.visible,
children: <Widget>[
_backgroundCover(),
//content inside header
Positioned(
top: 80,
left: 30,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
//crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Hello User',
style: TextStyle(
fontSize: 36,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
SizedBox(width: 10.0,),
// Padding(padding: EdgeInsets.only(right: 200.0)),
IconButton(
icon: Icon(
LineAwesomeIcons.power_off,
size: 40.0,
),
onPressed: () {
DialogHelper.exit(context);
// await _auth.signOut();
}),
],
),
),
CallCard(),
],
),
],
),
),
);
【问题讨论】:
-
您可以添加
Stack小部件的代码吗? @邦德先生。 -
我加了,(CallCard())
-
请将堆栈的代码 sn-p 添加到您的问题中,以便我提供帮助。 @邦德先生
-
嘿@TimilehinJegede 感谢您的评论,我通过简单地从堆栈小部件中删除它来解决它。谢谢你:)