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

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

Related

Flutter Create Spawns app That Contains Unexpected Folders and Files

The bounty expires in 7 days. Answers to this question are eligible for a +50 reputation bounty.
Nerdy Bunz is looking for a canonical answer.
About a week ago, I created a new flutter project using:
flutter create -t app my_app
But when I opened the resulting project in the IDE, I was surprised to find the project has some key differences compared to what I'm used to:
there is a folder inside the lib folder, "src"
the main.dart does not contain the usual "counter app" and looks like this:
import 'package:flutter/material.dart';
import 'src/app.dart';
import 'src/settings/settings_controller.dart';
import 'src/settings/settings_service.dart';
void main() async {
// Set up the SettingsController, which will glue user settings to multiple
// Flutter Widgets.
final settingsController = SettingsController(SettingsService());
// Load the user's preferred theme while the splash screen is displayed.
// This prevents a sudden theme change when the app is first displayed.
await settingsController.loadSettings();
// Run the app and pass in the SettingsController. The app listens to the
// SettingsController for changes, then passes it further down to the
// SettingsView.
runApp(MyApp(settingsController: settingsController));
}
I tried creating other new projects and I verified it also happened when using "flutter create -t skeleton."
Now, after a week, it seems to have gone back to the old behavior.
Does anyone know the explanation for this?

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.

Flutter, how to take full screenshot

i am trying to find a way to take a screenshot of entire screen. Flutter library is only allowing me to make a screenshot of a widget, but i want a screenshot of entire android.
I did find this link:
How to programmatically take a screenshot on Android?
and this is resolwing my problem, but i tried to use that java code as it is in documentation:
https://flutter.dev/docs/development/platform-integration/platform-channels?tab=android-channel-java-tab
sadly i am not able to run that code, maybie im making some kind of mistakes? i find a error, while i whas following docs instruction, after that program whas working (not exacly, java whas not able to find my battery, but code whas compiling), and then i copy first answer from that stack link and i tried to pase it in "MainActivity" folder, sadly program whas not working, my "old" java code whas comipilng, from the docs, not the new one.
If you know the solution how to make a photo of entire android screen using some kind of buttor in flutter, or how to implement code from that link into my MainActivity.java folder, please help
Try this package native_screenshot
https://pub.dev/packages/native_screenshot
You can simply run this function to take the screenshot of your phone:
Future<void> _capturePng() async {
String path = await NativeScreenshot.takeScreenshot();
print(path);
}
You can learn more about this package here
It work fine with Android and IOS
Hope it will be useful
You can use screenshot plugin:https://pub.dev/packages/screenshot to take a widget screenshot.
A screenshot is a simple plugin to capture widgets as Images. This plugin wraps your widgets inside RenderRepaintBoundary
Use this package as a library
Add this to your package's pubspec.yaml file:
dependencies:
screenshot: ^0.2.0
Now in your Dart code, Import it:
import 'package:screenshot/screenshot.dart';
This handy plugin can be used to capture any Widget including full-screen screenshots & individual widgets like Text().
Create Instance of Screenshot Controller
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
File _imageFile;
//Create an instance of ScreenshotController
ScreenshotController screenshotController = ScreenshotController();
#override
void initState() {
// TODO: implement initState
super.initState();
}
...
}
Wrap the widget that you want to capture inside Screenshot Widget. Assign the controller to screenshotController that you have created earlier
Screenshot(
controller: screenshotController,
child: Text("This text will be captured as image"),
),
Take the screenshot by calling the capture method. This will return a File
screenshotController.capture().then((File image) {
//Capture Done
setState(() {
_imageFile = image;
});
}).catchError((onError) {
print(onError);
});
Duplicate: How to take a screenshot of the current widget - Flutter

Issue : Cant resolve symbol 'firebasemessaging'

I am using Firebase Cloud Messaging for getting notifications. I was getting proper notifications when my app was running but when my app was in background, I used to get this exception on arrival of the notification :
After some digging I got a solution for this where they performed the following changes :
My MyActivity.java :
package ......; /* Package Name*/
import android.os.Bundle;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Application.java :
GeneratedPluginRegistrant.java
And I changed the 'android:name' of tag form "io.flutter.app.FlutterApplication" to ".Application" accordingly :
Now as you can see in the screenshots provided above ..... I am getting errors saying cannot revolves symbol 'Firebasemesseging' etc. (Same 'Cannot resolve' everywhere). Can anyone please help me to fix this error. I am a bit new to Flutter hence I am not sure how to solve this.
Thanks a lot in advance for the help.

Error When Forcing Portrait Orientation in Flutter

I am trying to force my Flutter app to only use Portrait mode. My main() method looks like this.
void main() {
SystemChrome.setSystemUIOverlayStyle(uiOverlayStyle);
SystemChrome.setPreferredOrientations(ALLOWED_ORIENTATIONS)
.then((_) => runApp(MyApp()));
}
Here is the definition of ALLOWED_ORIENTATIONS:
const List<DeviceOrientation> ALLOWED_ORIENTATIONS = [
DeviceOrientation.portraitUp
];
I just separated all the settings and such to another file to make modifying them later on easier.
When I run this code, I get the following error.
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception:
ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
If you're running an application and need to access the binary messenger before `runApp()`
has been called (for example, during plugin initialization), then you need to explicitly
call the `WidgetsFlutterBinding.ensureInitialized()` first.
It looks like there is some race condition that's failing. I am just not sure what is causing it. Removing the SystemChrome.setPreferredOrientations() line makes the app compile as expected. So, I am thinking the error has something to do with that line.
Any advice?
Like the error says
If you're running an application and need to access the binary
messenger before runApp() has been called (for example, during
plugin initialization), then you need to explicitly call the
WidgetsFlutterBinding.ensureInitialized() first.
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setSystemUIOverlayStyle(uiOverlayStyle);
await SystemChrome.setPreferredOrientations(ALLOWED_ORIENTATIONS);
runApp(MyApp());
}