helpers.dart
2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sheet/sheet.dart';
const Key _childKey = Key('_sheet_child');
Finder findSheet() => find.byKey(_childKey);
extension SheetTester on WidgetTester {
Future<void> pumpApp(Widget sheet, {VoidCallback? onButtonPressed}) async {
await pumpWidget(
MaterialApp(
home: Stack(
children: <Widget>[
TextButton(
child: const Text('TapHere'),
onPressed: onButtonPressed,
),
sheet,
],
)),
);
}
Future<void> pumpSheet({VoidCallback? onButtonPressed}) async {
await pumpWidget(
MaterialApp(
home: Stack(
children: <Widget>[
TextButton(
child: const Text('TapHere'),
onPressed: onButtonPressed,
),
Sheet(
fit: fitVariants.currentValue ?? SheetFit.loose,
child: childVariants.currentValue ?? Container(),
),
],
)),
);
}
double getSheetTop() {
final Offset offset = getTopLeft(find.byKey(_childKey));
return offset.dy;
}
double getSheetExtent() {
final Rect rootRect = getRect(find.byType(Sheet));
final Offset offset = getTopLeft(find.byKey(_childKey));
return rootRect.bottom - offset.dy;
}
SheetController getSheetController() {
final BuildContext context = element(find.byKey(_childKey));
return Sheet.of(context)!.controller;
}
SheetPosition getSheetPosition() {
final BuildContext context = element(find.byKey(_childKey));
return Sheet.of(context)!.position;
}
double getSheetHeight() {
final Size rect = getSize(find.byKey(_childKey));
return rect.height;
}
Size getSheetSize() {
return getSize(find.byKey(_childKey));
}
Future<void> dragSheet(double offset) {
return drag(find.byKey(_childKey), Offset(0, offset));
}
}
final FitSheetVariant fitVariants = FitSheetVariant();
class FitSheetVariant extends ValueVariant<SheetFit> {
FitSheetVariant() : super(SheetFit.values.toSet());
}
final SheetChildVariant childVariants = SheetChildVariant();
class SheetChildVariant extends ValueVariant<Widget> {
SheetChildVariant()
: super(<Widget>{Container(), const SingleChildScrollView()});
}