How do I use local auth and bar code scanner in the same flutter project? - flutter

I building a flutter app that scans bar codes and also uses biometric auth in it. The problem is for package local_auth
MainActivity.kt should be like
import io.flutter.embedding.android.FlutterFragmentActivity;
public class MainActivity extends FlutterFragmentActivity {
// ...
}
but for scaning bar codes MainActivity.kt should be like
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
else it don't work. How do I use them both in the same project?

Currently you have to replace FlutterActivity with FlutterFragmentActivity yourself in FlutterBarcodeScannerPlugin.java (like this).
So you would want to use a fork of the flutter_barcode_scanner plugin where FlutterFragmentActivity is used or you use some other barcode scanner plugin.

Related

How do I use multiple main activities in flutter?

I am building a flutter app which has these two plugins 1) local_auth 2) flutter_bar_code and they both use different main activities , for local auth the MainActivity.kt is like
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
}
and for flutter bar code scanner the MainActivity.tk is like
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
Flutter has a single MainActivity file. if you want to add more screen then please read doc and blogs here is one for you: Add Multiple screen

User isn't a type so it can't be used as a type argument

Recently i tried to develop some flutter apps using firebase, and i follow along the tutorial on the youtube how to make connection with it, but i got trouble when in the video, the person hover his cursor to some word, and it showed option for correction and add some library in it, and in my case, there's no option for adding the library, but to make some class or mixin.
Here's mine
And This is the tutorial
import 'package:firebase_auth/firebase_auth.dart';
import 'package:get/get.dart';
class AuthController extends GetxController{
static AuthController instance = Get.find();
Rx<User?> _user;
FirebaseAuth auth = FirebaseAuth.instance;
#override
void onReady(){
super.onReady();
_user = Rx<User?>(auth.currentUser)
}
}
The problem was in Rx<User?>, i already add the library manually, but still have the same error message
The name 'User' isn't a type so it can't be used as a type argument.
Android studio needs to re index the dependencies.
have a look at the solution here (similar case):
https://stackoverflow.com/a/24406882/11914081

Flutter only import library in debug mode

I am using Android 11 Wireless Debugging to develop my app. Whenever the device automatically locks itself, it takes a while to re-establish the connection for hot reloading.
To overcome this I am using wakelock, which I only need to use if my app is in debug mode, not in release mode.
In lib/main.dart I have the following code:
import 'package:flutter/foundation.dart' as Foundation;
import 'package:wakelock/wakelock.dart';
...
void main() {
if (Foundation.kDebugMode) {
Wakelock.enable();
}
runApp(App());
}
As you can see the wakelock package is only used if the app is running in debug mode.
Is there a way to only import wakelock if the app is running in debug mode?
Tested it as
pubspec.yaml
dev_dependencies:
wakelock: ^0.2.1+1
Usage
import 'package:flutter/foundation.dart';
import 'package:wakelock/wakelock.dart';
import 'package:flutter/material.dart';
main() async {
WidgetsFlutterBinding.ensureInitialized();
if (kDebugMode) {
print('activating wakelock in debug');
Wakelock.enable();
}
runApp(App());
}
Sidenote:
If all you need is the device to stop locking itself after some time then try increasing the sleep delay under the Display setting on the device itself, or use a setting in developer options called Stay awake while charging which allows the device to stay on forever while charging.

Disable screenshot in flutter

How to disable screenshot in flutter? I have Kotlin file instead of MainActivity.java file. Please suggest full code with path where I need to change for disable screenshot in my app.
package com.quotster.untitled
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
If you want to do that in Android only you can use flutter_windowmanager and add FLAG_SECURE.
await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);

In flutter how to prevent screenshot to secure my app for android part in kotlin

In my flutter app, it supports the kotlin for android part. i can't find a code to prevent the screeenshot in app which is written in kotlin language. I searched over the google then i found the code that is written in java language but i require the kotlin code to prevent the screenshot.
package com.example.schoolbells
import io.flutter.embedding.android.FlutterActivity
import android.os.Bundle;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
import android.view.WindowManager.LayoutParams;
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE);
}
}
getting this error in onCreate method
[ERROR] :Unresolved reference: WindowManagerkotlin(UNRESOLVED_REFERENCE)
I tried this code in kotlin but getting error.
Is there any other way to prevent screenshot in flutter?