import 'package:flutter/material.dart';
import 'package:issel_code_widgets/issel_code_widgets.dart';
import '../../../issel/presentation/controllers/app_issel_controller.dart';
class HomeView extends StatefulWidget {
const HomeView({super.key, required this.app});
final AppIsselController app;
@override
State<HomeView> createState() => _HomeViewState();
}
class _HomeViewState extends State<HomeView> {
final _formKey = GlobalKey<FormState>();
final _name = TextEditingController();
@override
void dispose() {
_name.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final text = Theme.of(context).textTheme;
final dark = Theme.of(context).brightness == Brightness.dark;
final scale = dark
? widget.app.config.darkTheme.text.fontSizeScale
: widget.app.config.lightTheme.text.fontSizeScale;
return Scaffold(
appBar: AppBar(title: const Text('Inicio')),
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 820),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: colors.surface,
borderRadius: BorderRadius.circular(16),
),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text('Tu nombre', style: text.titleMedium),
const SizedBox(height: 12),
IsselTextFormField(
controller: _name,
hintText: 'Escribe tu nombre',
fillColor: colors.surfaceContainer,
textInputAction: TextInputAction.done,
onSubmitted: (_) => _greet(),
validator: (value) => (value ?? '').trim().isEmpty
? 'Escribe tu nombre'
: null,
),
const SizedBox(height: 16),
IsselButton(text: 'Saludar', onTap: _greet),
],
),
),
),
const SizedBox(height: 24),
Text('Apariencia', style: text.titleMedium),
const SizedBox(height: 12),
IsselThemeSelector(controller: widget.app.theme),
const SizedBox(height: 20),
IsselStepperField(
title: 'Escala de texto',
minValue: 0.5,
maxValue: 2,
step: 0.1,
initValue: scale,
onChanged: widget.app.setTextScaleForCurrentMode,
),
],
),
),
),
),
),
);
}
void _greet() {
if (!(_formKey.currentState?.validate() ?? false)) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Hola, ${_name.text.trim()}')),
);
}
}