refactor: dblog
parent
d2d92ed8bb
commit
65b477d648
|
|
@ -1,8 +0,0 @@
|
|||
import "package:mobdr/main.dart";
|
||||
|
||||
class dbLog {
|
||||
static void addLog(
|
||||
String type, String module, String libelle, int duree) async {
|
||||
objectbox.addLog(type, module, libelle, duree);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@ import 'package:mobdr/ui/splash_screen.dart';
|
|||
import 'package:mobdr/service/device_info.dart';
|
||||
import 'package:mobdr/service/directories.dart';
|
||||
import 'package:mobdr/service/plausible.dart';
|
||||
import 'package:mobdr/db/db_log.dart';
|
||||
|
||||
/// Provides access to the ObjectBox Store throughout the app.
|
||||
late ObjectBox objectbox;
|
||||
|
|
@ -62,7 +61,7 @@ Future<void> main() async {
|
|||
'name': SharedPrefs().login,
|
||||
});
|
||||
|
||||
dbLog.addLog('LOG', 'MOBDR', 'Ouverture application ', 0);
|
||||
LoggerUtil.dblog('LOG', 'MOBDR', 'Ouverture application ', 0);
|
||||
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
|
||||
.then((_) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import 'package:logger/logger.dart';
|
||||
import 'package:mobdr/objectbox.dart';
|
||||
import 'package:mobdr/main.dart';
|
||||
|
||||
class LoggerUtil {
|
||||
static final Logger _logger = Logger(printer: PrettyPrinter());
|
||||
|
|
@ -7,6 +9,12 @@ class LoggerUtil {
|
|||
printer: PrettyPrinter(methodCount: 0),
|
||||
);
|
||||
|
||||
static final ObjectBox _loggerDB = objectbox;
|
||||
|
||||
static void dblog(String type, String module, String libelle, int duree) {
|
||||
_loggerDB.addLog(type, module, libelle, duree);
|
||||
}
|
||||
|
||||
static void logVerbose(String message) {
|
||||
_logger.v(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import 'package:mobdr/main.dart';
|
||||
import 'package:mobdr/config/global_style.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../db/box_log.dart';
|
||||
import 'package:mobdr/main.dart';
|
||||
import 'package:mobdr/config/global_style.dart';
|
||||
import 'package:mobdr/ui/reusable/reusable_widget.dart';
|
||||
import 'package:mobdr/db/box_log.dart';
|
||||
|
||||
class LogPage extends StatefulWidget {
|
||||
@override
|
||||
|
|
@ -10,17 +11,21 @@ class LogPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _LogPageState extends State<LogPage> {
|
||||
final _reusableWidget = ReusableWidget();
|
||||
|
||||
Widget Function(BuildContext, int) _itemBuilder(List<Log> logs) =>
|
||||
(BuildContext context, int index) => Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
border:
|
||||
Border(bottom: BorderSide(color: Colors.black12))),
|
||||
border: Border(bottom: BorderSide(color: Colors.black12)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 18.0, horizontal: 10.0),
|
||||
vertical: 18.0,
|
||||
horizontal: 10.0,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
|
|
@ -59,30 +64,72 @@ class _LogPageState extends State<LogPage> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
void _showConfirmationDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Confirmation'),
|
||||
content: Text('Are you sure you want to delete this log?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Delete'),
|
||||
onPressed: () {
|
||||
// remove all log from db
|
||||
objectbox.logBox.removeAll();
|
||||
|
||||
// close dialog
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
iconTheme: IconThemeData(
|
||||
color: GlobalStyle.appBarIconThemeColor,
|
||||
),
|
||||
elevation: GlobalStyle.appBarElevation,
|
||||
title: Text(
|
||||
'Show logs',
|
||||
style: GlobalStyle.appBarTitle,
|
||||
),
|
||||
backgroundColor: GlobalStyle.appBarBackgroundColor,
|
||||
systemOverlayStyle: GlobalStyle.appBarSystemOverlayStyle),
|
||||
body: Column(children: <Widget>[
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
iconTheme: IconThemeData(
|
||||
color: GlobalStyle.appBarIconThemeColor,
|
||||
),
|
||||
elevation: GlobalStyle.appBarElevation,
|
||||
title: Text(
|
||||
'Show logs',
|
||||
style: GlobalStyle.appBarTitle,
|
||||
),
|
||||
backgroundColor: GlobalStyle.appBarBackgroundColor,
|
||||
systemOverlayStyle: GlobalStyle.appBarSystemOverlayStyle,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: _showConfirmationDialog,
|
||||
),
|
||||
],
|
||||
bottom: _reusableWidget.bottomAppBar(),
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: StreamBuilder<List<Log>>(
|
||||
stream: objectbox.getLogs(),
|
||||
builder: (context, snapshot) => ListView.builder(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
itemCount: snapshot.hasData ? snapshot.data!.length : 0,
|
||||
itemBuilder: _itemBuilder(snapshot.data ?? []))))
|
||||
]));
|
||||
child: StreamBuilder<List<Log>>(
|
||||
stream: objectbox.getLogs(),
|
||||
builder: (context, snapshot) => ListView.builder(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
itemCount: snapshot.hasData ? snapshot.data!.length : 0,
|
||||
itemBuilder: _itemBuilder(snapshot.data ?? []),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue