How do I use multiple main activities in flutter? - 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

Related

flutter: how to hide the top bar of an app

How can I hide the topbar of an app in flutter? I want to restrict users from closing the app.
Solution:
Add to dependencies window_manager: ^0.2.8
Import in main.dart import 'package:window_manager/window_manager.dart';
Place the following code
runApp(App());
windowManager.waitUntilReadyToShow().then((_) async{
await windowManager.setTitleBarStyle(TitleBarStyle.hidden);
});

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

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.

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?

ui4j - Possible to screenshot the whole page?

I would like to capture a screenshot of a website including content that you can only see if you scrolled down.
Is that possible?
EDIT:
I already tried https://github.com/ui4j/ui4j/blob/master/ui4j-sample/src/main/java/com/ui4j/sample/ScreenCapture.java, but it did not capture the whole page, just the visible portion(inside my monitor's viewport).
page.show(true);
page.captureScreen(new FileOutputStream(file));
Yes, you could capture screenshot of the whole page with ui4j. Sample code:
package com.ui4j.sample;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.ui4j.api.browser.BrowserFactory;
import com.ui4j.api.browser.Page;
public class ScreenCapture {
public static void main(String[] args) throws FileNotFoundException {
Page page = BrowserFactory.getWebKit().navigate("https://www.google.com");
page.show(true);
page.captureScreen(new FileOutputStream(new File("google.png")));
}
}
Alternative solution:
I highly recommend to use cdp4j library for full page screen capture. Its a Java library which help to automate Chrome/Chromium based browser. Here is the sample code.