|
@@ -26,6 +26,7 @@ class _MyAppState extends State<MyApp> {
|
26
|
26
|
String? _connectedPrinter;
|
27
|
27
|
final _flutterZsdkPlugin = FlutterZsdk();
|
28
|
28
|
String? _selectedBluetoothPrinterMacAddress;
|
|
29
|
+ bool _disconnecting = false;
|
29
|
30
|
|
30
|
31
|
@override
|
31
|
32
|
void initState() {
|
|
@@ -127,6 +128,29 @@ class _MyAppState extends State<MyApp> {
|
127
|
128
|
setState(() {});
|
128
|
129
|
}
|
129
|
130
|
|
|
131
|
+ Future<void> closeConnection() async {
|
|
132
|
+ print('invoked closeConnection from dart');
|
|
133
|
+ try {
|
|
134
|
+ setState(() {
|
|
135
|
+ _disconnecting = true;
|
|
136
|
+ });
|
|
137
|
+ await _flutterZsdkPlugin.closeConnection();
|
|
138
|
+ _connectedPrinter = null;
|
|
139
|
+ _disconnecting = false;
|
|
140
|
+ print('Connection closed successfully from dart');
|
|
141
|
+
|
|
142
|
+ } on FlutterZsdkException catch (e) {
|
|
143
|
+ inspect(e);
|
|
144
|
+ showSnackBar(e.message);
|
|
145
|
+
|
|
146
|
+ } catch (e) {
|
|
147
|
+ inspect(e);
|
|
148
|
+ showSnackBar('Unexpected error while disconnecting bluetooth printers');
|
|
149
|
+ }
|
|
150
|
+
|
|
151
|
+ setState(() {});
|
|
152
|
+ }
|
|
153
|
+
|
130
|
154
|
@override
|
131
|
155
|
Widget build(BuildContext context) {
|
132
|
156
|
return Scaffold(
|
|
@@ -148,6 +172,12 @@ class _MyAppState extends State<MyApp> {
|
148
|
172
|
),
|
149
|
173
|
SizedBox(height: 20),
|
150
|
174
|
|
|
175
|
+ ElevatedButton(
|
|
176
|
+ child: Text(_disconnecting ? 'Disconnecting...' : 'Disconnect from $_connectedPrinter'),
|
|
177
|
+ onPressed: _connectedPrinter == null || _disconnecting ? null : closeConnection,
|
|
178
|
+ ),
|
|
179
|
+ SizedBox(height: 20),
|
|
180
|
+
|
151
|
181
|
ElevatedButton(
|
152
|
182
|
child: Text('Check connection status'),
|
153
|
183
|
onPressed: () async {
|