/
overlay_keys.dart
71 lines (62 loc) · 1.91 KB
/
overlay_keys.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
import 'package:flutter/widgets.dart';
import 'package:overlay_support/overlay_support.dart';
/// A widget that builds its child.
/// The same as [KeyedSubtree]
class KeyedOverlay extends StatelessWidget {
final Widget child;
const KeyedOverlay({required Key key, required this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return child;
}
}
/// [showOverlay] with block other show with the same [ModalKey].
///
/// for example
/// ```dart
/// final modalKey = ModalKey('simple');
///
/// //popup a simple message on top of screen
/// showSimpleNotification(Text('modal example'), key: modalKey);
///
/// //when previous notification is showing, popup again whit this key
/// //this notification will be rejected.
/// showSimpleNotification(Text('modal example 2'), key: modalKey);
///
/// ```
class ModalKey<T> extends ValueKey<T> {
ModalKey(T value) : super(value);
@override
bool operator ==(other) {
return other is ModalKey<T> && value == other.value;
}
@override
int get hashCode => Object.hash(runtimeType, value);
}
///
/// The [OverlaySupportEntry] associated with [TransientKey] will be dismiss immediately
/// when next [OverlaySupportEntry] showing by [showOverlay] with the same key.
///
/// This key was designed for [toast], but it seems wired, so have not use yet.
///
/// For example:
/// ```dart
///
/// final key = const TransientKey('transient');
///
/// showSimpleNotification(Text('modal example'), key: key);
///
/// // The previous notification will be dismiss immediately, instead of have
/// // a disappearing animation effect.
/// showSimpleNotification(Text('modal example 2'), key: key);
///
/// ```
class TransientKey<T> extends ValueKey<T> {
const TransientKey(T value) : super(value);
@override
bool operator ==(other) {
return other is TransientKey<T> && value == other.value;
}
@override
int get hashCode => Object.hash(runtimeType, value);
}