mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-29 16:26:27 +00:00
80 lines
2.1 KiB
Dart
80 lines
2.1 KiB
Dart
import 'package:comunic/utils/intl_utils.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Ask the user to enter an URL
|
|
class SingleInputDialog extends StatefulWidget {
|
|
final String title;
|
|
final IconData icon;
|
|
final String initialValue;
|
|
final String label;
|
|
final bool Function(String) checkInput;
|
|
final String errorMessage;
|
|
|
|
const SingleInputDialog({
|
|
Key key,
|
|
@required this.title,
|
|
@required this.icon,
|
|
@required this.initialValue,
|
|
@required this.label,
|
|
@required this.checkInput,
|
|
@required this.errorMessage,
|
|
}) : assert(title != null),
|
|
assert(icon != null),
|
|
assert(label != null),
|
|
assert(checkInput != null),
|
|
assert(errorMessage != null),
|
|
super(key: key);
|
|
|
|
@override
|
|
__InputURLDialogState createState() => __InputURLDialogState();
|
|
}
|
|
|
|
class __InputURLDialogState extends State<SingleInputDialog> {
|
|
TextEditingController _controller;
|
|
|
|
bool get _isValid =>
|
|
_controller.text.isNotEmpty && widget.checkInput(_controller.text);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = new TextEditingController(text: widget.initialValue);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text(widget.title),
|
|
content: TextField(
|
|
controller: _controller,
|
|
onChanged: (s) => setState(() {}),
|
|
decoration: InputDecoration(
|
|
icon: Icon(widget.icon),
|
|
alignLabelWithHint: true,
|
|
labelText: widget.label,
|
|
errorText: _controller.text.isNotEmpty && !_isValid
|
|
? widget.errorMessage
|
|
: null,
|
|
),
|
|
),
|
|
actions: <Widget>[
|
|
// Cancel
|
|
MaterialButton(
|
|
child: Text(tr("Cancel").toUpperCase()),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
textColor: Colors.red,
|
|
),
|
|
|
|
// Confirm
|
|
MaterialButton(
|
|
child: Text(tr("Confirm").toUpperCase()),
|
|
onPressed: _isValid
|
|
? () => Navigator.of(context).pop(_controller.text)
|
|
: null,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|