Skip to content

Commit

Permalink
YaruSection: simplify headline & remove headerWidget (#381)
Browse files Browse the repository at this point in the history
* YaruSection: replace headline & headerWidget with a single title widget

It's easy enough to wrap stuff into a Row when needed, and then you'll
have full control over the main & cross axis alignment etc. ;-)

* Rename title back to headline
  • Loading branch information
jpnurmi committed Nov 11, 2022
1 parent f980bda commit 8c21ea0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
15 changes: 10 additions & 5 deletions example/lib/pages/section_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ class DummySection extends StatelessWidget {
@override
Widget build(BuildContext context) {
return YaruSection(
headline: const Text('Headline'),
headerWidget: const SizedBox(
child: YaruCircularProgressIndicator(strokeWidth: 3),
height: 20,
width: 20,
headline: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Text('Headline'),
SizedBox(
child: YaruCircularProgressIndicator(strokeWidth: 3),
height: 20,
width: 20,
)
],
),
child: const YaruTile(
title: Text('Title'),
Expand Down
38 changes: 13 additions & 25 deletions lib/src/pages/yaru_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class YaruSection extends StatelessWidget {
required this.child,
this.width,
this.height,
this.headerWidget,
this.padding = const EdgeInsets.all(8.0),
this.headlinePadding = const EdgeInsets.all(8.0),
this.margin,
});

/// Widget that is placed above the list of `children`.
/// Widget that is placed above the `child`.
final Widget? headline;

/// The child widget inside the section.
Expand All @@ -27,16 +27,13 @@ class YaruSection extends StatelessWidget {
/// Specifies the [height] of the section.
final double? height;

/// Aligns the widget horizontally along with headline.
///
/// Both `headline` and `headerWidget` will be aligned horizontally
/// with [mainAxisAlignment] as [MainAxisAlignment.spaceBetween].
final Widget? headerWidget;

/// The padding between the section border and its [child] which defaults to
/// `EdgeInsets.only(all: 8.0)`.
/// `EdgeInsets.all(8.0)`.
final EdgeInsets padding;

/// The padding around the [headline] which defaults to `EdgeInsets.all(8.0)`.
final EdgeInsets headlinePadding;

/// An optional margin around the section border.
final EdgeInsets? margin;

Expand All @@ -48,25 +45,16 @@ class YaruSection extends StatelessWidget {
padding: padding,
margin: margin,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.all(headline != null ? 8.0 : 0),
child: Align(
alignment: Alignment.topLeft,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (headline != null)
DefaultTextStyle(
style: Theme.of(context).textTheme.titleLarge!,
textAlign: TextAlign.left,
child: headline!,
),
headerWidget ?? const SizedBox()
],
if (headline != null)
Padding(
padding: headlinePadding,
child: DefaultTextStyle(
style: Theme.of(context).textTheme.titleLarge!,
child: headline!,
),
),
),
child,
],
),
Expand Down

0 comments on commit 8c21ea0

Please sign in to comment.