【问题标题】:Flutter Flatbutton onpressed not working while trying to open phone dialer尝试打开电话拨号器时,Flutter Flatbutton onpressed 不起作用
【发布时间】: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 感谢您的评论,我通过简单地从堆栈小部件中删除它来解决它。谢谢你:)

标签: android flutter


【解决方案1】:

您是否尝试在发布前进行打印?可能是启动被卡住了,然后打印就永远无法到达(这在我的某些包中发生过)。

我不确定启动如何与电话号码一起使用,但您可能想了解一下您是否正确使用它。

【讨论】:

  • 还有一件事,你定位的意图是什么? Stack是祖先吗?
  • 是的 Stack 是父母,我不知道有人告诉我使用 Positioned 所以我做了
【解决方案2】:

我对这段代码没问题。

launch('tel:$yourPhoneNo');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多