|
@@ -1,3 +1,5 @@
|
|
|
+import 'dart:math';
|
|
|
+
|
|
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flowy_infra/theme.dart';
|
|
@@ -19,46 +21,55 @@ class ListOverlay extends StatelessWidget {
|
|
|
const ListOverlay({
|
|
|
Key? key,
|
|
|
required this.itemBuilder,
|
|
|
- this.itemCount,
|
|
|
+ this.itemCount = 0,
|
|
|
this.controller,
|
|
|
- this.width = double.infinity,
|
|
|
- this.height = double.infinity,
|
|
|
+ this.constraints = const BoxConstraints(),
|
|
|
this.footer,
|
|
|
}) : super(key: key);
|
|
|
|
|
|
final IndexedWidgetBuilder itemBuilder;
|
|
|
- final int? itemCount;
|
|
|
+ final int itemCount;
|
|
|
final ScrollController? controller;
|
|
|
- final double width;
|
|
|
- final double height;
|
|
|
+ final BoxConstraints constraints;
|
|
|
final ListOverlayFooter? footer;
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
const padding = EdgeInsets.symmetric(horizontal: 6, vertical: 6);
|
|
|
- double totalHeight = height + padding.vertical;
|
|
|
+ double totalHeight = constraints.minHeight + padding.vertical;
|
|
|
if (footer != null) {
|
|
|
totalHeight = totalHeight + footer!.height + footer!.padding.vertical;
|
|
|
}
|
|
|
|
|
|
+ final innerConstraints = BoxConstraints(
|
|
|
+ minHeight: totalHeight,
|
|
|
+ maxHeight: max(constraints.maxHeight, totalHeight),
|
|
|
+ minWidth: constraints.minWidth,
|
|
|
+ maxWidth: constraints.maxWidth,
|
|
|
+ );
|
|
|
+
|
|
|
+ List<Widget> children = [];
|
|
|
+ for (var i = 0; i < itemCount; i++) {
|
|
|
+ children.add(itemBuilder(context, i));
|
|
|
+ }
|
|
|
+
|
|
|
return OverlayContainer(
|
|
|
- constraints: BoxConstraints.tight(Size(width, totalHeight)),
|
|
|
+ constraints: innerConstraints,
|
|
|
padding: padding,
|
|
|
child: SingleChildScrollView(
|
|
|
- child: Column(
|
|
|
- children: [
|
|
|
- ListView.builder(
|
|
|
- shrinkWrap: true,
|
|
|
- itemBuilder: itemBuilder,
|
|
|
- itemCount: itemCount,
|
|
|
- controller: controller,
|
|
|
- ),
|
|
|
- if (footer != null)
|
|
|
- Padding(
|
|
|
- padding: footer!.padding,
|
|
|
- child: footer!.widget,
|
|
|
- ),
|
|
|
- ],
|
|
|
+ scrollDirection: Axis.horizontal,
|
|
|
+ child: IntrinsicWidth(
|
|
|
+ child: Column(
|
|
|
+ mainAxisSize: MainAxisSize.min,
|
|
|
+ children: [
|
|
|
+ ...children,
|
|
|
+ if (footer != null)
|
|
|
+ Padding(
|
|
|
+ padding: footer!.padding,
|
|
|
+ child: footer!.widget,
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
),
|
|
|
),
|
|
|
);
|
|
@@ -68,10 +79,9 @@ class ListOverlay extends StatelessWidget {
|
|
|
BuildContext context, {
|
|
|
required String identifier,
|
|
|
required IndexedWidgetBuilder itemBuilder,
|
|
|
- int? itemCount,
|
|
|
+ int itemCount = 0,
|
|
|
ScrollController? controller,
|
|
|
- double width = double.infinity,
|
|
|
- double height = double.infinity,
|
|
|
+ BoxConstraints constraints = const BoxConstraints(),
|
|
|
required BuildContext anchorContext,
|
|
|
AnchorDirection? anchorDirection,
|
|
|
FlowyOverlayDelegate? delegate,
|
|
@@ -85,8 +95,7 @@ class ListOverlay extends StatelessWidget {
|
|
|
itemBuilder: itemBuilder,
|
|
|
itemCount: itemCount,
|
|
|
controller: controller,
|
|
|
- width: width,
|
|
|
- height: height,
|
|
|
+ constraints: constraints,
|
|
|
footer: footer,
|
|
|
),
|
|
|
identifier: identifier,
|
|
@@ -122,7 +131,9 @@ class OverlayContainer extends StatelessWidget {
|
|
|
child: Container(
|
|
|
padding: padding,
|
|
|
decoration: FlowyDecoration.decoration(
|
|
|
- theme.surface, theme.shadowColor.withOpacity(0.15)),
|
|
|
+ theme.surface,
|
|
|
+ theme.shadowColor.withOpacity(0.15),
|
|
|
+ ),
|
|
|
constraints: constraints,
|
|
|
child: child,
|
|
|
),
|