Horizontal divider with text in the middle in Flutter? Horizontal divider with text in the middle in Flutter? flutter flutter

Horizontal divider with text in the middle in Flutter?


You can try to use the Row widget.

Row(    children: <Widget>[        Expanded(            child: Divider()        ),               Text("OR"),                Expanded(            child: Divider()        ),    ])


Example Implementation of a divider with Text

To expand on Jerome's answer - Here is an example that shows how to embed it with other content and also has additional edgeinsets for coming closer to the actual picture that you want:

          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 ")],            ),          ])


There is no flutter widget that do this, I created on for myself.You can do it like this

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

The usage will be:

HorizontalOrLine(height: 10,label: "OR")