提问者:小点点

RoundedRectangleBorder不能与flutter中的ListTile或Card一起工作


我有一个自定义函数,它返回一个包含listtile的卡片。我的造型有点麻烦。我想应用圆角要么卡或ListTile(我只想圆角)如下。对我没用。

我尝试将cardTheme应用到一个单独文件中的定制主题中的所有卡片,但不起作用,而且在我下面的代码中,我希望卡片在用户按下的瞬间被染成蓝色,并且显示默认的涟漪效果,但不能。也不能在卡片周围应用蓝色边框。我的造型出问题了

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)),
),
);}

在Main.Dart中我使用了AppTheme.LightTheme

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

共1个答案

匿名用户

是否强制使用列表视图?因为您可以使用其他小部件,如容器内部的卡与圆角。例如:

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'),
      ],
    ),
  ),
);

您可以根据您的需要定制容器,希望对您有帮助…