mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Improve update message dialog
This commit is contained in:
		@@ -93,6 +93,7 @@ Future<String> askUserString({
 | 
			
		||||
  @required String defaultValue,
 | 
			
		||||
  @required String hint,
 | 
			
		||||
  int maxLength = 200,
 | 
			
		||||
  int minLength = 1,
 | 
			
		||||
}) async {
 | 
			
		||||
  assert(context != null);
 | 
			
		||||
  assert(title != null);
 | 
			
		||||
@@ -105,35 +106,13 @@ Future<String> askUserString({
 | 
			
		||||
 | 
			
		||||
  final confirm = await showDialog<bool>(
 | 
			
		||||
      context: context,
 | 
			
		||||
      builder: (c) => AlertDialog(
 | 
			
		||||
            title: Text(title),
 | 
			
		||||
            content: AutoSizeDialogContentWidget(
 | 
			
		||||
              child: Column(
 | 
			
		||||
                children: <Widget>[
 | 
			
		||||
                  Text(message),
 | 
			
		||||
                  TextField(
 | 
			
		||||
                    controller: controller,
 | 
			
		||||
                    maxLines: null,
 | 
			
		||||
                    maxLength: maxLength,
 | 
			
		||||
                    keyboardType: TextInputType.text,
 | 
			
		||||
                    decoration: InputDecoration(
 | 
			
		||||
                      labelText: hint,
 | 
			
		||||
                      alignLabelWithHint: true,
 | 
			
		||||
                    ),
 | 
			
		||||
                  )
 | 
			
		||||
                ],
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
            actions: <Widget>[
 | 
			
		||||
              FlatButton(
 | 
			
		||||
                child: Text(tr("Cancel").toUpperCase()),
 | 
			
		||||
                onPressed: () => Navigator.pop(c, false),
 | 
			
		||||
              ),
 | 
			
		||||
              FlatButton(
 | 
			
		||||
                child: Text(tr("OK")),
 | 
			
		||||
                onPressed: () => Navigator.pop(c, true),
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
      builder: (c) => _InputTextDialog(
 | 
			
		||||
            title: title,
 | 
			
		||||
            message: message,
 | 
			
		||||
            controller: controller,
 | 
			
		||||
            maxLength: maxLength,
 | 
			
		||||
            minLength: minLength,
 | 
			
		||||
            hint: hint,
 | 
			
		||||
          ));
 | 
			
		||||
 | 
			
		||||
  if (confirm == null || !confirm) return null;
 | 
			
		||||
@@ -141,6 +120,65 @@ Future<String> askUserString({
 | 
			
		||||
  return controller.text;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _InputTextDialog extends StatefulWidget {
 | 
			
		||||
  final String title;
 | 
			
		||||
  final String message;
 | 
			
		||||
  final TextEditingController controller;
 | 
			
		||||
  final int maxLength;
 | 
			
		||||
  final int minLength;
 | 
			
		||||
  final String hint;
 | 
			
		||||
 | 
			
		||||
  const _InputTextDialog({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.title,
 | 
			
		||||
    @required this.message,
 | 
			
		||||
    @required this.controller,
 | 
			
		||||
    @required this.maxLength,
 | 
			
		||||
    @required this.minLength,
 | 
			
		||||
    @required this.hint,
 | 
			
		||||
  }) : super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  __InputTextDialogState createState() => __InputTextDialogState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class __InputTextDialogState extends State<_InputTextDialog> {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext c) => AlertDialog(
 | 
			
		||||
        title: Text(widget.title),
 | 
			
		||||
        content: AutoSizeDialogContentWidget(
 | 
			
		||||
          child: Column(
 | 
			
		||||
            children: <Widget>[
 | 
			
		||||
              Text(widget.message),
 | 
			
		||||
              TextField(
 | 
			
		||||
                controller: widget.controller,
 | 
			
		||||
                maxLines: null,
 | 
			
		||||
                maxLength: widget.maxLength,
 | 
			
		||||
                keyboardType: TextInputType.text,
 | 
			
		||||
                onChanged: (s) => setState(() {}),
 | 
			
		||||
                decoration: InputDecoration(
 | 
			
		||||
                  labelText: widget.hint,
 | 
			
		||||
                  alignLabelWithHint: true,
 | 
			
		||||
                ),
 | 
			
		||||
              )
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
        actions: <Widget>[
 | 
			
		||||
          FlatButton(
 | 
			
		||||
            child: Text(tr("Cancel").toUpperCase()),
 | 
			
		||||
            onPressed: () => Navigator.pop(c, false),
 | 
			
		||||
          ),
 | 
			
		||||
          FlatButton(
 | 
			
		||||
            child: Text(tr("OK")),
 | 
			
		||||
            onPressed: widget.controller.text.length >= widget.minLength
 | 
			
		||||
                ? () => Navigator.pop(c, true)
 | 
			
		||||
                : null,
 | 
			
		||||
          ),
 | 
			
		||||
        ],
 | 
			
		||||
      );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Show an alert dialog to get user confirmation for something
 | 
			
		||||
///
 | 
			
		||||
/// Return value of this function is never null
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user