Skip to content

Commit d9f1be0

Browse files
committed
Miscellaneous fixes
- Enable scrolling for expanded frames with special conditions for child. - Fix ClipRect as SingleChildScrollView child not being merge swept. - Don't use alignment on container from the child in codegen if it is scrollable. - Fix image always using fixed sizes. - Removed fixed width/height with a SizedBox around SingleChildScrollView. - Don't wrap a stack child with Align widget if it is scrollable. - Fix scrollable property enable/disable conditions to allow proper scrolling in some special cases.
1 parent e908888 commit d9f1be0

File tree

5 files changed

+130
-46
lines changed

5 files changed

+130
-46
lines changed

lib/src/transformers/node_transformers/passive_rectangle_transformer.dart

+15-15
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,11 @@ List<Widget> wrapWithPaddingAndScroll(
223223
node: node,
224224
padding: applyPadding ? resolvedPadding : null,
225225
clipBehavior: defaultGetClipBehavior(node),
226-
child: SizedBox(
227-
width: node.scrollDirection.isHorizontal
228-
? node.outerBoxLocal.width
229-
: null,
230-
height: node.scrollDirection.isVertical
231-
? node.outerBoxLocal.height
232-
: null,
233-
child: Stack(
234-
clipBehavior: Clip.none,
235-
alignment: stackAlignment.flutterAlignment ??
236-
AlignmentDirectional.topStart,
237-
children: children,
238-
),
226+
child: Stack(
227+
clipBehavior: Clip.none,
228+
alignment:
229+
stackAlignment.flutterAlignment ?? AlignmentDirectional.topStart,
230+
children: children,
239231
),
240232
),
241233
];
@@ -565,8 +557,16 @@ List<Widget> buildFills(
565557
} else {
566558
child = UltimateImageBuilder(
567559
url: imageURL,
568-
width: node.basicBoxLocal.width,
569-
height: node.basicBoxLocal.height,
560+
width: (node.horizontalFit == SizeFit.shrinkWrap)
561+
? null
562+
: (node.horizontalFit == SizeFit.expanded)
563+
? double.infinity
564+
: node.basicBoxLocal.width,
565+
height: (node.verticalFit == SizeFit.shrinkWrap)
566+
? null
567+
: (node.verticalFit == SizeFit.expanded)
568+
? double.infinity
569+
: node.basicBoxLocal.height,
570570
paint: paint,
571571
node: node,
572572
bytes: bytes,

lib/src/transformers/node_transformers/passive_stack_transformer.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class PassiveStackTransformer extends NodeWidgetTransformer<BaseNode> {
3232
isTallest: tallestChild?.id == node.id,
3333
);
3434
} else {
35-
if (node.alignment != commonAlignment) {
35+
if (node.alignment != commonAlignment &&
36+
(node is! ScrollableMixin || !node.isScrollable)) {
3637
child = Align(
3738
alignment: node.alignment.flutterAlignment!,
3839
child: child,

lib/src/utils/extensions.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ extension CCrossAxisAlignmentHelper on CrossAxisAlignmentC {
470470
}
471471
}
472472

473-
extension CAxisHelper on AxisC {
473+
extension AxisHelperExt on AxisC {
474474
flutter.Axis get flutterAxis => this == AxisC.horizontal
475475
? flutter.Axis.horizontal
476476
: flutter.Axis.vertical;

lib/src/utils/image_builder.dart

+50-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:cached_network_image/cached_network_image.dart';
22
import 'package:codelessly_api/codelessly_api.dart';
3+
import 'package:flutter/foundation.dart';
34
import 'package:flutter/material.dart';
45
import 'package:flutter_svg/svg.dart';
56
import 'package:google_fonts/google_fonts.dart';
@@ -43,14 +44,39 @@ class UltimateImageBuilder extends StatefulWidget {
4344
this.node,
4445
this.blendMode,
4546
this.useInk = false,
46-
}) : assert(url != null || bytes != null || paint != null,
47-
'url or bytes or paint must be provided'),
48-
assert(
47+
}) : assert(url != null || bytes != null || paint != null,
48+
'url or bytes or paint must be provided')
49+
/*assert(
4950
paint == null || (width != null && height != null && node != null),
50-
'width, height and node must be provided when paint is provided');
51+
'width, height and node must be provided when paint is provided')*/
52+
;
5153

5254
@override
5355
State<UltimateImageBuilder> createState() => _UltimateImageBuilderState();
56+
57+
@override
58+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
59+
properties.add(StringProperty('url', url));
60+
properties.add(DiagnosticsProperty<TypedBytes>('bytes', bytes));
61+
properties.add(EnumProperty<BoxFit>('fit', fit));
62+
properties.add(DiagnosticsProperty<Alignment>('alignment', alignment));
63+
properties.add(DoubleProperty('scale', scale));
64+
properties.add(DoubleProperty('width', width));
65+
properties.add(DoubleProperty('height', height));
66+
properties.add(EnumProperty<ImageRepeat>('repeat', repeat));
67+
properties.add(ColorProperty('color', color));
68+
properties.add(
69+
ObjectFlagProperty<WidgetBuilder>.has('errorBuilder', errorBuilder));
70+
properties.add(ObjectFlagProperty<
71+
Widget Function(BuildContext context,
72+
DownloadProgress? progress)>.has('loadingBuilder', loadingBuilder));
73+
properties.add(DiagnosticsProperty<PaintModel>('paint', paint));
74+
properties.add(DiagnosticsProperty<BaseNode>('node', node));
75+
properties.add(EnumProperty<BlendMode>('blendMode', blendMode));
76+
properties.add(DiagnosticsProperty<bool>('useInk', useInk));
77+
78+
super.debugFillProperties(properties);
79+
}
5480
}
5581

5682
class _UltimateImageBuilderState extends State<UltimateImageBuilder> {
@@ -82,9 +108,27 @@ class _UltimateImageBuilderState extends State<UltimateImageBuilder> {
82108
BlendMode.srcIn)
83109
: null;
84110

85-
double? get width => widget.width ?? widget.node?.basicBoxLocal.width;
111+
double? get width {
112+
if (widget.width case var width?) return width;
113+
114+
if (widget.node case var node?) {
115+
if (node.isHorizontalExpanded) return double.infinity;
116+
return node.basicBoxLocal.width;
117+
}
118+
119+
return null;
120+
}
121+
122+
double? get height {
123+
if (widget.height case var height?) return height;
86124

87-
double? get height => widget.height ?? widget.node?.basicBoxLocal.height;
125+
if (widget.node case var node?) {
126+
if (node.isVerticalExpanded) return null;
127+
return node.basicBoxLocal.height;
128+
}
129+
130+
return null;
131+
}
88132

89133
@override
90134
void initState() {

lib/src/utils/utils.dart

+62-23
Original file line numberDiff line numberDiff line change
@@ -229,39 +229,72 @@ final RegExp staticImageTypesRegex =
229229
return (horizontal: true, vertical: true);
230230
}
231231

232-
final bool hasChildren = delegatedNode.childrenOrEmpty.isNotEmpty;
232+
if (delegatedNode is RowColumnMixin) {
233+
final bool hasChildren = delegatedNode.childrenOrEmpty.isNotEmpty;
233234

234-
if (!hasChildren) {
235+
if (!hasChildren) {
236+
return (horizontal: false, vertical: false);
237+
}
238+
239+
for (final id in delegatedNode.childrenOrEmpty) {
240+
final child = getNode(id);
241+
isAnyExpandingHorizontally =
242+
isAnyExpandingHorizontally || child.horizontalFit.isFlex;
243+
isAnyExpandingVertically =
244+
isAnyExpandingVertically || child.verticalFit.isFlex;
245+
}
246+
return (
247+
horizontal: !isAnyExpandingHorizontally,
248+
vertical: !isAnyExpandingVertically,
249+
);
250+
}
251+
252+
if (delegatedNode.childrenOrEmpty.length != 1) {
235253
return (horizontal: false, vertical: false);
236254
}
237255

238-
for (final id in delegatedNode.childrenOrEmpty) {
239-
final child = getNode(id);
240-
isAnyExpandingHorizontally =
241-
isAnyExpandingHorizontally || child.horizontalFit.isFlex;
242-
isAnyExpandingVertically =
243-
isAnyExpandingVertically || child.verticalFit.isFlex;
256+
if (node is! ScrollableMixin) return (horizontal: false, vertical: false);
257+
258+
final child = getNode(delegatedNode.childrenOrEmpty.first);
259+
260+
bool allowHorizontal = true;
261+
bool allowVertical = true;
262+
if (child.isHorizontalExpanded) allowHorizontal = false;
263+
if (child.alignment.data == null || child.alignment.data!.x != -1) {
264+
allowHorizontal = false;
265+
}
266+
if (child.alignment.data == null &&
267+
child.outerBoxLocal.left.roundToPrecision(3) != 0) {
268+
allowHorizontal = false;
244269
}
245270

246-
return (
247-
horizontal: !isAnyExpandingHorizontally,
248-
vertical: !isAnyExpandingVertically,
249-
);
271+
if (child.isVerticalExpanded) allowVertical = false;
272+
if (child.alignment.data != null && child.alignment.data!.y != -1) {
273+
allowVertical = false;
274+
}
275+
if (child.alignment.data == null &&
276+
child.outerBoxLocal.top.roundToPrecision(3) != 0) {
277+
allowVertical = false;
278+
}
279+
280+
return (horizontal: allowHorizontal, vertical: allowVertical);
250281
}
251282

252283
({bool horizontal, bool vertical}) checkSelfForLegalScrollableAxes(
253284
{required BaseNode node}) {
254-
if (node is CanvasNode) {
255-
return (
256-
horizontal: true,
257-
vertical: true,
258-
);
259-
}
260-
261-
return (
262-
horizontal: node.isHorizontalWrap,
263-
vertical: node.isVerticalWrap,
264-
);
285+
return (horizontal: true, vertical: true);
286+
287+
// if (node is CanvasNode) {
288+
// return (
289+
// horizontal: true,
290+
// vertical: true,
291+
// );
292+
// }
293+
//
294+
// return (
295+
// horizontal: node.isHorizontalWrap,
296+
// vertical: node.isVerticalWrap,
297+
// );
265298
}
266299

267300
({bool horizontal, bool vertical}) checkParentForLegalScrollableAxes({
@@ -412,6 +445,12 @@ AlignmentModel retrieveCommonStackAlignment(
412445
) {
413446
final List<AlignmentModel> alignments = [];
414447

448+
if (nodes.length == 1 &&
449+
nodes.first is ScrollableMixin &&
450+
(nodes.first as ScrollableMixin).isScrollable) {
451+
return AlignmentModel.none;
452+
}
453+
415454
for (final BaseNode node in nodes) {
416455
final AlignmentModel alignment = node.alignment;
417456
if (alignment.data == null) continue;

0 commit comments

Comments
 (0)