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.
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
I have a dart function someFunction which takes a couple of minutes to run (it has a good amount of network requests it awaits on). Currently when I run the function and move my app to the background it seems that the requests that were queued up before leaving the app are executed, but then the function stops, and also doesn't resume when I return to the app. What I would like to do is to have the function run in the background until completion, even if the app is not in the foreground, and also send a notification once the function finishes if the app is not in the foreground.
I've looked at some solutions like the background-fetch plugin and isolates, but unless im missing something they seem to be only for native code, or periodical background tasks. What i'm looking for is a task that runs once no matter what and returns back to the main thread with a result it can react to
The non Dart dependencies of the function incase this is relevant:
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
have you try this package, workmanager with WidgetsBindingObserver (App lifecycle)?
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
//Do whatever you want in background
if (state == AppLifecycleState.paused ||
state == AppLifecycleState.detached) {
}
}
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);
I just began learning flutter and built the sample app present in Building Layout tutorial.
In the source code it's suggested to un-comment two lines, to see the visual debug lines, but so far no luck.
import 'package:flutter/material.dart';
// Uncomment lines 7 and 10 to view the visual layout at runtime.
//import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;
void main() {
//debugPaintSizeEnabled = true;
runApp(new MyApp());
}
What I have tried?
Hot Reload
Full Restart
Setting other debug variables to true:
debugPaintPointersEnabled =
debugPaintBaselinesEnabled =
debugPaintLayerBordersEnabled =
debugRepaintRainbowEnabled = true;
, which I read from Docs. They worked fine.
My Setup?
Visual Studio Code
No Dart 2 Preview Mode
Flutter Beta
I use an Android Mobile Hardware, not Virtual (Moto G5)
Question: How to make the visual debugger work?
I had exactly the same problem and the only solution i found, is to toggle debug painting from VSCode command palette.
Flutter: Toggle Debug Painting
You can also make it works using the rendering library.
First you need to import it
import 'package:flutter/rendering.dart';
Then, set debugPaintSizeEnabled to true in the main method of your application or in a widget's build method
void main() {
debugPaintSizeEnabled=true;
runApp(MyApp());
}
You need to fully restart your application to apply effects
Here's the official documentation.
Add import statements :
import 'dart:developer';
import 'package:flutter/rendering.dart';
Then in the build add the debugPaintSizeEnabled=true; like :
Widget build(BuildContext context) {
debugPaintSizeEnabled=true;
It's not necessary import anything in VSCode, just:
Open command palette by Ctrl+Shift+P (Cmd for mac)
Type Flutter: Toggle Debug Painting and click on it: example.
I think you need import 'package:flutter/rendering.dart';
UPDATE
The following steps work on both android device and android
virtual device if you are working with ANDROID STUDIO. It works only
on Android virtual device if you are working wih VSCode
I was following the same tutorial recently to learn all about the layout elements in Flutter.
To enable visual layout at runtime, what I did was quite straightforward -
First
I added import 'package:flutter/rendering.dart' show debugPaintSizeEnabled; at the top of my main.dart file
Next
I added debugPaintSizeEnabled = true; to my main() method
void main() {
debugPaintSizeEnabled = true;
runApp(new MyApp());
}
Finally
I performed a full restart of my app to reflect all the changes. It doesn't reflect changes if you perform a hot reload.
Hope this helps.
In the terminal press 'p'
To toggle the display of construction lines (debugPaintSizeEnabled), press "p".
(this is the easiest option!)
import 'package:flutter/material.dart';
void main() {
debugPaintSizeEnabled = true;
runApp(new MyApp()); }
Open command palette by CTRL + SHIFT + P (for window),
type Flutter: Toggle Debug Painting and click on it.
I had the same issue, wasn't able to see any debug information.
Fixed it by running in debug mode instead of profile or release.
Maybe this will help someone.