Skip to content

Commit

Permalink
Add CenterOrScroll
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Jan 24, 2023
1 parent 1f6f9d8 commit f52667c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/black_hole_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export 'src/navigation.dart';
export 'src/render_object.dart';
export 'src/size.dart';
export 'src/widgets/buttons.dart';
export 'src/widgets/expand_or_scroll.dart';
export 'src/widgets/fill_or_wrap.dart';
export 'src/widgets/or_scroll.dart';
export 'src/widgets/title_and_subtitle.dart';
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
import 'package:flutter/widgets.dart';

/// Centers [child] if it's smaller than the parent and makes it scrollable
/// along [scrollDirection] if it's taller.
class CenterOrScroll extends StatelessWidget {
const CenterOrScroll({
super.key,
this.wrapInSafeArea = true,
this.padding = EdgeInsets.zero,
this.scrollDirection = Axis.vertical,
this.scrollController,
required this.child,
});

final bool wrapInSafeArea;
final EdgeInsets padding;
final Axis scrollDirection;
final ScrollController? scrollController;
final Widget child;

@override
Widget build(BuildContext context) {
var child = this.child;

if (wrapInSafeArea) child = SafeArea(child: child);

child = SingleChildScrollView(
padding: padding,
scrollDirection: scrollDirection,
controller: scrollController,
child: child,
);

return Center(child: _intrinsicAlongAxis(scrollDirection, child));
}
}

class ExpandOrScroll extends StatelessWidget {
const ExpandOrScroll({
super.key,
Expand Down

0 comments on commit f52667c

Please sign in to comment.