简体   繁体   English

Flutter 如何只给一个容器边框底部

[英]Flutter How to give a Container border bottom only

In Flutter how to set a border for the bottom only,在 Flutter 如何只为底部设置边框,

As shown in the picture below, I have a Container with Text, showing a red color border from the bottom, Kindly guide how to set a border from the bottom only.如下图所示,我有一个带有文本的容器,从底部显示红色边框,请指导如何仅从底部设置边框。

在此处输入图像描述

Use Border with the bottom argument.Borderbottom参数一起使用。

Container(
          decoration: BoxDecoration(
            Border(
              bottom: BorderSide(width: 1.5, color: Colors.grey[300]),
            ),
          ),
          child: ListTile(
            title: Text(title),
            subtitle: Text(score + dateFormatted),
            trailing: Row(
              mainAxisSize: MainAxisSize.min,
                 children: [
                    Text(amount),
                    Checkbox(
                       value: false,
                       activeColor: Colors.green,
                       onChanged: (bool newValue) {}),
                    ],
                   ),
           ),
);

better to use ListView.separator constructor最好使用ListView.separator构造函数

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(debugShowCheckedModeBanner: false, home: Home()));

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) => Scaffold(body: Demo());
}

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      itemCount: 42,
      separatorBuilder: (_, __) => Container(height: 1.5, color: Colors.grey[300]),
      itemBuilder: (context, index) {
        return ListTile(
          title: Text('item $index'),
        );
      },
    );
  }
}

在此处输入图像描述

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

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