From 60c89e28d37925e7406501ded1ea53767b5eeb33 Mon Sep 17 00:00:00 2001 From: Blake Leonard Date: Wed, 8 Mar 2023 14:09:37 -0500 Subject: [PATCH] chore(example): switch to connectAwaitable That way it only acts connected when the credentials have been accepted. Also I had to correct the value of "allowPlainAuth" which should be true since a bug with it has been identified, and not yet fixed. Signed-off-by: Blake Leonard --- example/lib/main.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 710257c..051a75f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -87,7 +87,7 @@ class _MyHomePageState extends State { SaslScramNegotiator(8, '', '', ScramHashType.sha1), ]); } - + Future _buttonPressed() async { if (connected) { await connection.disconnect(); @@ -100,13 +100,22 @@ class _MyHomePageState extends State { jid: JID.fromString(jidController.text), password: passwordController.text, useDirectTLS: true, - allowPlainAuth: false, + allowPlainAuth: true, // otherwise, connecting to some servers will // cause an app to hang ), ); - await connection.connect(); - setState(() {connected = true; loading = false;}); + final result = await connection.connectAwaitable(); + setState(() {connected = result.success; loading = false;}); + if (result.error != null) { + print(result.error); + if (context.mounted) { + showDialog(context: context, builder: (_) => AlertDialog( + title: const Text('Error'), + content: Text(result.error.toString()), + )); + } + } } @override