From f6144f0c25119a408ac58022c1ade704b5c50a30 Mon Sep 17 00:00:00 2001 From: Kishan Rathore <34465683+rkishan516@users.noreply.github.com> Date: Fri, 26 Jul 2024 21:45:36 +0530 Subject: [PATCH] feat: Add drag handle size to be configurable based on given size (#152085) Feat: Drag handle size can now be changed to any given size. So, In previous behaviour drag handle size was not able to extends beyond 48x48. But some user might want to change it. In current behaviour, drag handle size is default to same 48x48 but if drag handle size grows beyond that, we don't restrict it. Fixes #149170 --- .../lib/src/material/bottom_sheet.dart | 6 +- .../test/material/bottom_sheet_test.dart | 74 +++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index 4cb1dca297..2542109077 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -5,6 +5,8 @@ /// @docImport 'dart:ui'; library; +import 'dart:math' as math; + import 'package:flutter/gestures.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -460,8 +462,8 @@ class _DragHandle extends StatelessWidget { container: true, onTap: onSemanticsTap, child: SizedBox( - height: kMinInteractiveDimension, - width: kMinInteractiveDimension, + width: math.max(handleSize.width, kMinInteractiveDimension), + height: math.max(handleSize.height, kMinInteractiveDimension), child: Center( child: Container( height: handleSize.height, diff --git a/packages/flutter/test/material/bottom_sheet_test.dart b/packages/flutter/test/material/bottom_sheet_test.dart index cab5910aad..08384206d3 100644 --- a/packages/flutter/test/material/bottom_sheet_test.dart +++ b/packages/flutter/test/material/bottom_sheet_test.dart @@ -1281,6 +1281,80 @@ void main() { await checkDragHandleAndColors(); }); + testWidgets('Drag handle interactive area size at minimum possible size', (WidgetTester tester) async { + Widget buildScaffold(GlobalKey scaffoldKey, {Size? dragHandleSize}) { + return MaterialApp( + theme: ThemeData.light().copyWith( + bottomSheetTheme: BottomSheetThemeData( + dragHandleSize: dragHandleSize + ), + ), + home: Scaffold( + key: scaffoldKey, + ), + ); + } + + const Size smallerDragHandleSize = Size(20, 20); + + final GlobalKey scaffoldKey = GlobalKey(); + await tester.pumpWidget(buildScaffold(scaffoldKey, dragHandleSize: smallerDragHandleSize)); + + showModalBottomSheet( + context: scaffoldKey.currentContext!, + showDragHandle: true, + builder: (BuildContext context) { + return const Text('BottomSheet'); + }, + ); + + await tester.pump(); // Bottom sheet show animation starts. + await tester.pump(const Duration(seconds: 1)); // Animation done. + + final Finder dragHandle = find.bySemanticsLabel('Dismiss'); + expect( + tester.getSize(dragHandle), + const Size(kMinInteractiveDimension, kMinInteractiveDimension), + ); + }); + + testWidgets('Drag handle interactive area size at given dragHandleSize', (WidgetTester tester) async { + Widget buildScaffold(GlobalKey scaffoldKey, {Size? dragHandleSize}) { + return MaterialApp( + theme: ThemeData.light().copyWith( + bottomSheetTheme: BottomSheetThemeData( + dragHandleSize: dragHandleSize + ), + ), + home: Scaffold( + key: scaffoldKey, + ), + ); + } + + const Size extendedDragHandleSize = Size(100, 50); + + final GlobalKey scaffoldKey = GlobalKey(); + await tester.pumpWidget(buildScaffold(scaffoldKey, dragHandleSize: extendedDragHandleSize)); + + showModalBottomSheet( + context: scaffoldKey.currentContext!, + showDragHandle: true, + builder: (BuildContext context) { + return const Text('BottomSheet'); + }, + ); + + await tester.pump(); // Bottom sheet show animation starts. + await tester.pump(const Duration(seconds: 1)); // Animation done. + + final Finder dragHandle = find.bySemanticsLabel('Dismiss'); + expect( + tester.getSize(dragHandle), + extendedDragHandleSize, + ); + }); + testWidgets('showModalBottomSheet does not use root Navigator by default', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( home: Scaffold(