Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/dispose on qr controller #6

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class QRCaptureView(id: Int) :
barcodeView?.setTorch(isOn)
}
}

when (call?.method) {
"dispose" -> {
dispose()
}
}
}

private fun resume() {
Expand Down
53 changes: 36 additions & 17 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {

String _captureText = '';

int _captureCount = 0;

@override
void initState() {
super.initState();
Expand All @@ -24,6 +26,7 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
print('$data');
setState(() {
_captureText = data;
_captureCount++;
});
});
}
Expand All @@ -48,6 +51,7 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
await QRCaptureController.getQrCodeByImagePath(image.path);
setState(() {
_captureText = qrCodeResult.join('\n');
_captureCount++;
});
},
child: Text('photoAlbum', style: TextStyle(color: Colors.white)),
Expand All @@ -72,24 +76,21 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
),
Container(
child: Text('$_captureText'),
)
),
Container(
child: Text('Capture count: $_captureCount'),
alignment: Alignment.topCenter.add(Alignment(0, 0.2)),
),
],
),
),
);
}

Widget _buildToolBar() {
return Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () {
_controller.pause();
},
child: Text('pause'),
),
return Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FlatButton(
onPressed: () {
if (_isTorchOn) {
Expand All @@ -99,13 +100,31 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
}
_isTorchOn = !_isTorchOn;
},
child: Text('torch'),
child: Text('\n\ntorch'),
),
FlatButton(
onPressed: () {
_controller.resume();
},
child: Text('resume'),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () {
_controller.pause();
},
child: Text('pause'),
),
FlatButton(
onPressed: () {
_controller.resume();
},
child: Text('resume'),
),
FlatButton(
onPressed: () {
_controller.dispose();
},
child: Text('dispose'),
),
],
),
],
);
Expand Down
2 changes: 2 additions & 0 deletions ios/Classes/QRCaptureView.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
[device setTorchMode:AVCaptureTorchModeOff];
}
[device unlockForConfiguration];
} else if ([call.method isEqualToString:@"dispose"]) {
[self dealloc];
freitzzz marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/qrcode_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class QRCaptureController {
_capture = capture;
}

void dispose() {
_methodChannel?.invokeMethod('dispose');
}

set torchMode(CaptureTorchMode mode) {
var isOn = mode == CaptureTorchMode.on;
_methodChannel?.invokeMethod('setTorchMode', isOn);
Expand Down