From 792ec4d731076a9ab34ef35a0cbc7750ba89561e Mon Sep 17 00:00:00 2001 From: Blake Leonard Date: Wed, 8 Mar 2023 15:07:55 -0500 Subject: [PATCH] chore(example): format and fix lint errors Signed-off-by: Blake Leonard --- example/lib/main.dart | 54 +++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 051a75f..9d1b4bb 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -11,19 +11,22 @@ class ExampleTcpSocketWrapper extends TCPSocketWrapper { Future> srvQuery(String domain, bool dnssec) async { final records = await MoxdnsPlugin.srvQuery(domain, false); return records - .map((record) => MoxSrvRecord( - record.priority, - record.weight, - record.target, - record.port, - ),) - .toList(); + .map( + (record) => MoxSrvRecord( + record.priority, + record.weight, + record.target, + record.port, + ), + ) + .toList(); } } void main() { Logger.root.level = Level.ALL; Logger.root.onRecord.listen((record) { + // ignore: avoid_print print('${record.level.name}: ${record.time}: ${record.message}'); }); @@ -54,11 +57,13 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { + final logger = Logger('MyHomePage'); final XmppConnection connection = XmppConnection( RandomBackoffReconnectionPolicy(1, 60), AlwaysConnectedConnectivityManager(), //ExampleTcpSocketWrapper(), // this causes the app to crash - TCPSocketWrapper(true), // Note: you probably want this to be false in a real app + TCPSocketWrapper( + true), // Note: you probably want this to be false in a real app ); TextEditingController jidController = TextEditingController(); TextEditingController passwordController = TextEditingController(); @@ -91,29 +96,38 @@ class _MyHomePageState extends State { Future _buttonPressed() async { if (connected) { await connection.disconnect(); - setState(() {connected = false;}); + setState(() { + connected = false; + }); return; } - setState(() {loading = true;}); + setState(() { + loading = true; + }); connection.setConnectionSettings( ConnectionSettings( jid: JID.fromString(jidController.text), password: passwordController.text, useDirectTLS: true, allowPlainAuth: true, - // otherwise, connecting to some servers will - // cause an app to hang + // otherwise, connecting to some servers will + // cause an app to hang ), ); final result = await connection.connectAwaitable(); - setState(() {connected = result.success; loading = false;}); + setState(() { + connected = result.success; + loading = false; + }); if (result.error != null) { - print(result.error); + logger.severe(result.error); if (context.mounted) { - showDialog(context: context, builder: (_) => AlertDialog( - title: const Text('Error'), - content: Text(result.error.toString()), - )); + showDialog( + context: context, + builder: (_) => AlertDialog( + title: const Text('Error'), + content: Text(result.error.toString()), + )); } } } @@ -133,14 +147,14 @@ class _MyHomePageState extends State { TextField( enabled: !loading, controller: jidController, - decoration: InputDecoration( + decoration: const InputDecoration( labelText: 'JID', ), ), TextField( enabled: !loading, controller: passwordController, - decoration: InputDecoration( + decoration: const InputDecoration( labelText: 'Password', ), obscureText: true,