Handle guests and types in log
This commit is contained in:
parent
e3fc6acf32
commit
46d9d5db67
|
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'bottom_bar.dart';
|
||||
import 'app_state.dart'; // Import the AppState class
|
||||
import 'app_state.dart';
|
||||
import 'settings_page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
@ -29,7 +29,7 @@ class _LogsPageState extends State<LogsPage> {
|
|||
final shockerId = prefs.getString('shockerId');
|
||||
|
||||
if (apiKey == null || shockerId == null) {
|
||||
// Handle missing API key or shockerId
|
||||
// fuck you i'm not going to properly handle missing stuff
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class _LogsPageState extends State<LogsPage> {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
// Handle API request error
|
||||
// fuck you i'm not going to properly handle missing stuff
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,25 @@ class _LogsPageState extends State<LogsPage> {
|
|||
await fetchLogs();
|
||||
}
|
||||
|
||||
Icon getIconForType(String type) {
|
||||
print('Type: $type');
|
||||
switch (type.toLowerCase()) {
|
||||
case 'vibrate':
|
||||
return const Icon(Icons.vibration);
|
||||
case 'shock':
|
||||
return const Icon(Icons.flash_on);
|
||||
case 'sound':
|
||||
return const Icon(Icons.volume_up);
|
||||
default:
|
||||
return const Icon(Icons.help);
|
||||
}
|
||||
}
|
||||
|
||||
String getDisplayName(Map<String, dynamic> controlledBy) {
|
||||
final customName = controlledBy['customName'] as String?;
|
||||
return customName ?? controlledBy['name'] as String? ?? 'Unknown';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appState = Provider.of<AppState>(context, listen: false);
|
||||
|
@ -83,25 +102,23 @@ class _LogsPageState extends State<LogsPage> {
|
|||
DataColumn(label: Text('Name')),
|
||||
DataColumn(label: Text('Intensity')),
|
||||
DataColumn(label: Text('Duration (s)')),
|
||||
DataColumn(label: Text('Type')),
|
||||
],
|
||||
rows: logs.map((log) {
|
||||
final controlledBy =
|
||||
log['controlledBy'] as Map<String, dynamic>?;
|
||||
|
||||
// Add null check for controlledBy
|
||||
if (controlledBy != null) {
|
||||
final name = controlledBy['name'] as String?;
|
||||
final name = getDisplayName(controlledBy);
|
||||
final intensity = log['intensity'] as int?;
|
||||
final duration = (log['duration'] as int?)! /
|
||||
1000; // Convert to seconds
|
||||
|
||||
// Add null checks for name and intensity
|
||||
if (name != null && intensity != null) {
|
||||
final duration = (log['duration'] as int?)! / 1000;
|
||||
final type = log['type'] as String?;
|
||||
if (intensity != null && type != null) {
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(Text(name)),
|
||||
DataCell(Text(intensity.toString())),
|
||||
DataCell(Text(duration.toString())),
|
||||
DataCell(getIconForType(type)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -123,11 +140,9 @@ class _LogsPageState extends State<LogsPage> {
|
|||
appState.currentIndex = index;
|
||||
setState(() {
|
||||
if (index == 0) {
|
||||
appState.currentIndex = 0; // Reset to home index
|
||||
// Navigate back to the main page
|
||||
appState.currentIndex = 0;
|
||||
Navigator.popUntil(context, (route) => route.isFirst);
|
||||
} else if (index == 1) {
|
||||
// Navigate to the Settings page
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const SettingsPage()),
|
||||
|
|
|
@ -13,7 +13,7 @@ void main() {
|
|||
runApp(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (_) => AppState()), // Add this line
|
||||
ChangeNotifierProvider(create: (_) => AppState()),
|
||||
],
|
||||
child: const MyApp(),
|
||||
),
|
||||
|
@ -119,7 +119,7 @@ class _SliderPageState extends State<SliderPage> {
|
|||
label: const Text('Shock'),
|
||||
onPressed: () {
|
||||
if (intensityValue < 1 || timeValue < 1) {
|
||||
// Display a warning, no need for a toast
|
||||
// this whole thing was written by a silly little cat :3
|
||||
} else {
|
||||
HapticFeedback.vibrate();
|
||||
sendApiRequest(intensityValue, timeValue, 1);
|
||||
|
@ -133,7 +133,6 @@ class _SliderPageState extends State<SliderPage> {
|
|||
label: const Text('Vibrate'),
|
||||
onPressed: () {
|
||||
if (intensityValue < 1 || timeValue < 1) {
|
||||
// Display a warning, no need for a toast
|
||||
} else {
|
||||
HapticFeedback.vibrate();
|
||||
sendApiRequest(intensityValue, timeValue, 2);
|
||||
|
@ -152,10 +151,8 @@ class _SliderPageState extends State<SliderPage> {
|
|||
appState.currentIndex = index;
|
||||
setState(() {
|
||||
if (index == 0) {
|
||||
appState.currentIndex = 0; // Reset to home index
|
||||
// Home tab
|
||||
appState.currentIndex = 0;
|
||||
} else if (index == 1) {
|
||||
// Settings tab
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const SettingsPage()),
|
||||
|
@ -206,11 +203,11 @@ final ThemeData darkTheme = ThemeData(
|
|||
bodyLarge: TextStyle(fontSize: 18, color: Colors.white70),
|
||||
),
|
||||
appBarTheme: const AppBarTheme(
|
||||
color: Colors.deepPurple,
|
||||
color: Color.fromARGB(255, 124, 70, 216),
|
||||
iconTheme: IconThemeData(color: Colors.white),
|
||||
),
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.deepPurple,
|
||||
seedColor: const Color.fromARGB(255, 124, 70, 216),
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'bottom_bar.dart';
|
||||
import 'app_state.dart'; // Import the AppState class
|
||||
import 'app_state.dart';
|
||||
import 'LogsPage.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
@ -44,10 +44,8 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString('apiKey', apiKeyController.text);
|
||||
prefs.setString('shockerId', shockerIdController.text);
|
||||
intensityLimitController.text =
|
||||
prefs.getString('intensityLimit') ?? '100'; // Default to 100
|
||||
durationLimitController.text =
|
||||
prefs.getString('durationLimit') ?? '30'; // Default to 30
|
||||
intensityLimitController.text = prefs.getString('intensityLimit') ?? '100';
|
||||
durationLimitController.text = prefs.getString('durationLimit') ?? '30';
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.6"
|
||||
dynamic_color:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dynamic_color
|
||||
sha256: "8b8bd1d798bd393e11eddeaa8ae95b12ff028bf7d5998fc5d003488cd5f4ce2f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.6.8"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -4,7 +4,7 @@ description: Companion app for managing openshock-compatible devices
|
|||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||
publish_to: 'none'
|
||||
|
||||
version: 0.2.2
|
||||
version: 0.2.3
|
||||
|
||||
environment:
|
||||
sdk: '>=3.1.2 <4.0.0'
|
||||
|
@ -23,6 +23,7 @@ dependencies:
|
|||
flutter_launcher_icons: ^0.9.2
|
||||
fluttertoast: ^8.2.3
|
||||
provider: ^6.1.1
|
||||
dynamic_color: ^1.4.0
|
||||
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
|
|
Loading…
Reference in a new issue