forked from EdsonBueno/focus_detector
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.dart
127 lines (121 loc) · 3.64 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import 'package:flutter/material.dart';
import 'package:focus_detector_v2/focus_detector_v2.dart';
import 'package:logger/logger.dart';
class FocusDetectorExample extends StatelessWidget {
const FocusDetectorExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => FocusDetector(
onFocusLost: () {
logger.i(
'Focus Lost.'
'\nTriggered when either [onVisibilityLost] or [onForegroundLost] '
'is called.'
'\nEquivalent to onPause() on Android or viewDidDisappear() on '
'iOS.',
);
},
onFocusGained: () {
logger.i(
'Focus Gained.'
'\nTriggered when either [onVisibilityGained] or '
'[onForegroundGained] '
'is called.'
'\nEquivalent to onResume() on Android or viewDidAppear() on iOS.',
);
},
onVisibilityLost: () {
logger.i(
'Visibility Lost.'
'\nIt means the widget is no longer visible within your app.',
);
},
onVisibilityGained: () {
logger.i(
'Visibility Gained.'
'\nIt means the widget is now visible within your app.',
);
},
onForegroundLost: () {
logger.i(
'Foreground Lost.'
'\nIt means, for example, that the user sent your app to the '
'background by opening another app or turned off the device\'s '
'screen while your widget was visible.',
);
},
onForegroundGained: () {
logger.i(
'Foreground Gained.'
'\nIt means, for example, that the user switched back to your app '
'or turned the device\'s screen back on while your widget was '
'visible.',
);
},
isWidgetTest: false,
child: Material(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Send the app to the background or push another page and '
'watch the console.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
),
),
const SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () {
final route = MaterialPageRoute(
builder: (_) => const OtherPage(),
);
Navigator.of(context).push(route);
},
child: const Text(
'PUSH ANOTHER PAGE',
),
)
],
),
),
),
);
}
class OtherPage extends StatelessWidget {
const OtherPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(),
body: const Padding(
padding: EdgeInsets.all(16),
child: Center(
child: Text(
'Look at the console and return to the first screen.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
),
),
),
),
);
}
Logger logger = Logger(
printer: PrettyPrinter(
methodCount: 0,
printTime: false,
),
);
void main() {
runApp(
MaterialApp(
home: const FocusDetectorExample(),
theme: ThemeData(),
),
);
}