【问题标题】:How can I get a clickable icon on the top right corner of a button in flutter?如何在颤动的按钮右上角获得可点击的图标?
【发布时间】:2020-06-17 09:01:02
【问题描述】:

我试图在按钮的右上角获得一个可点击的图标。我尝试将 FloatingActionButton 添加到行小部件,但它只是将其添加到按钮的右侧。我希望它漂浮在右上角的按钮上。任何帮助,将不胜感激。我有一个屏幕截图,它现在显示在下面。

            ButtonTheme (
              minWidth: 250.0,
              height: 80.0,
              buttonColor: Color.fromRGBO(234, 135, 137, 1.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  RaisedButton (
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10.0),
                      side: BorderSide(
                        color: Colors.transparent,
                      ),
                    ),
                    child: Text(
                      'Daily Challenge',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 22.0,
                        fontFamily: 'MuseoSans',
                      ),
                    ),
                    onPressed: () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(builder: (context) => DailyMedChallenge(uid: user.uid, qidDC: user.qidDC)),
                      );
                    },
                  ),
                  Container(
                    width: 35.0,
                    height: 35.0,
                    child: FloatingActionButton(
                      child: Icon(
                        Icons.help,
                      ),
                      backgroundColor: Colors.grey,
                      onPressed: () {

                      },
                    ),
                  )
                ],
              ),
            ),

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您可以为此使用 Stack 和 Positioned 小部件

    
       ButtonTheme (
                  minWidth: 250.0,
                  height: 80.0,
                  buttonColor: Color.fromRGBO(234, 135, 137, 1.0),
                  child: Stack(
                     children: [
                      RaisedButton (
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10.0),
                          side: BorderSide(
                            color: Colors.transparent,
                          ),
                        ),
                        child: Text(
                          'Daily Challenge',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 22.0,
                            fontFamily: 'MuseoSans',
                          ),
                        ),
                        onPressed: () {
                         //click actions
                        },
                      ),
                      Positioned( // will be positioned in the top right of the container
                        top: 0,
                        right: 0,
                        child: Icon(
                            Icons.help,
                          ),
                       )
                    ]
                  )
                ),
    
    
    

    【讨论】:

    • 是否可以让它稍微漂浮在上面?我用 FloatingActionButton 替换了 IconButton,但现在它位于角落的按钮中。我想要一半在右上角,另一半浮出
    • 我通过将堆栈中的对齐属性更改为 alignment.bottomCenter 并用容器包装堆栈来实现它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 2021-10-30
    • 2016-09-13
    • 2011-07-06
    • 1970-01-01
    相关资源
    最近更新 更多