[New private chat dialog] Validate input before continuing
Took 19 minutes
This commit is contained in:
parent
c0594fa22b
commit
58f45406e8
|
@ -6,12 +6,17 @@ import '../matrix.dart';
|
||||||
|
|
||||||
class NewPrivateChatDialog extends StatelessWidget {
|
class NewPrivateChatDialog extends StatelessWidget {
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
void submitAction(BuildContext context) async {
|
void submitAction(BuildContext context) async {
|
||||||
if (controller.text.isEmpty) return;
|
if (controller.text.isEmpty) return;
|
||||||
|
if (!_formKey.currentState.validate()) return;
|
||||||
final MatrixState matrix = Matrix.of(context);
|
final MatrixState matrix = Matrix.of(context);
|
||||||
|
|
||||||
|
if ("@" + controller.text.trim() == matrix.client.userID) return;
|
||||||
|
|
||||||
final User user = User(
|
final User user = User(
|
||||||
"@" + controller.text,
|
"@" + controller.text.trim(),
|
||||||
room: Room(id: "", client: matrix.client),
|
room: Room(id: "", client: matrix.client),
|
||||||
);
|
);
|
||||||
final String roomID =
|
final String roomID =
|
||||||
|
@ -33,17 +38,38 @@ class NewPrivateChatDialog extends StatelessWidget {
|
||||||
content: Column(
|
content: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
TextField(
|
Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: TextFormField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
textInputAction: TextInputAction.go,
|
textInputAction: TextInputAction.go,
|
||||||
onSubmitted: (s) => submitAction(context),
|
onFieldSubmitted: (s) => submitAction(context),
|
||||||
|
validator: (value) {
|
||||||
|
if (value.isEmpty) {
|
||||||
|
return 'Please enter a matrix identifier';
|
||||||
|
}
|
||||||
|
final MatrixState matrix = Matrix.of(context);
|
||||||
|
String mxid = "@" + controller.text.trim();
|
||||||
|
if (mxid == matrix.client.userID) {
|
||||||
|
return "You cannot invite yourself";
|
||||||
|
}
|
||||||
|
if(!mxid.contains("@")) {
|
||||||
|
return "Make sure the identifier is valid";
|
||||||
|
}
|
||||||
|
if(!mxid.contains(":")) {
|
||||||
|
return "Make sure the identifier is valid";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: "Enter a username",
|
labelText: "Enter a username",
|
||||||
icon: Icon(Icons.account_circle),
|
icon: Icon(Icons.account_circle),
|
||||||
prefixText: "@",
|
prefixText: "@",
|
||||||
hintText: "username:homeserver"),
|
hintText: "username:homeserver",
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
|
|
Loading…
Reference in a new issue