flutter : 如何在颤动中制作卡片

Posted

技术标签:

【中文标题】flutter : 如何在颤动中制作卡片【英文标题】:flutter : How to make Card in flutter 【发布时间】:2021-09-29 13:09:41 【问题描述】:

我想制作这样的卡片。

谁能帮帮我。

【问题讨论】:

你应该使用 ListTile Widget 和你的设计一样 @RavindraS.Patil 但是如何添加名称、日期等所有字段 您可能想仔细查看卡片小部件:api.flutter.dev/flutter/material/Card-class.html 你可以学到一些东西然后你就知道了how toflutter.dev/docs/development/ui/layout/tutorial 【参考方案1】:

我通过使用“卡片”小部件实现了您的要求。

/// Flutter code sample for Card

// This sample shows creation of a [Card] widget that shows album information
// and two actions.

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

/// This is the main application widget.
class MyApp extends StatelessWidget 
  const MyApp(Key key) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) 
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const MyStatelessWidget(),
      ),
    );
  


/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget 
  const MyStatelessWidget(Key key) : super(key: key);

  @override
  Widget build(BuildContext context) 
    return Center(
      child: Card(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              padding: EdgeInsets.symmetric(horizontal: 20),
              decoration: BoxDecoration(
                border: Border(
                  right: BorderSide(color: Colors.black, width: 1),
                ),
              ),
              child: Icon(Icons.album),
            ),
            Expanded(
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text('Name'),
                        Text('Price'),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text('Date'),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text('Quantity: 3'),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text('Total Amount'),
                        Text('Rs. 253'),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  


【讨论】:

【参考方案2】:

这是主应用程序实例化的无状态小部件。

class MyCardWidget extends StatelessWidget  
  MyCardWidget(Key key) : super(key: key);  

更多:https://www.javatpoint.com/flutter-card

【讨论】:

以上是关于flutter : 如何在颤动中制作卡片的主要内容,如果未能解决你的问题,请参考以下文章

如何使卡片像颤动的标签一样可滑动? [复制]

如何在颤动中从另一个屏幕进行更改

如何在 Flutter 中制作带有标题的多张卡片列表

颤动布局中的卡片视图

卡片宽度与父级匹配:颤动

如何在颤动中制作具有多种颜色的ColorTween动画