Skip to content

Commit

Permalink
Fix WoltNavigationToolbar leading constraint (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaTesser authored Jan 22, 2025
1 parent 01d32a8 commit 41e8b73
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/src/widgets/wolt_navigation_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
if (hasChild(_ToolbarSlot.leading)) {
final BoxConstraints constraints = BoxConstraints(
maxWidth: size.width,
minHeight:
size.height, // The height should be exactly the height of the bar.
maxHeight: size.height,
);
leadingWidth = layoutChild(_ToolbarSlot.leading, constraints).width;
final Size leadingSize = layoutChild(_ToolbarSlot.leading, constraints);
leadingWidth = leadingSize.width;
final double leadingX;
switch (textDirection) {
case TextDirection.rtl:
Expand All @@ -124,7 +123,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
leadingX = 0.0;
break;
}
positionChild(_ToolbarSlot.leading, Offset(leadingX, 0.0));
final double leadingY = (size.height - leadingSize.height) / 2.0;
positionChild(_ToolbarSlot.leading, Offset(leadingX, leadingY));
}

if (hasChild(_ToolbarSlot.trailing)) {
Expand Down
44 changes: 44 additions & 0 deletions test/widgets/wolt_navigation_toolbar_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wolt_modal_sheet/src/widgets/wolt_navigation_toolbar.dart';

void main() {
testWidgets(
'Leading/Trailing widget constaints',
(tester) async {
const IconData leadingIcon = Icons.chevron_left;
const IconData trailingIcon = Icons.chevron_right;
const double iconSize = 24.0;

await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: SizedBox(
height: 72.0,
child: WoltNavigationToolbar(
leading: const ColoredBox(
color: Color(0xFF00FF00),
child: Icon(leadingIcon),
),
trailing: Container(
color: const Color(0xFFFF0000),
child: const Icon(trailingIcon),
),
),
),
),
),
),
);

final Size leadingSize = tester.getSize(find.ancestor(
of: find.byIcon(leadingIcon), matching: find.byType(ColoredBox)));
expect(leadingSize, const Size.square(iconSize));

final Size trailingSize = tester.getSize(find.ancestor(
of: find.byIcon(trailingIcon), matching: find.byType(ColoredBox)));
expect(trailingSize, const Size.square(iconSize));
},
);
}

0 comments on commit 41e8b73

Please sign in to comment.