简体   繁体   English

RoundedRectangleBorder 不适用于 flutter 中的 ListTile 或 Card

[英]RoundedRectangleBorder not working with ListTile nor Card in flutter

I have this custom function that returns a card containing ListTile.我有这个自定义的 function,它返回一张包含 ListTile 的卡片。 I'm having some trouble with styling.我在造型上遇到了一些麻烦。 I want to apply rounded corners either to card or ListTile (I just want rounded corners) as below.我想将圆角应用于卡片或 ListTile(我只想要圆角),如下所示。 It didn't work with me.它对我不起作用。

I tried to apply cardTheme to all cards in a customized theme in a separate file but doesn't work, also in my code underneath I wanted the card to be colored blue at the moment the user presses and the default ripple effect to show but couldn't.我尝试将 cardTheme 应用于单独文件中自定义主题中的所有卡片但不起作用,在我下面的代码中,我希望卡片在用户按下时显示为蓝色,并显示默认的波纹效果但不能不。 Also couldn't apply blue border around the card.也无法在卡片周围应用蓝色边框。 something is going wrong with my styling我的造型出了点问题

Card myCardListTile(MyScreen myScreen, BuildContext context) {
return Card(
  child: ListTile(
    contentPadding: EdgeInsets.all(10),
    shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(18.0),
        side: BorderSide(color: kColorOxfordBlue, width: 12)),
    // focusColor: kColorOxfordBlue,
    // hoverColor: kColorOxfordBlue,
    onTap: () {
      Navigator.pushNamed(context, myScreen.route);
    },
    title: Text(
      myScreen.title,
      style: Theme.of(context).textTheme.headline6,
      // TextStyle(),
    ),
  ),
);


Class AppTheme {  
static final ThemeData lightTheme = ThemeData(
  cardTheme: CardTheme(
  shape: RoundedRectangleBorder(borderRadius:   BorderRadius.circular(18.0)),
),
);}

and in the main.dart I used AppTheme.lightTheme在 main.dart 我使用了 AppTheme.lightTheme

return MaterialApp(
  theme: AppTheme.lightTheme,
  // code

Is it mandatory to use list view?是否必须使用列表视图? cause you can use other widgets like container inside card with rounded corners.因为您可以使用其他小部件,例如带有圆角的卡片内的容器。 For example例如

return Card(
  elevation: 10.0,
  color: Colors.blue,
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(15.0),
  ),
  child: Container(
    padding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 8.0),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Text('something here'),
        SizedBox(width: 4.0),
        Text('something other here'),
      ],
    ),
  ),
);

You can customize container as per your need, hope it helps..您可以根据需要自定义容器,希望对您有所帮助..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM