Files
2026-08-10 17:01:30 +05:30

71 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import '../settings.dart';
import '../theme.dart';
class SettingsScreen extends StatefulWidget {
final Settings settings;
final VoidCallback? onLogout;
const SettingsScreen({super.key, required this.settings, this.onLogout});
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}
class _SettingsScreenState extends State<SettingsScreen> {
late final TextEditingController _url = TextEditingController(text: widget.settings.baseUrl);
void _save() {
widget.settings.baseUrl = _url.text.trim();
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Saved')));
setState(() {});
}
@override
Widget build(BuildContext context) {
final name = widget.settings.name;
return Scaffold(
appBar: AppBar(title: const Text('Settings')),
body: ListView(
padding: const EdgeInsets.all(20),
children: [
if (name != null && name.isNotEmpty)
Card(
child: ListTile(
leading: const CircleAvatar(backgroundColor: AppColors.emerald, child: Icon(Icons.person, color: Colors.white)),
title: Text(name, style: const TextStyle(fontWeight: FontWeight.w600)),
subtitle: Text(widget.settings.isManager ? 'Manager' : 'Employee'),
),
),
const SizedBox(height: 20),
const Text('Server URL', style: TextStyle(fontWeight: FontWeight.w600, color: AppColors.navy)),
const SizedBox(height: 8),
TextField(
controller: _url,
keyboardType: TextInputType.url,
autocorrect: false,
decoration: const InputDecoration(prefixIcon: Icon(Icons.link), hintText: Settings.defaultBaseUrl),
),
const SizedBox(height: 6),
const Text('The Scalar360 API base URL. Default is api.scalar360.in.',
style: TextStyle(fontSize: 12, color: AppColors.muted)),
const SizedBox(height: 16),
FilledButton(onPressed: _save, child: const Text('Save')),
if (widget.onLogout != null) ...[
const SizedBox(height: 32),
OutlinedButton.icon(
onPressed: widget.onLogout,
icon: const Icon(Icons.logout, color: AppColors.danger),
label: const Text('Sign out', style: TextStyle(color: AppColors.danger)),
style: OutlinedButton.styleFrom(
minimumSize: const Size.fromHeight(50),
side: const BorderSide(color: AppColors.border),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
),
),
],
],
),
);
}
}