| .. | .. |
|---|
| 1 | 1 | import 'package:flutter/material.dart'; |
|---|
| 2 | 2 | import 'package:flutter_riverpod/flutter_riverpod.dart'; |
|---|
| 3 | +import 'package:shared_preferences/shared_preferences.dart'; |
|---|
| 3 | 4 | |
|---|
| 4 | 5 | import '../models/server_config.dart'; |
|---|
| 5 | 6 | import '../providers/providers.dart'; |
|---|
| .. | .. |
|---|
| 249 | 250 | label: const Text('Wake Mac'), |
|---|
| 250 | 251 | ), |
|---|
| 251 | 252 | const SizedBox(height: 12), |
|---|
| 253 | + |
|---|
| 254 | + // Reset TLS Trust button |
|---|
| 255 | + OutlinedButton.icon( |
|---|
| 256 | + onPressed: () async { |
|---|
| 257 | + final confirmed = await showDialog<bool>( |
|---|
| 258 | + context: context, |
|---|
| 259 | + builder: (ctx) => AlertDialog( |
|---|
| 260 | + title: const Text('Reset Server Trust?'), |
|---|
| 261 | + content: const Text( |
|---|
| 262 | + 'This clears the saved server certificate fingerprint. ' |
|---|
| 263 | + 'Use this if you reinstalled AIBroker or changed servers. ' |
|---|
| 264 | + 'The app will trust the next server it connects to.', |
|---|
| 265 | + ), |
|---|
| 266 | + actions: [ |
|---|
| 267 | + TextButton( |
|---|
| 268 | + onPressed: () => Navigator.pop(ctx, false), |
|---|
| 269 | + child: const Text('Cancel'), |
|---|
| 270 | + ), |
|---|
| 271 | + TextButton( |
|---|
| 272 | + onPressed: () => Navigator.pop(ctx, true), |
|---|
| 273 | + child: const Text('Reset', style: TextStyle(color: AppColors.error)), |
|---|
| 274 | + ), |
|---|
| 275 | + ], |
|---|
| 276 | + ), |
|---|
| 277 | + ); |
|---|
| 278 | + if (confirmed == true && mounted) { |
|---|
| 279 | + // Access MqttService through the provider and reset trust |
|---|
| 280 | + final prefs = await SharedPreferences.getInstance(); |
|---|
| 281 | + await prefs.remove('trustedCertFingerprint'); |
|---|
| 282 | + ScaffoldMessenger.of(context).showSnackBar( |
|---|
| 283 | + const SnackBar(content: Text('Server trust reset. Reconnect to trust the new server.')), |
|---|
| 284 | + ); |
|---|
| 285 | + } |
|---|
| 286 | + }, |
|---|
| 287 | + icon: const Icon(Icons.shield_outlined), |
|---|
| 288 | + label: const Text('Reset Server Trust'), |
|---|
| 289 | + ), |
|---|
| 290 | + const SizedBox(height: 12), |
|---|
| 252 | 291 | ], |
|---|
| 253 | 292 | ), |
|---|
| 254 | 293 | ), |
|---|