flutter_scan
flutter_scan copied to clipboard
dark screen in android
library version : 1.6.0 android sdk : 31
I will check
We meet this issue on Android as well
Here is what happens:
- There is a page on our app with a button to open the scan, and a textfield
- When clicking on the textfield, the keyboard appears
- If we click on the button that opens the scan camera while the keyboard is opened, we also see that dark screen
ℹ️ Note that the scanning system still works though. We can still scan barcodes but we don't see what we scan (as the screen is fully dark)
oh、someone meet this issue too、you can solve this problem just close the keyboard before scan---- On 星期一, 03 一月 2022 22:12:41 +0800 ***@***.******@***.***> wrote ----
We meet this issue on Android as well
Here is what happens:
There is a page on our app with a button to open the scan, and a textfield
When clicking on the textfield, the keyboard appears
If we click on the button that opens the scan camera while the keyboard is opened, we also see that dark screen
ℹ️ Note that the scanning system still works though. We can still scan barcodes but we don't see what we scan (as the screen is fully dark)
—Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.Message ID: @.***>
#31
@DJafari Just use it like this :
Future goToScanPage() async { await unfocus(); Future.delayed(const Duration(milliseconds: 500), () { Navigator.push( context, MaterialPageRoute( builder: (context) { return Scan(); } ) ); } ); }
Future unFocus() async { FocusManager.instance.primaryFocus?.unfocus(); }
any update on this?
write like this can resolve this problem:
/// Use WidgetsBindingObserver to monitor keyboard pop-up and retract events
class _ScanToolState extends State<ScanTool> with WidgetsBindingObserver {
/// A completer that monitors whether the keyboard is retracted or not
Completer _keyboardBackCompleter = Completer()..complete(true);
@override
void initState() {
/// Add listener object
WidgetsBinding.instance.addObserver(this);
super.initState();
}
@override
void didChangeMetrics() {
/// add callback
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
if(MediaQuery.of(context).viewInsets.bottom==0){
/// The keyboard is retracted (the keyboard retracts once, and it will be triggered several times here)
if(!_keyboardBackCompleter.isCompleted) {
_keyboardBackCompleter.complete(true);
}
}else{
/// The keyboard pops up (once the keyboard pops up, it will be triggered several times here)
if(_keyboardBackCompleter.isCompleted) {
_keyboardBackCompleter = Completer();
}
}
});
});
super.didChangeMetrics();
}
/// enter scanPage method
scanCode() async {
/// here write your unfocus method
unfocus();
await _keyboardBackCompleter.future;
/// Here you can ensure that the keyboard must be retracted,then you can jump to the scan page
Navigator.of(context).push.........
}