SimpleCloudNotifier/flutter/lib/pages/debug/debug_persistence.dart

89 lines
3.4 KiB
Dart
Raw Normal View History

2024-05-23 17:41:51 +02:00
import 'package:flutter/material.dart';
2024-05-26 00:20:25 +02:00
import 'package:hive_flutter/hive_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:simplecloudnotifier/models/channel.dart';
2024-06-15 21:29:51 +02:00
import 'package:simplecloudnotifier/models/scn_message.dart';
2024-05-26 00:20:25 +02:00
import 'package:simplecloudnotifier/pages/debug/debug_persistence_hive.dart';
import 'package:simplecloudnotifier/pages/debug/debug_persistence_sharedprefs.dart';
import 'package:simplecloudnotifier/state/application_log.dart';
2024-06-15 18:24:18 +02:00
import 'package:simplecloudnotifier/state/fb_message.dart';
import 'package:simplecloudnotifier/state/interfaces.dart';
2024-05-26 00:20:25 +02:00
import 'package:simplecloudnotifier/state/request_log.dart';
import 'package:simplecloudnotifier/utils/navi.dart';
2024-05-23 17:41:51 +02:00
class DebugPersistencePage extends StatefulWidget {
@override
_DebugPersistencePageState createState() => _DebugPersistencePageState();
}
class _DebugPersistencePageState extends State<DebugPersistencePage> {
2024-05-26 00:20:25 +02:00
SharedPreferences? prefs = null;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => setState(() => prefs = value));
}
2024-05-23 17:41:51 +02:00
@override
Widget build(BuildContext context) {
2024-05-26 00:20:25 +02:00
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
2024-06-15 18:24:18 +02:00
_buildSharedPrefCard(context),
_buildHiveCard(context, () => Hive.box<SCNRequest>('scn-requests'), 'scn-requests'),
_buildHiveCard(context, () => Hive.box<SCNLog>('scn-logs'), 'scn-logs'),
2024-06-15 21:29:51 +02:00
_buildHiveCard(context, () => Hive.box<SCNMessage>('scn-message-cache'), 'scn-message-cache'),
2024-06-15 18:24:18 +02:00
_buildHiveCard(context, () => Hive.box<Channel>('scn-channel-cache'), 'scn-channel-cache'),
_buildHiveCard(context, () => Hive.box<FBMessage>('scn-fb-messages'), 'scn-fb-messages'),
],
),
);
}
Widget _buildSharedPrefCard(BuildContext context) {
return Card.outlined(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () {
Navi.push(context, () => DebugSharedPrefPage(sharedPref: prefs!));
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(width: 30, child: Text('')),
Expanded(child: Text('Shared Preferences', style: TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.center)),
SizedBox(width: 40, child: Text('${prefs?.getKeys().length.toString()}', textAlign: TextAlign.end)),
],
),
2024-06-15 18:24:18 +02:00
),
),
);
}
Widget _buildHiveCard(BuildContext context, Box<FieldDebuggable> Function() boxFunc, String boxname) {
return Card.outlined(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () {
2024-06-15 21:29:51 +02:00
Navi.push(context, () => DebugHiveBoxPage(boxName: boxname, box: boxFunc()));
2024-06-15 18:24:18 +02:00
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(width: 30, child: Text('')),
Expanded(child: Text('Hive [$boxname]', style: TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.center)),
SizedBox(width: 40, child: Text('${boxFunc().length.toString()}', textAlign: TextAlign.end)),
],
),
2024-06-15 18:24:18 +02:00
),
2024-05-26 00:20:25 +02:00
),
);
2024-05-23 17:41:51 +02:00
}
}