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
This commit is contained in:
Kishan Rathore 2024-07-26 21:45:36 +05:30 committed by GitHub
parent 7f8ad8a4cb
commit f6144f0c25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 78 additions and 2 deletions

View File

@ -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,

View File

@ -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<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
await tester.pumpWidget(buildScaffold(scaffoldKey, dragHandleSize: smallerDragHandleSize));
showModalBottomSheet<void>(
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<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
await tester.pumpWidget(buildScaffold(scaffoldKey, dragHandleSize: extendedDragHandleSize));
showModalBottomSheet<void>(
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(