102 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Dart
		
	
	
			
		
		
	
	
			102 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Dart
		
	
	
import 'package:flutter/material.dart';
 | 
						|
 | 
						|
/// Created by @Haoyi on 4/15/21
 | 
						|
 | 
						|
 | 
						|
class HorizontalDivider extends StatelessWidget {
 | 
						|
  /// Creates a material design vertical divider.
 | 
						|
  ///
 | 
						|
  /// The [height], [thickness], [indent], and [endIndent] must be null or
 | 
						|
  /// non-negative.
 | 
						|
  const HorizontalDivider({
 | 
						|
    Key? key,
 | 
						|
    this.height,
 | 
						|
    this.thickness,
 | 
						|
    this.indent,
 | 
						|
    this.endIndent,
 | 
						|
    this.color,
 | 
						|
    this.bgColor,
 | 
						|
  })  : assert(height == null || height >= 0.0),
 | 
						|
        assert(thickness == null || thickness >= 0.0),
 | 
						|
        assert(indent == null || indent >= 0.0),
 | 
						|
        assert(endIndent == null || endIndent >= 0.0),
 | 
						|
        super(key: key);
 | 
						|
 | 
						|
  /// The divider's width.
 | 
						|
  ///
 | 
						|
  /// The divider itself is always drawn as a vertical line that is centered
 | 
						|
  /// within the width specified by this value.
 | 
						|
  ///
 | 
						|
  /// If this is null, then the [DividerThemeData.space] is used. If that is
 | 
						|
  /// also null, then this defaults to 16.0.
 | 
						|
  final double? height;
 | 
						|
 | 
						|
  /// The thickness of the line drawn within the divider.
 | 
						|
  ///
 | 
						|
  /// A divider with a [thickness] of 0.0 is always drawn as a line with a
 | 
						|
  /// width of exactly one device pixel.
 | 
						|
  ///
 | 
						|
  /// If this is null, then the [DividerThemeData.thickness] is used which
 | 
						|
  /// defaults to 0.0.
 | 
						|
  final double? thickness;
 | 
						|
 | 
						|
  /// The amount of empty space on top of the divider.
 | 
						|
  ///
 | 
						|
  /// If this is null, then the [DividerThemeData.indent] is used. If that is
 | 
						|
  /// also null, then this defaults to 0.0.
 | 
						|
  final double? indent;
 | 
						|
 | 
						|
  /// The amount of empty space under the divider.
 | 
						|
  ///
 | 
						|
  /// If this is null, then the [DividerThemeData.endIndent] is used. If that is
 | 
						|
  /// also null, then this defaults to 0.0.
 | 
						|
  final double? endIndent;
 | 
						|
 | 
						|
  /// The color to use when painting the line.
 | 
						|
  ///
 | 
						|
  /// If this is null, then the [DividerThemeData.color] is used. If that is
 | 
						|
  /// also null, then [ThemeData.dividerColor] is used.
 | 
						|
  ///
 | 
						|
  /// {@tool snippet}
 | 
						|
  ///
 | 
						|
  /// ```dart
 | 
						|
  /// Divider(
 | 
						|
  ///   color: Colors.deepOrange,
 | 
						|
  /// )
 | 
						|
  /// ```
 | 
						|
  /// {@end-tool}
 | 
						|
  final Color? color;
 | 
						|
 | 
						|
  final Color? bgColor;
 | 
						|
 | 
						|
  @override
 | 
						|
  Widget build(BuildContext context) {
 | 
						|
    final DividerThemeData dividerTheme = DividerTheme.of(context);
 | 
						|
    final double height = this.height ?? dividerTheme.space ?? 16.0;
 | 
						|
    final double thickness = this.thickness ?? dividerTheme.thickness ?? 0.0;
 | 
						|
    final double indent = this.indent ?? dividerTheme.indent ?? 0.0;
 | 
						|
    final double endIndent = this.endIndent ?? dividerTheme.endIndent ?? 0.0;
 | 
						|
    final Color bgColor = this.bgColor ?? Colors.transparent;
 | 
						|
 | 
						|
    return SizedBox(
 | 
						|
      width: double.infinity,
 | 
						|
      height: height,
 | 
						|
      child: Center(
 | 
						|
        child: Container(
 | 
						|
          height: thickness,
 | 
						|
          padding: EdgeInsetsDirectional.only(start: indent, end: endIndent),
 | 
						|
          color: bgColor,
 | 
						|
          child: Container(
 | 
						|
            height: thickness,
 | 
						|
            decoration: BoxDecoration(
 | 
						|
              border: Border(
 | 
						|
                top: Divider.createBorderSide(context, color: color, width: thickness),
 | 
						|
              ),
 | 
						|
            ),
 | 
						|
          ),
 | 
						|
        ),
 | 
						|
      ),
 | 
						|
    );
 | 
						|
  }
 | 
						|
}
 |