games_app/prediqo_mobile/lib/shared/widgets/pred_text_field.dart
2026-07-25 22:48:54 +02:00

102 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../core/theme/app_colors.dart';
import '../../l10n/app_strings.dart';
class PredTextField extends StatelessWidget {
const PredTextField({
super.key,
required this.controller,
required this.label,
this.obscure = false,
this.keyboardType,
this.prefixIcon,
this.suffix,
this.maxLength,
this.enabled = true,
this.textCapitalization = TextCapitalization.none,
this.inputFormatters,
});
final TextEditingController controller;
final String label;
final bool obscure;
final TextInputType? keyboardType;
final IconData? prefixIcon;
final Widget? suffix;
final int? maxLength;
final bool enabled;
final TextCapitalization textCapitalization;
final List<TextInputFormatter>? inputFormatters;
@override
Widget build(BuildContext context) {
return TextField(
controller: controller,
obscureText: obscure,
keyboardType: keyboardType,
maxLength: maxLength,
enabled: enabled,
textCapitalization: textCapitalization,
inputFormatters: inputFormatters,
decoration: InputDecoration(
labelText: label,
prefixIcon: prefixIcon != null ? Icon(prefixIcon) : null,
suffixIcon: suffix,
counterText: maxLength != null ? '' : null,
),
);
}
}
class PredErrorView extends StatelessWidget {
const PredErrorView({super.key, required this.message, this.onRetry});
final String message;
final VoidCallback? onRetry;
@override
Widget build(BuildContext context) {
final s = context.strings;
return Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.error_outline_rounded, size: 48, color: AppColors.danger.withValues(alpha: 0.9)),
const SizedBox(height: 16),
Text(message, textAlign: TextAlign.center),
if (onRetry != null) ...[
const SizedBox(height: 20),
FilledButton(onPressed: onRetry, child: Text(s.retry)),
],
],
),
),
);
}
}
class PredLoadingView extends StatelessWidget {
const PredLoadingView({super.key, this.message});
final String? message;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const CircularProgressIndicator(),
if (message != null) ...[
const SizedBox(height: 16),
Text(message!, style: Theme.of(context).textTheme.bodyMedium),
],
],
),
);
}
}