import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../services/deck_repository.dart'; import 'home_screen.dart'; class SettingsScreen extends StatefulWidget { const SettingsScreen({super.key}); @override State createState() => _SettingsScreenState(); } class _SettingsScreenState extends State { final TextEditingController _apiKeyController = TextEditingController(); @override void dispose() { _apiKeyController.dispose(); super.dispose(); } Future _saveApiKey() async { final apiKey = _apiKeyController.text.trim(); if (apiKey.isEmpty) return; final repo = Provider.of(context, listen: false); await repo.setApiKey(apiKey); ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('API key saved!')), ); if (mounted) { Navigator.of(context).pushReplacement( MaterialPageRoute(builder: (_) => const HomeScreen()), ); } } @override void initState() { super.initState(); final repo = Provider.of(context, listen: false); repo.loadApiKey().then((key) { if (key != null) { _apiKeyController.text = key; } }); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: const Color(0xFF121212), appBar: AppBar( title: const Text('Settings'), backgroundColor: const Color(0xFF1F1F1F), foregroundColor: Colors.white, ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ TextField( controller: _apiKeyController, obscureText: true, style: const TextStyle(color: Colors.white), decoration: InputDecoration( labelText: 'WaniKani API Key', labelStyle: const TextStyle(color: Colors.grey), filled: true, fillColor: const Color(0xFF1E1E1E), border: OutlineInputBorder( borderRadius: BorderRadius.circular(6), borderSide: const BorderSide(color: Colors.grey), ), ), ), const SizedBox(height: 16), ElevatedButton( onPressed: _saveApiKey, style: ElevatedButton.styleFrom( backgroundColor: Colors.blueAccent, foregroundColor: Colors.white, ), child: const Text('Save & Start Quiz'), ), ], ), ), ); } }