MotorSignal-App/lib/features/settings/settings_screen.dart

71 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../services/sensor_fusion_service.dart';
import '../../database/database.dart';
class SettingsScreen extends ConsumerWidget {
const SettingsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: AppBar(title: const Text('Settings')),
body: ListView(
padding: const EdgeInsets.all(16.0),
children: [
const Text(
'Sensors',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.cyanAccent),
),
const SizedBox(height: 16),
Card(
child: ListTile(
leading: const Icon(Icons.screen_rotation),
title: const Text('Calibrate Mount Angle'),
subtitle: const Text('Place the motorcycle perfectly upright and tap this to zero the lean angle sensor.'),
trailing: ElevatedButton(
onPressed: () async {
ref.read(sensorFusionServiceProvider).calibrateUpright();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Sensors Calibrated!')),
);
}
},
child: const Text('Calibrate'),
),
),
),
const SizedBox(height: 32),
const Text(
'Data',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.cyanAccent),
),
const SizedBox(height: 16),
Card(
child: ListTile(
leading: const Icon(Icons.delete_forever, color: Colors.redAccent),
title: const Text('Clear Ride History'),
subtitle: const Text('Permanently delete all recorded rides and performance runs.'),
trailing: ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red.withValues(alpha: 0.2)),
onPressed: () async {
final db = ref.read(databaseProvider);
await db.delete(db.rides).go();
await db.delete(db.performanceRuns).go();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('All data cleared.')),
);
}
},
child: const Text('Clear', style: TextStyle(color: Colors.redAccent)),
),
),
),
],
),
);
}
}