a7c41063fa
Keep the Material-only settings implementation and its focused tests while preserving public cupertino parameters for later cleanup. This removes unreachable platform-specific widgets and test variants without changing the Material path.
145 lines
3.6 KiB
Dart
145 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../ui/theme/custom_fonts/custom_font_draft.dart';
|
|
|
|
const customFontNameLabel = 'Name';
|
|
const addCustomFontTitle = 'Add font';
|
|
const renameCustomFontTitle = 'Rename font';
|
|
const addCustomFontFailedTitle = 'Could not add font';
|
|
|
|
/// Asks for a font family's name, prefilled with [initial]; null when
|
|
/// cancelled. [detail] lists what is being added.
|
|
Future<String?> showFontNameDialog(
|
|
BuildContext context, {
|
|
required String title,
|
|
required String initial,
|
|
required String confirm,
|
|
String? detail,
|
|
}) {
|
|
final dialog = _FontNameDialog(
|
|
title: title,
|
|
initial: initial,
|
|
confirm: confirm,
|
|
detail: detail,
|
|
);
|
|
return showDialog<String>(context: context, builder: (_) => dialog);
|
|
}
|
|
|
|
class _FontNameDialog extends StatefulWidget {
|
|
const _FontNameDialog({
|
|
required this.title,
|
|
required this.initial,
|
|
required this.confirm,
|
|
this.detail,
|
|
});
|
|
|
|
final String title;
|
|
final String initial;
|
|
final String confirm;
|
|
final String? detail;
|
|
|
|
@override
|
|
State<_FontNameDialog> createState() => _FontNameDialogState();
|
|
}
|
|
|
|
class _FontNameDialogState extends State<_FontNameDialog> {
|
|
late final TextEditingController _name = TextEditingController(
|
|
text: widget.initial,
|
|
);
|
|
String? _problem;
|
|
|
|
@override
|
|
void dispose() {
|
|
_name.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _submit() {
|
|
final problem = CustomFontLimits.nameProblem(_name.text);
|
|
if (problem != null) {
|
|
setState(() => _problem = problem);
|
|
return;
|
|
}
|
|
Navigator.pop(context, _name.text.trim());
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final field = TextField(
|
|
controller: _name,
|
|
autofocus: true,
|
|
maxLength: CustomFontLimits.maxNameLength,
|
|
decoration: InputDecoration(
|
|
labelText: customFontNameLabel,
|
|
errorText: _problem,
|
|
),
|
|
onSubmitted: (_) => _submit(),
|
|
);
|
|
final content = Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
if (widget.detail != null) ...<Widget>[
|
|
Text(widget.detail!),
|
|
const SizedBox(height: 12),
|
|
],
|
|
field,
|
|
],
|
|
);
|
|
return AlertDialog(
|
|
title: Text(widget.title),
|
|
content: SingleChildScrollView(child: content),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(onPressed: _submit, child: Text(widget.confirm)),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Confirms deleting an added font; true when the user agrees.
|
|
Future<bool> confirmRemoveFont(BuildContext context, String name) async {
|
|
final title = Text('Remove $name?');
|
|
const body = Text('Its files are deleted from this device.');
|
|
final confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: title,
|
|
content: body,
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: const Text('Remove'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
return confirmed ?? false;
|
|
}
|
|
|
|
/// Says why a font could not be added or changed.
|
|
Future<void> showFontProblem(
|
|
BuildContext context,
|
|
String title,
|
|
String message,
|
|
) => showDialog<void>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: Text(title),
|
|
content: Text(message),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('OK'),
|
|
),
|
|
],
|
|
),
|
|
);
|