Custom Card Shape Flutter SDK

前端 未结 4 1718
迷失自我
迷失自我 2021-01-30 12:10

I just started learning Flutter and I have developed an app with GridView. GridView items are Card. Default card shape is Rectangle with a radius of 4.

I know there is s

相关标签:
4条回答
  • 2021-01-30 12:44

    When Card I always use RoundedRectangleBorder.

    Card(
      color: Colors.grey[900],
      shape: RoundedRectangleBorder(
        side: BorderSide(color: Colors.white70, width: 1),
        borderRadius: BorderRadius.circular(10),
      ),
      margin: EdgeInsets.all(20.0),
      child: Container(
        child: Column(
            children: <Widget>[
            ListTile(
                title: Text(
                'example',
                style: TextStyle(fontSize: 18, color: Colors.white),
                ),
            ),
            ],
        ),
      ),
    ),
    
    0 讨论(0)
  • 2021-01-30 12:44

    You can also customize the card theme globally with ThemeData.cardTheme:

    MaterialApp(
      title: 'savvy',
      theme: ThemeData(
        cardTheme: CardTheme(
          shape: RoundedRectangleBorder(
            borderRadius: const BorderRadius.all(
              Radius.circular(8.0),
            ),
          ),
        ),
        // ...
    
    0 讨论(0)
  • 2021-01-30 12:44

    An Alternative Solution to the above

    Card(
      shape: RoundedRectangleBorder(
         borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20))),
      color: Colors.white,
      child: ...
    )
    

    You can use BorderRadius.only() to customize the corners you wish to manage.

    0 讨论(0)
  • You can use it this way

    Card(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(15.0),
      ),
      child: Text(
        'Card with circular border',
        textScaleFactor: 1.2,
      ),
    ),
    Card(
      shape: BeveledRectangleBorder(
        borderRadius: BorderRadius.circular(10.0),
      ),
      child: Text(
        'Card with Beveled border',
        textScaleFactor: 1.2,
      ),
    ),
    Card(
      shape: StadiumBorder(
      side: BorderSide(
        color: Colors.black,
        width: 2.0,
      ),
    ),
      child: Text(
        'Card with Beveled border',
        textScaleFactor: 1.2,
      ),
    ),
    
    0 讨论(0)
提交回复
热议问题