Skip to content

Commit

Permalink
fix: Add maximum width to UniversalListView.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Mar 13, 2023
1 parent 13a0d9c commit a057c77
Showing 1 changed file with 50 additions and 27 deletions.
77 changes: 50 additions & 27 deletions packages/masamune/lib/universal/universal_list_view.dart
Expand Up @@ -71,6 +71,7 @@ class UniversalListView extends StatelessWidget {
this.paddingWhenNotFullWidth,
this.crossAxisAlignment = CrossAxisAlignment.start,
this.rowSegments = 12,
this.maxWidth,
this.padding,
}) : assert(
!(controller != null && primary == true),
Expand All @@ -90,6 +91,11 @@ class UniversalListView extends StatelessWidget {
? const AlwaysScrollableScrollPhysics()
: null);

/// Maximum width.
///
/// 最大の横幅。
final double? maxWidth;

/// Method called by [RefreshIndicator].
///
/// Pull-to-Refresh will execute and display an indicator until [Future] is returned.
Expand Down Expand Up @@ -185,36 +191,39 @@ class UniversalListView extends StatelessWidget {
context,
_buildScrollbar(
context,
_buildDecoratedBox(
_buildConstrainedBox(
context,
CustomScrollView(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
controller: controller,
primary: primary,
physics: physics,
scrollBehavior: scrollBehavior,
shrinkWrap: shrinkWrap,
center: center,
anchor: anchor,
cacheExtent: cacheExtent,
semanticChildCount: semanticChildCount,
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior,
restorationId: restorationId,
clipBehavior: clipBehavior,
slivers: [
_padding(
context,
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => rows[i],
childCount: rows.length,
_buildDecoratedBox(
context,
CustomScrollView(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
controller: controller,
primary: primary,
physics: physics,
scrollBehavior: scrollBehavior,
shrinkWrap: shrinkWrap,
center: center,
anchor: anchor,
cacheExtent: cacheExtent,
semanticChildCount: semanticChildCount,
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior,
restorationId: restorationId,
clipBehavior: clipBehavior,
slivers: [
_padding(
context,
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => rows[i],
childCount: rows.length,
),
),
),
),
],
],
),
),
),
),
Expand Down Expand Up @@ -307,6 +316,20 @@ class UniversalListView extends StatelessWidget {
}
}

Widget _buildConstrainedBox(BuildContext context, Widget child) {
if (maxWidth != null) {
return Align(
alignment: Alignment.center,
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth!),
child: child,
),
);
} else {
return child;
}
}

Widget _padding(BuildContext context, Widget sliver) {
final width = MediaQuery.of(context).size.width;
final breakpoint = UniversalScaffold.of(context)?.breakpoint;
Expand Down

0 comments on commit a057c77

Please sign in to comment.