144 lines
5.5 KiB
Dart
144 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:trainhub_flutter/core/constants/ui_constants.dart';
|
|
import 'package:trainhub_flutter/core/theme/app_colors.dart';
|
|
|
|
class TextInputDialog {
|
|
TextInputDialog._();
|
|
|
|
static Future<String?> show(
|
|
BuildContext context, {
|
|
required String title,
|
|
String? hintText,
|
|
String? initialValue,
|
|
String confirmLabel = 'Create',
|
|
}) {
|
|
final controller = TextEditingController(text: initialValue);
|
|
|
|
return showDialog<String>(
|
|
context: context,
|
|
builder: (context) => Dialog(
|
|
backgroundColor: AppColors.surfaceContainer,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: UIConstants.cardBorderRadius,
|
|
side: const BorderSide(color: AppColors.border),
|
|
),
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: UIConstants.dialogWidth),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(UIConstants.pagePadding),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: GoogleFonts.inter(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
),
|
|
const SizedBox(height: UIConstants.spacing16),
|
|
TextField(
|
|
controller: controller,
|
|
autofocus: true,
|
|
style: GoogleFonts.inter(
|
|
fontSize: 14,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
cursorColor: AppColors.accent,
|
|
decoration: InputDecoration(
|
|
hintText: hintText,
|
|
hintStyle: GoogleFonts.inter(
|
|
fontSize: 14,
|
|
color: AppColors.textMuted,
|
|
),
|
|
filled: true,
|
|
fillColor: AppColors.zinc950,
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: UIConstants.spacing12,
|
|
vertical: UIConstants.spacing12,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: UIConstants.smallCardBorderRadius,
|
|
borderSide: const BorderSide(color: AppColors.border),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: UIConstants.smallCardBorderRadius,
|
|
borderSide: const BorderSide(color: AppColors.border),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: UIConstants.smallCardBorderRadius,
|
|
borderSide: const BorderSide(color: AppColors.accent),
|
|
),
|
|
),
|
|
onSubmitted: (value) {
|
|
final text = value.trim();
|
|
if (text.isNotEmpty) {
|
|
Navigator.of(context).pop(text);
|
|
}
|
|
},
|
|
),
|
|
const SizedBox(height: UIConstants.spacing24),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: AppColors.textSecondary,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: UIConstants.smallCardBorderRadius,
|
|
),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: UIConstants.spacing16,
|
|
vertical: UIConstants.spacing12,
|
|
),
|
|
),
|
|
child: Text(
|
|
'Cancel',
|
|
style: GoogleFonts.inter(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: UIConstants.spacing8),
|
|
FilledButton(
|
|
onPressed: () {
|
|
final text = controller.text.trim();
|
|
if (text.isNotEmpty) {
|
|
Navigator.of(context).pop(text);
|
|
}
|
|
},
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: AppColors.accent,
|
|
foregroundColor: AppColors.zinc950,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: UIConstants.smallCardBorderRadius,
|
|
),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: UIConstants.spacing16,
|
|
vertical: UIConstants.spacing12,
|
|
),
|
|
),
|
|
child: Text(
|
|
confirmLabel,
|
|
style: GoogleFonts.inter(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|