/
main.dart
53 lines (47 loc) · 1.13 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
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'package:flutterwebapp_reload_detector/flutterwebapp_reload_detector.dart';
void main() {
runApp(
const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
),
);
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool isReloaded = false;
@override
void initState() {
// Make sure to Call this on Top Level Widget only once
WebAppReloadDetector.onReload(() {
setState(() {
isReloaded = true;
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Browser Reloaded Detector'),
),
body: Center(
child: Text(
'WebApp Reloaded : $isReloaded',
style: TextStyle(
color: isReloaded ? Colors.green : Colors.red,
fontWeight: FontWeight.w400,
fontSize: 20,
),
),
),
);
}
}