focus_detector 1.0.2 focus_detector: ^1.0.2 copied to clipboard
Android's onResume/onPause and iOS's viewDidAppear/viewDidDisappear for Flutter.
import 'package:flutter/material.dart';
import 'package:focus_detector/focus_detector.dart';
void main() {
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
final _resumeDetectorKey = UniqueKey();
@override
Widget build(BuildContext context) => MaterialApp(
title: 'FocusDetector Example',
theme: ThemeData(
primarySwatch: Colors.green,
),
home: FocusDetector(
key: _resumeDetectorKey,
child: Scaffold(
appBar: AppBar(
title: Text('FocusDetector Example'),
),
),
onFocusGained: () {
print('Focus gained, equivalent to onResume or viewDidAppear');
},
onFocusLost: () {
print('Focus lost, equivalent to onPause or viewDidDisappear');
},
),
);
}