This repository was archived by the owner on Jan 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathpip_view.dart
74 lines (64 loc) · 1.93 KB
/
pip_view.dart
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
import 'package:flutter/material.dart';
import 'dismiss_keyboard.dart';
import 'raw_pip_view.dart';
class PIPView extends StatefulWidget {
final PIPViewCorner initialCorner;
final double? floatingWidth;
final double? floatingHeight;
final double? floatingBorderRadius;
final bool avoidKeyboard;
final Widget Function(
BuildContext context,
bool isFloating,
) builder;
const PIPView({
Key? key,
required this.builder,
this.initialCorner = PIPViewCorner.topRight,
this.floatingWidth,
this.floatingHeight,
this.floatingBorderRadius,
this.avoidKeyboard = true,
}) : super(key: key);
@override
PIPViewState createState() => PIPViewState();
static PIPViewState? of(BuildContext context) {
return context.findAncestorStateOfType<PIPViewState>();
}
}
class PIPViewState extends State<PIPView> with TickerProviderStateMixin {
Widget? _bottomWidget;
void presentBelow(Widget widget) {
dismissKeyboard(context);
setState(() => _bottomWidget = widget);
}
void stopFloating() {
dismissKeyboard(context);
setState(() => _bottomWidget = null);
}
@override
Widget build(BuildContext context) {
final isFloating = _bottomWidget != null;
return RawPIPView(
avoidKeyboard: widget.avoidKeyboard,
bottomWidget: isFloating
? Navigator(
onGenerateInitialRoutes: (navigator, initialRoute) => [
MaterialPageRoute(builder: (context) => _bottomWidget!),
],
)
: null,
onTapTopWidget: isFloating ? stopFloating : null,
topWidget: IgnorePointer(
ignoring: isFloating,
child: Builder(
builder: (context) => widget.builder(context, isFloating),
),
),
floatingHeight: widget.floatingHeight,
floatingWidth: widget.floatingWidth,
floatingBorderRadius: widget.floatingBorderRadius,
initialCorner: widget.initialCorner,
);
}
}