google preperation 1
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services/app_settings.dart';
|
||||
|
||||
/// Dark dialog with one text field. Returns the trimmed text, or null if cancelled.
|
||||
/// [onReset] adds a secondary button ([resetLabel], default "Reset to Default") that closes the dialog.
|
||||
Future<String?> showTextPrompt(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
String? message,
|
||||
String initial = '',
|
||||
String? hint,
|
||||
TextInputType keyboardType = TextInputType.text,
|
||||
String? confirmLabel,
|
||||
String? resetLabel,
|
||||
VoidCallback? onReset,
|
||||
}) {
|
||||
final s = AppSettings.instance;
|
||||
final controller = TextEditingController(text: initial);
|
||||
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (dialog) => AlertDialog(
|
||||
title: Text(title),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (message != null) ...[
|
||||
Text(message),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
keyboardType: keyboardType,
|
||||
autocorrect: false,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
cursorColor: s.bulletColor,
|
||||
decoration: InputDecoration(
|
||||
hintText: hint,
|
||||
hintStyle: const TextStyle(color: Colors.white38),
|
||||
filled: true,
|
||||
fillColor: Colors.white10,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: s.bulletColor),
|
||||
),
|
||||
),
|
||||
onSubmitted: (v) => Navigator.pop(dialog, v.trim()),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (onReset != null)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
onReset();
|
||||
Navigator.pop(dialog);
|
||||
},
|
||||
child: Text(resetLabel ?? s.t('Reset to Default'), style: const TextStyle(color: Colors.white54)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialog),
|
||||
child: Text(s.t('Cancel'), style: const TextStyle(color: Colors.white70)),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: s.bulletColor),
|
||||
onPressed: () => Navigator.pop(dialog, controller.text.trim()),
|
||||
child: Text(confirmLabel ?? s.t('Save')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user