mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can create weblink posts
This commit is contained in:
86
lib/ui/dialogs/url_dialog.dart
Normal file
86
lib/ui/dialogs/url_dialog.dart
Normal file
@ -0,0 +1,86 @@
|
||||
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,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user