mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
87 lines
2.1 KiB
Dart
87 lines
2.1 KiB
Dart
import 'package:comunic/utils/input_utils.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
|
|
///
|
|
/// @author Pierre Hubert
|
|
|
|
/// Ask the user to enter an URL
|
|
Future<String> showInputURLDialog({
|
|
@required BuildContext context,
|
|
@required String title,
|
|
String initialURL,
|
|
}) async {
|
|
return await showDialog(
|
|
context: context,
|
|
builder: (c) => _InputURLDialog(
|
|
title: title,
|
|
initialURL: initialURL,
|
|
),
|
|
);
|
|
}
|
|
|
|
class _InputURLDialog extends StatefulWidget {
|
|
final String title;
|
|
final String initialURL;
|
|
|
|
const _InputURLDialog({
|
|
Key key,
|
|
@required this.title,
|
|
@required this.initialURL,
|
|
}) : assert(title != null),
|
|
super(key: key);
|
|
|
|
@override
|
|
__InputURLDialogState createState() => __InputURLDialogState();
|
|
}
|
|
|
|
class __InputURLDialogState extends State<_InputURLDialog> {
|
|
TextEditingController _controller;
|
|
|
|
bool get _isValid =>
|
|
_controller.text.isNotEmpty && validateUrl(_controller.text);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = new TextEditingController(text: widget.initialURL);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text(widget.title),
|
|
content: TextField(
|
|
controller: _controller,
|
|
onChanged: (s) => setState(() {}),
|
|
decoration: InputDecoration(
|
|
icon: Icon(Icons.link),
|
|
alignLabelWithHint: true,
|
|
labelText: "http://...",
|
|
errorText: _controller.text.isNotEmpty && !_isValid
|
|
? tr("Invalid URL!")
|
|
: 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,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|