在Flutter中间有文字的水平分隔线?

Dec*_*che 11 user-interface dart material-design flutter

Flutter中是否有一个内置的小部件来创建一个中间有文本的分隔符?关于如何做的任何指南?像这样:(水平线中间的"OR"文字)

这是我想要实现的截图

Jer*_*nte 34

您可以尝试使用Row小部件.

Row(
    children: <Widget>[
        Expanded(
            child: Divider()
        ),       

        Text("OR"),        

        Expanded(
            child: Divider()
        ),
    ]
)
Run Code Online (Sandbox Code Playgroud)


Osw*_*ann 10

带文本的除法器的示例实现

扩展Jerome的答案-这是一个示例,展示了如何将其与其他内容嵌入在一起,并且还具有其他边缘插入物,以使其更接近所需的实际图片:

          Column(children: <Widget>[
            Row(
              children: <Widget>[Text("above")],
            ),
            Row(children: <Widget>[
              Expanded(
                child: new Container(
                    margin: const EdgeInsets.only(left: 10.0, right: 20.0),
                    child: Divider(
                      color: Colors.black,
                      height: 36,
                    )),
              ),
              Text("OR"),
              Expanded(
                child: new Container(
                    margin: const EdgeInsets.only(left: 20.0, right: 10.0),
                    child: Divider(
                      color: Colors.black,
                      height: 36,
                    )),
              ),
            ]),
            Row(
              children: <Widget>[Text("below ")],
            ),
          ])
Run Code Online (Sandbox Code Playgroud)


AMA*_*N N 10

我对此做了一些美化,代码如下

Row(
   mainAxisAlignment: MainAxisAlignment.center,
   children: const [
                     Expanded(
                       child: Divider(
                                indent: 20.0,
                                endIndent: 10.0,
                                thickness: 1,
                              ),
                     ),
                     Text(
                          "OR",
                          style: TextStyle(color: Colors.blueGrey),
                     ),
                     Expanded(
                          child: Divider(
                                  indent: 10.0,
                                  endIndent: 20.0,
                                  thickness: 1,
                          ),
                      ),
                ],
),
Run Code Online (Sandbox Code Playgroud)


小智 6

没有 Flutter 小部件可以做到这一点,这是我为自己创建的。你可以这样做

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class HorizontalOrLine extends StatelessWidget {
  const HorizontalOrLine({
    this.label,
    this.height,
  });

  final String label;
  final double height;

  @override
  Widget build(BuildContext context) {

    return Row(children: <Widget>[
      Expanded(
        child: new Container(
            margin: const EdgeInsets.only(left: 10.0, right: 15.0),
            child: Divider(
              color: Colors.black,
              height: height,
            )),
      ),

      Text(label),

      Expanded(
        child: new Container(
            margin: const EdgeInsets.only(left: 15.0, right: 10.0),
            child: Divider(
              color: Colors.black,
              height: height,
            )),
      ),
    ]);
  }
}
Run Code Online (Sandbox Code Playgroud)

用法将是:

HorizontalOrLine(height: 10,label: "OR")
Run Code Online (Sandbox Code Playgroud)