-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew Text Document.txt
51 lines (45 loc) · 1.18 KB
/
New Text Document.txt
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
import 'package:flutter/material.dart';
import 'database_helper.dart';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
DatabaseHelper().closeDatabase();
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.paused) {
// Close the database when the app is going to the background
DatabaseHelper().closeDatabase();
} else if (state == AppLifecycleState.resumed) {
// Optionally, reopen the database when the app is resumed
DatabaseHelper().database;
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('SQLite Database Example'),
),
body: Center(
child: Text('Database management in Flutter'),
),
),
);
}
}
void main() {
runApp(MyApp());
}