Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YaruSection: sort out margin vs. padding etc. #380

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions example/lib/pages/carousel_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class _CarouselPageState extends State<CarouselPage> {
navigationControls: true,
),
),
const SizedBox(height: 20),
YaruSection(
headline: const Text('Auto scroll: on'),
width: 700,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/section_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class _SectionPageState extends State<SectionPage> {
padding: const EdgeInsets.all(kYaruPagePadding),
children: [
const DummySection(width: kMinSectionWidth),
const SizedBox(height: 20),
YaruSection(
width: kMinSectionWidth,
child: Column(
Expand Down
77 changes: 37 additions & 40 deletions lib/src/pages/yaru_section.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import '../constants.dart';
import '../utilities/yaru_border_container.dart';

class YaruSection extends StatelessWidget {
/// Creates a yaru style section widget with multiple
Expand All @@ -9,8 +9,10 @@ class YaruSection extends StatelessWidget {
this.headline,
required this.child,
this.width,
this.height,
this.headerWidget,
this.padding = const EdgeInsets.only(bottom: 20.0),
this.padding = const EdgeInsets.all(8.0),
this.margin,
});

/// Widget that is placed above the list of `children`.
Expand All @@ -19,59 +21,54 @@ class YaruSection extends StatelessWidget {
/// The child widget inside the section.
final Widget child;

/// Specifies the [width] of the [Container].
/// By default the width will be 500.
/// Specifies the [width] of the section.
final double? width;

/// 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 [EdgeInsets] which defaults to `EdgeInsets.only(bottom: 20.0)`.
/// The padding between the section border and its [child] which defaults to
/// `EdgeInsets.only(all: 8.0)`.
final EdgeInsets padding;

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

@override
Widget build(BuildContext context) {
return Padding(
return YaruBorderContainer(
width: width,
height: height,
padding: padding,
child: SizedBox(
width: width,
child: Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.15),
),
borderRadius: const BorderRadius.all(
Radius.circular(kYaruContainerRadius),
),
),
child: Column(
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()
],
),
),
margin: margin,
child: Column(
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()
],
),
child,
],
),
),
),
child,
],
),
);
}
Expand Down