chore(example): format and fix lint errors
Signed-off-by: Blake Leonard <me@blakes.dev>
This commit is contained in:
parent
60c89e28d3
commit
792ec4d731
@ -11,19 +11,22 @@ class ExampleTcpSocketWrapper extends TCPSocketWrapper {
|
|||||||
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
|
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
|
||||||
final records = await MoxdnsPlugin.srvQuery(domain, false);
|
final records = await MoxdnsPlugin.srvQuery(domain, false);
|
||||||
return records
|
return records
|
||||||
.map((record) => MoxSrvRecord(
|
.map(
|
||||||
record.priority,
|
(record) => MoxSrvRecord(
|
||||||
record.weight,
|
record.priority,
|
||||||
record.target,
|
record.weight,
|
||||||
record.port,
|
record.target,
|
||||||
),)
|
record.port,
|
||||||
.toList();
|
),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
Logger.root.level = Level.ALL;
|
Logger.root.level = Level.ALL;
|
||||||
Logger.root.onRecord.listen((record) {
|
Logger.root.onRecord.listen((record) {
|
||||||
|
// ignore: avoid_print
|
||||||
print('${record.level.name}: ${record.time}: ${record.message}');
|
print('${record.level.name}: ${record.time}: ${record.message}');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -54,11 +57,13 @@ class MyHomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
final logger = Logger('MyHomePage');
|
||||||
final XmppConnection connection = XmppConnection(
|
final XmppConnection connection = XmppConnection(
|
||||||
RandomBackoffReconnectionPolicy(1, 60),
|
RandomBackoffReconnectionPolicy(1, 60),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
//ExampleTcpSocketWrapper(), // this causes the app to crash
|
//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 jidController = TextEditingController();
|
||||||
TextEditingController passwordController = TextEditingController();
|
TextEditingController passwordController = TextEditingController();
|
||||||
@ -91,29 +96,38 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
Future<void> _buttonPressed() async {
|
Future<void> _buttonPressed() async {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
await connection.disconnect();
|
await connection.disconnect();
|
||||||
setState(() {connected = false;});
|
setState(() {
|
||||||
|
connected = false;
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {loading = true;});
|
setState(() {
|
||||||
|
loading = true;
|
||||||
|
});
|
||||||
connection.setConnectionSettings(
|
connection.setConnectionSettings(
|
||||||
ConnectionSettings(
|
ConnectionSettings(
|
||||||
jid: JID.fromString(jidController.text),
|
jid: JID.fromString(jidController.text),
|
||||||
password: passwordController.text,
|
password: passwordController.text,
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
// otherwise, connecting to some servers will
|
// otherwise, connecting to some servers will
|
||||||
// cause an app to hang
|
// cause an app to hang
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final result = await connection.connectAwaitable();
|
final result = await connection.connectAwaitable();
|
||||||
setState(() {connected = result.success; loading = false;});
|
setState(() {
|
||||||
|
connected = result.success;
|
||||||
|
loading = false;
|
||||||
|
});
|
||||||
if (result.error != null) {
|
if (result.error != null) {
|
||||||
print(result.error);
|
logger.severe(result.error);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
showDialog(context: context, builder: (_) => AlertDialog(
|
showDialog(
|
||||||
title: const Text('Error'),
|
context: context,
|
||||||
content: Text(result.error.toString()),
|
builder: (_) => AlertDialog(
|
||||||
));
|
title: const Text('Error'),
|
||||||
|
content: Text(result.error.toString()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,14 +147,14 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
TextField(
|
TextField(
|
||||||
enabled: !loading,
|
enabled: !loading,
|
||||||
controller: jidController,
|
controller: jidController,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'JID',
|
labelText: 'JID',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
enabled: !loading,
|
enabled: !loading,
|
||||||
controller: passwordController,
|
controller: passwordController,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Password',
|
labelText: 'Password',
|
||||||
),
|
),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user