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

108 lines
4.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.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: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
const ListTile(
leading: Icon(Icons.screen_rotation),
title: Text('Calibrate Mount Angle'),
subtitle: Text('Place the motorcycle perfectly upright and tap this to zero the lean angle sensor.'),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 16.0, bottom: 8.0),
child: 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.monitor_heart),
title: const Text('Sensor Diagnostics'),
subtitle: const Text('View raw IMU and GPS values.'),
trailing: const Icon(Icons.chevron_right),
onTap: () => context.go('/settings/diagnostics'),
),
),
const SizedBox(height: 16),
Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
const ListTile(
leading: Icon(Icons.delete_forever, color: Colors.redAccent),
title: Text('Clear Ride History'),
subtitle: Text('Permanently delete all recorded rides and performance runs.'),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(right: 16.0, bottom: 8.0),
child: 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)),
),
),
),
],
),
),
),
],
),
);
}
}