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 <me@blakes.dev>
This commit is contained in:
Blake Leonard 2023-03-08 14:09:37 -05:00
parent 7b215d5c6e
commit 60c89e28d3
No known key found for this signature in database
GPG Key ID: C1C57FDCC13B90D0

View File

@ -87,7 +87,7 @@ class _MyHomePageState extends State<MyHomePage> {
SaslScramNegotiator(8, '', '', ScramHashType.sha1), SaslScramNegotiator(8, '', '', ScramHashType.sha1),
]); ]);
} }
Future<void> _buttonPressed() async { Future<void> _buttonPressed() async {
if (connected) { if (connected) {
await connection.disconnect(); await connection.disconnect();
@ -100,13 +100,22 @@ class _MyHomePageState extends State<MyHomePage> {
jid: JID.fromString(jidController.text), jid: JID.fromString(jidController.text),
password: passwordController.text, password: passwordController.text,
useDirectTLS: true, useDirectTLS: true,
allowPlainAuth: false, allowPlainAuth: true,
// otherwise, connecting to some servers will // otherwise, connecting to some servers will
// cause an app to hang // cause an app to hang
), ),
); );
await connection.connect(); final result = await connection.connectAwaitable();
setState(() {connected = true; loading = false;}); 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 @override