【问题标题】:Card layouts - Flutter卡片布局 - Flutter
【发布时间】:2019-12-24 04:58:27
【问题描述】:

我正在尝试使用颤振构建一张卡片,看起来像下面显示的概念,但我得到了这个。

这是 Dart 中的卡片小部件代码:

@override
Widget build(BuildContext context) {
    return Center(
      child: Card(
        margin: EdgeInsets.symmetric(horizontal: 14.0),
        color: Colors.white,
        elevation: 6.0,
        child: InkWell(
          splashColor: Colors.blue.withAlpha(30),
          onLongPress: () {_copy();},
          onTap: () {},
          child: Container(
            child: Padding( 
              padding: EdgeInsets.all(12.0),
              child: Row(
                children: <Widget>[
                  Text(widget.cardTitle),
                  Spacer(),
                  ButtonBar(
                    children: <Widget>[
                      new IconButton(
                        icon: Icon(CardsIcons.arrows_ccw, color: primaryDark,),
                        onPressed: () {_refresh();},
                      ),
                      new IconButton(
                        icon: Icon(CardsIcons.heart_empty, color: Colors.redAccent,),
                        onPressed: () {_bookmark();},
                      ),
                    ],
                  ),
                  SizedBox(height: 24.0,),
                  Text(
                    widget.cardContent,
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

这是我目前得到的输出

这是所需的输出

【问题讨论】:

    标签: mobile flutter dart flutter-layout


    【解决方案1】:

    您的结构很接近,但要获得布局,您需要先将所有内容包装在一个 Column 小部件中,其中包含您的行的子小部件,然后是文本。

    下面的代码应该是一个好的开始,您只需要调整填充/文本样式等就可以让它像您的模型一样

      @override
      Widget build(BuildContext context) {
          return Center(
            child: Card(
              margin: EdgeInsets.symmetric(horizontal: 14.0),
              color: Colors.white,
              elevation: 6.0,
              child: InkWell(
                splashColor: Colors.blue.withAlpha(30),
                onLongPress: () {_copy();},
                onTap: () {},
                child: Container(
                  child: Padding( 
                    padding: EdgeInsets.all(12.0),
                    child: Column(
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            Text(widget.cardTitle),
                            Spacer(),
                            ButtonBar(
                              children: <Widget>[
                                new IconButton(
                                  icon: Icon(CardsIcons.arrows_ccw, color: primaryDark,),
                                  onPressed: () {_refresh();},
                                ),
                                new IconButton(
                                  icon: Icon(CardsIcons.heart_empty, color: Colors.redAccent,),
                                  onPressed: () {_bookmark();},
                                ),
                              ],
                            ),
                            SizedBox(height: 24.0,),
                          ],
                        ),
                        Container(
                          child: Text(
                            widget.cardContent,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          );
        }
    

    【讨论】:

    猜你喜欢
    • 2021-08-08
    • 2021-09-01
    • 2019-10-31
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多