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