Agrego frontend app

This commit is contained in:
Pablo
2026-08-22 19:08:19 -03:00
parent 824e092b29
commit 2d0797e627
254 changed files with 37231 additions and 0 deletions
@@ -0,0 +1,415 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gimnasio_soma/core/services/soma_logger.dart';
import 'package:gimnasio_soma/core/theme/soma_colors.dart';
import 'package:gimnasio_soma/core/widgets/soma_toast.dart';
class LogsScreen extends StatefulWidget {
const LogsScreen({super.key});
@override
State<LogsScreen> createState() => _LogsScreenState();
}
class _LogsScreenState extends State<LogsScreen> {
LogLevel? _filter;
String _search = '';
List<LogEntry> get _filteredEntries {
var entries = SomaLogger.instance.entries.reversed.toList();
if (_filter != null) {
entries = entries.where((e) => e.level == _filter).toList();
}
if (_search.isNotEmpty) {
final q = _search.toLowerCase();
entries = entries
.where((e) =>
e.message.toLowerCase().contains(q) ||
e.tag.toLowerCase().contains(q) ||
(e.detail?.toLowerCase().contains(q) ?? false))
.toList();
}
return entries;
}
void _copyAll() {
final text = SomaLogger.instance.export();
Clipboard.setData(ClipboardData(text: text));
SomaToast.show(context,
message: 'Logs copiados al portapapeles', type: ToastType.success);
}
void _clearLogs() {
SomaLogger.instance.clear();
setState(() {});
SomaToast.show(context, message: 'Logs limpiados', type: ToastType.info);
}
@override
Widget build(BuildContext context) {
final isWide = MediaQuery.of(context).size.width >= 800;
final theme = Theme.of(context);
final entries = _filteredEntries;
return Scaffold(
body: Column(
children: [
// Header
Padding(
padding: EdgeInsets.fromLTRB(
isWide ? 32 : 16,
isWide ? 28 : 16,
isWide ? 32 : 16,
8,
),
child: Column(
children: [
Row(
children: [
const Text(
'Logs',
style:
TextStyle(fontSize: 22, fontWeight: FontWeight.w700),
),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: SomaColors.primary.withAlpha(25),
borderRadius: BorderRadius.circular(6),
),
child: Text(
SomaLogger.instance.platform,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: theme.colorScheme.onSurface,
),
),
),
const Spacer(),
IconButton(
onPressed: _copyAll,
icon: const Icon(Icons.copy, size: 20),
tooltip: 'Copiar logs',
),
IconButton(
onPressed: _clearLogs,
icon: const Icon(Icons.delete_outline, size: 20),
tooltip: 'Limpiar logs',
),
IconButton(
onPressed: () => setState(() {}),
icon: const Icon(Icons.refresh, size: 20),
tooltip: 'Refrescar',
),
],
),
const SizedBox(height: 8),
// Filtros
Row(
children: [
Expanded(
child: SizedBox(
height: 36,
child: TextField(
onChanged: (v) => setState(() => _search = v),
decoration: InputDecoration(
hintText: 'Buscar...',
prefixIcon:
const Icon(Icons.search, size: 18),
contentPadding:
const EdgeInsets.symmetric(horizontal: 12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color:
theme.colorScheme.surfaceContainerHighest,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color:
theme.colorScheme.surfaceContainerHighest,
),
),
),
style: const TextStyle(fontSize: 13),
),
),
),
const SizedBox(width: 8),
_FilterChip(
label: 'Todos',
selected: _filter == null,
onTap: () => setState(() => _filter = null),
),
const SizedBox(width: 4),
_FilterChip(
label: 'RPC',
selected: _search == 'RPC',
onTap: () => setState(() {
_search = _search == 'RPC' ? '' : 'RPC';
}),
color: SomaColors.primary,
),
const SizedBox(width: 4),
_FilterChip(
label: 'Error',
selected: _filter == LogLevel.error,
onTap: () => setState(() {
_filter =
_filter == LogLevel.error ? null : LogLevel.error;
}),
color: SomaColors.error,
),
],
),
],
),
),
// Contador
Padding(
padding: EdgeInsets.symmetric(horizontal: isWide ? 32 : 16),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'${entries.length} entradas',
style: TextStyle(
fontSize: 11,
color: theme.colorScheme.onSurface.withAlpha(100),
),
),
),
),
const SizedBox(height: 4),
// Lista
Expanded(
child: entries.isEmpty
? Center(
child: Text(
'Sin logs',
style: TextStyle(
fontSize: 14,
color: theme.colorScheme.onSurface.withAlpha(100),
),
),
)
: ListView.builder(
padding: EdgeInsets.fromLTRB(
isWide ? 32 : 12,
0,
isWide ? 32 : 12,
80,
),
itemCount: entries.length,
itemBuilder: (context, index) {
return _LogEntryTile(entry: entries[index]);
},
),
),
],
),
);
}
}
class _LogEntryTile extends StatelessWidget {
final LogEntry entry;
const _LogEntryTile({required this.entry});
Color _levelColor() {
switch (entry.level) {
case LogLevel.debug:
return Colors.grey;
case LogLevel.info:
return Colors.blue;
case LogLevel.warning:
return Colors.orange;
case LogLevel.error:
return SomaColors.error;
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final ts =
'${entry.timestamp.hour.toString().padLeft(2, '0')}:'
'${entry.timestamp.minute.toString().padLeft(2, '0')}:'
'${entry.timestamp.second.toString().padLeft(2, '0')}';
final dur = entry.duration != null
? ' ${entry.duration!.inMilliseconds}ms'
: '';
return Padding(
padding: const EdgeInsets.only(bottom: 2),
child: InkWell(
borderRadius: BorderRadius.circular(6),
onTap: entry.detail != null
? () => _showDetail(context)
: null,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: entry.level == LogLevel.error
? SomaColors.error.withAlpha(8)
: Colors.transparent,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Timestamp
Text(
ts,
style: TextStyle(
fontSize: 11,
fontFamily: 'monospace',
color: theme.colorScheme.onSurface.withAlpha(80),
),
),
const SizedBox(width: 6),
// Level badge
Container(
width: 6,
height: 6,
margin: const EdgeInsets.only(top: 5),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _levelColor(),
),
),
const SizedBox(width: 6),
// Tag
Text(
'[${entry.tag}]',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
fontFamily: 'monospace',
color: theme.colorScheme.onSurface.withAlpha(140),
),
),
const SizedBox(width: 6),
// Message
Expanded(
child: Text(
entry.message,
style: TextStyle(
fontSize: 12,
fontFamily: 'monospace',
color: theme.colorScheme.onSurface,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
// Duration
if (dur.isNotEmpty)
Text(
dur,
style: TextStyle(
fontSize: 11,
fontFamily: 'monospace',
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface.withAlpha(100),
),
),
// Detail indicator
if (entry.detail != null)
Padding(
padding: const EdgeInsets.only(left: 4),
child: Icon(
Icons.info_outline,
size: 14,
color: theme.colorScheme.onSurface.withAlpha(60),
),
),
],
),
),
),
);
}
void _showDetail(BuildContext context) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text(
'[${entry.tag}] ${entry.message}',
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
),
content: SingleChildScrollView(
child: SelectableText(
entry.detail ?? '',
style: const TextStyle(fontSize: 12, fontFamily: 'monospace'),
),
),
actions: [
TextButton(
onPressed: () {
Clipboard.setData(
ClipboardData(text: '${entry.formatted}\n${entry.detail}'));
Navigator.of(ctx).pop();
},
child: const Text('Copiar'),
),
TextButton(
onPressed: () => Navigator.of(ctx).pop(),
child: const Text('Cerrar'),
),
],
),
);
}
}
class _FilterChip extends StatelessWidget {
final String label;
final bool selected;
final VoidCallback onTap;
final Color? color;
const _FilterChip({
required this.label,
required this.selected,
required this.onTap,
this.color,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final c = color ?? SomaColors.primary;
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: selected ? c.withAlpha(25) : Colors.transparent,
border: Border.all(
color: selected ? c : theme.colorScheme.surfaceContainerHighest,
width: 0.8,
),
),
child: Text(
label,
style: TextStyle(
fontSize: 11,
fontWeight: selected ? FontWeight.w600 : FontWeight.w400,
color: selected ? c : theme.colorScheme.onSurface.withAlpha(130),
),
),
),
);
}
}
@@ -0,0 +1,314 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gimnasio_soma/core/widgets/soma_logo.dart';
import 'package:gimnasio_soma/core/widgets/soma_primary_button.dart';
import 'package:gimnasio_soma/core/widgets/soma_secondary_button.dart';
import 'package:gimnasio_soma/core/widgets/soma_text_field.dart';
import 'package:gimnasio_soma/core/widgets/soma_toast.dart';
import 'package:gimnasio_soma/features/auth/presentation/providers/auth_provider.dart';
class WidgetGalleryScreen extends ConsumerStatefulWidget {
const WidgetGalleryScreen({super.key});
@override
ConsumerState<WidgetGalleryScreen> createState() =>
_WidgetGalleryScreenState();
}
class _WidgetGalleryScreenState extends ConsumerState<WidgetGalleryScreen> {
final _textController = TextEditingController();
final _passwordController = TextEditingController();
bool _isLoading = false;
bool _obscurePassword = true;
@override
void dispose() {
_textController.dispose();
_passwordController.dispose();
super.dispose();
}
void _simulateLoading() async {
setState(() => _isLoading = true);
await Future.delayed(const Duration(seconds: 2));
if (mounted) setState(() => _isLoading = false);
}
@override
Widget build(BuildContext context) {
final authState = ref.watch(authStateProvider);
final user = authState.valueOrNull;
return Scaffold(
appBar: AppBar(
title: const Text('Widget Gallery'),
actions: [
IconButton(
icon: const Icon(Icons.logout),
onPressed: () => ref.read(authStateProvider.notifier).logout(),
tooltip: 'Cerrar sesión',
),
],
),
body: ListView(
padding: const EdgeInsets.all(24),
children: [
// User Info
if (user != null) ...[
_SectionTitle('Usuario Logueado'),
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Nombre: ${user.displayName}',
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 8),
Text(
'DNI: ${user.dni}',
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 8),
Text(
'Rol: ${user.role}',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
],
),
),
),
const SizedBox(height: 32),
],
// Logo
_SectionTitle('Logo'),
const Center(child: SomaLogo(width: 200)),
const SizedBox(height: 32),
// Primary Buttons
_SectionTitle('Botones Primarios'),
SomaPrimaryButton(
text: 'Botón Normal',
onPressed: () => SomaToast.show(
context,
message: 'Botón presionado',
type: ToastType.info,
),
),
const SizedBox(height: 12),
SomaPrimaryButton(
text: 'Con Ícono',
icon: Icons.check,
onPressed: () => SomaToast.show(
context,
message: 'Botón con ícono presionado',
type: ToastType.success,
),
),
const SizedBox(height: 12),
SomaPrimaryButton(
text: 'Loading...',
isLoading: _isLoading,
onPressed: _simulateLoading,
),
const SizedBox(height: 12),
const SomaPrimaryButton(text: 'Deshabilitado', onPressed: null),
const SizedBox(height: 32),
// Secondary Buttons
_SectionTitle('Botones Secundarios'),
SomaSecondaryButton(
text: 'Botón Outline',
onPressed: () => SomaToast.show(
context,
message: 'Botón secundario presionado',
type: ToastType.info,
),
),
const SizedBox(height: 12),
SomaSecondaryButton(
text: 'Con Ícono',
icon: Icons.edit,
onPressed: () {},
),
const SizedBox(height: 12),
SomaSecondaryButton(
text: 'Loading...',
isLoading: _isLoading,
onPressed: _simulateLoading,
),
const SizedBox(height: 12),
const SomaSecondaryButton(text: 'Deshabilitado', onPressed: null),
const SizedBox(height: 32),
// Text Fields
_SectionTitle('Campos de Texto'),
SomaTextField(
controller: _textController,
hintText: 'Ingresá tu nombre',
labelText: 'Nombre',
prefixIcon: Icons.person,
),
const SizedBox(height: 16),
SomaTextField(
controller: _passwordController,
hintText: 'Ingresá tu contraseña',
labelText: 'Contraseña',
prefixIcon: Icons.lock,
obscureText: _obscurePassword,
suffixIcon: IconButton(
icon: Icon(
_obscurePassword
? Icons.visibility_outlined
: Icons.visibility_off_outlined,
),
onPressed: () {
setState(() => _obscurePassword = !_obscurePassword);
},
),
),
const SizedBox(height: 16),
const SomaTextField(
hintText: 'Campo deshabilitado',
labelText: 'Deshabilitado',
prefixIcon: Icons.block,
enabled: false,
),
const SizedBox(height: 32),
// Toasts
_SectionTitle('Notificaciones (Toasts)'),
ElevatedButton(
onPressed: () => SomaToast.show(
context,
message: 'Operación exitosa',
type: ToastType.success,
),
child: const Text('Toast Success'),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () => SomaToast.show(
context,
message: 'Error en la operación',
type: ToastType.error,
),
child: const Text('Toast Error'),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () => SomaToast.show(
context,
message: 'Información importante',
type: ToastType.info,
),
child: const Text('Toast Info'),
),
const SizedBox(height: 32),
// Colors
_SectionTitle('Paleta de Colores'),
Row(
children: [
Expanded(
child: _ColorBox(
color: Theme.of(context).colorScheme.primary,
label: 'Primary',
),
),
const SizedBox(width: 12),
Expanded(
child: _ColorBox(
color: Theme.of(context).colorScheme.surface,
label: 'Surface',
),
),
],
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: _ColorBox(
color: Theme.of(context).colorScheme.error,
label: 'Error',
),
),
const SizedBox(width: 12),
Expanded(
child: _ColorBox(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
label: 'Surface Variant',
),
),
],
),
const SizedBox(height: 48),
],
),
);
}
}
class _SectionTitle extends StatelessWidget {
final String title;
const _SectionTitle(this.title);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Text(
title,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.onSurface,
),
),
);
}
}
class _ColorBox extends StatelessWidget {
final Color color;
final String label;
const _ColorBox({required this.color, required this.label});
@override
Widget build(BuildContext context) {
return Container(
height: 80,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Theme.of(context).colorScheme.onSurface.withAlpha(51),
),
),
child: Center(
child: Text(
label,
style: TextStyle(
color: _getContrastColor(color),
fontWeight: FontWeight.w600,
),
),
),
);
}
Color _getContrastColor(Color background) {
final luminance = background.computeLuminance();
return luminance > 0.5 ? Colors.black87 : Colors.white;
}
}