Customize input dialog button label

This commit is contained in:
Ming Ming 2021-09-28 12:44:03 +08:00
parent 3d2003de26
commit dc83f49d81
2 changed files with 9 additions and 6 deletions

View file

@ -444,7 +444,9 @@ class _AlbumBrowserState extends State<AlbumBrowser>
void _onEditAppBarAddTextPressed() { void _onEditAppBarAddTextPressed() {
showDialog<String>( showDialog<String>(
context: context, context: context,
builder: (context) => const SimpleInputDialog(), builder: (context) => SimpleInputDialog(
buttonText: MaterialLocalizations.of(context).saveButtonLabel,
),
).then((value) { ).then((value) {
if (value == null) { if (value == null) {
return; return;
@ -467,6 +469,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
showDialog<String>( showDialog<String>(
context: context, context: context,
builder: (context) => SimpleInputDialog( builder: (context) => SimpleInputDialog(
buttonText: MaterialLocalizations.of(context).saveButtonLabel,
initialText: item.text, initialText: item.text,
), ),
).then((value) { ).then((value) {

View file

@ -4,6 +4,7 @@ import 'package:flutter/widgets.dart';
class SimpleInputDialog extends StatefulWidget { class SimpleInputDialog extends StatefulWidget {
const SimpleInputDialog({ const SimpleInputDialog({
Key? key, Key? key,
required this.buttonText,
this.initialText, this.initialText,
this.hintText, this.hintText,
this.validator, this.validator,
@ -12,6 +13,7 @@ class SimpleInputDialog extends StatefulWidget {
@override @override
createState() => _SimpleInputDialogState(); createState() => _SimpleInputDialogState();
final String buttonText;
final String? initialText; final String? initialText;
final String? hintText; final String? hintText;
final FormFieldValidator<String>? validator; final FormFieldValidator<String>? validator;
@ -36,16 +38,14 @@ class _SimpleInputDialogState extends State<SimpleInputDialog> {
), ),
actions: [ actions: [
TextButton( TextButton(
onPressed: _onSavePressed, onPressed: _onButtonPressed,
child: Text( child: Text(widget.buttonText),
MaterialLocalizations.of(context).saveButtonLabel,
),
), ),
], ],
); );
} }
void _onSavePressed() { void _onButtonPressed() {
if (_formKey.currentState?.validate() == true) { if (_formKey.currentState?.validate() == true) {
_formValue = _FormValue(); _formValue = _FormValue();
_formKey.currentState!.save(); _formKey.currentState!.save();