-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix PR issues * WIP separator * Adjust separator default values * Tweak separator even more * Tidy up separator implementation * Commit from GitHub Actions (Forui Presubmit) * Fix PR issues * Add global border width --------- Co-authored-by: Pante <[email protected]>
- Loading branch information
Showing
7 changed files
with
147 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
import 'package:forui/forui.dart'; | ||
|
||
/// A separator visually separates content. | ||
final class FSeparator extends StatelessWidget { | ||
|
||
/// The style. | ||
final FSeparatorStyle? style; | ||
|
||
/// Whether this separator should be horizontal or vertical. Defaults to horizontal (false). | ||
final bool vertical; | ||
|
||
/// Creates a [FSeparator]. | ||
const FSeparator({this.style, this.vertical = false, super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final style = this.style ?? (vertical ? context.theme.separatorStyles.vertical : context.theme.separatorStyles.horizontal); | ||
return Padding( | ||
padding: style.padding, | ||
child: vertical ? | ||
SizedBox( | ||
width: style.width, | ||
child: ColoredBox( | ||
color: style.color, | ||
), | ||
) : | ||
SizedBox( | ||
height: style.width, | ||
child: ColoredBox( | ||
color: style.color, | ||
), | ||
), | ||
); | ||
} | ||
|
||
} | ||
|
||
/// [FSeparator]'s style. | ||
final class FSeparatorStyle with Diagnosticable { | ||
|
||
/// The default padding for horizontal and vertical separators. | ||
static const defaultPadding = ( | ||
horizontal: EdgeInsets.symmetric(vertical: 20), | ||
vertical: EdgeInsets.symmetric(horizontal: 20), | ||
); | ||
|
||
/// The color of the separating line. Defaults to [FColorScheme.secondary]. | ||
final Color color; | ||
|
||
/// The padding surrounding the separating line. | ||
final EdgeInsetsGeometry padding; | ||
|
||
/// The width of the separating line. Defaults to 1. | ||
/// | ||
/// ## Contract: | ||
/// Throws an [AssertionError] if: | ||
/// * `width` <= 0.0 | ||
/// * `width` is Nan | ||
final double width; | ||
|
||
/// Creates a [FSeparatorStyle]. | ||
FSeparatorStyle({required this.color, required this.padding, this.width = 1}): | ||
assert(0 < width, 'The width is $width, but it should be in the range "0 < width".'); | ||
|
||
/// Creates a [FCardContentStyle] that inherits its properties from [colorScheme]. | ||
FSeparatorStyle.inherit({required FColorScheme colorScheme, required FStyle style, required EdgeInsetsGeometry padding}): | ||
this(color: colorScheme.secondary, padding: padding, width: style.borderWidth); | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is FSeparatorStyle && | ||
runtimeType == other.runtimeType && | ||
color == other.color && | ||
padding == other.padding && | ||
width == other.width; | ||
|
||
@override | ||
int get hashCode => color.hashCode ^ padding.hashCode ^ width.hashCode; | ||
|
||
} |