In flutter when I am trying to run project it is giving error - flutter

Pease help me!, I am new to flutter I am importing a project and when I try to run it is giving exception
/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:9: error: cannot find symbol
import android.support.v4.app.ActivityCompat;
^
symbol: class ActivityCompat
location: package android.support.v4.app
My project is already compatible with androidX, I have tried package get and upgrade package but nothing happens, I have got the similar problem

When you migrate a flutter app to AndroidX, all the plugins the app depends on should also support AndroidX else your app build will fail and this is what is happening here.
Even though you have migrated your project to AndroidX, the simple-permissions plugin has not been migrated to AndroidX yet and this is what is causing the issue.
Below are the options you have in this case -
1. User the permission_handler plugin instead of simple-permissions.
The permission_handler plugin is a much more frequently updated plugin which has already been migrated to AndroidX. Here is the link to the plugin.
2. Migrate simple-permissions to AndroidX yourself
If you strictly want to use simple-permissions, you can clone the git repo and manually migrate the plugin to AndroidX and use the plugin via git url inside your pubspec.yaml. Details for migrating plugins to AndroidX can be found here.
You can use the plugin from git url in the following way inside you pubspec.yaml
dependencies:
plugin1:
git:
url: git://github.com/flutter/plugin1.git
//Your repo url goes in place of this url
3. Avoid using AndroidX altogether in you app.
You can force your app to use the older support libraries if you do not wish to perform the above two steps, but by doing this you will need to downgrade all your plugins to versions which do not use AndroidX, which is not the ideal solution.
More about this here.
Hope this helps!

Related

The plugins `advance_pdf_viewer, flutter_webview_plugin` use a deprecated version of the Android embedding

The plugins advance_pdf_viewer, flutter_webview_plugin use a deprecated version of the Android embedding.
To avoid unexpected runtime failures or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of
Flutter will remove these deprecated APIs."
I follow some documentation but is still not working.
i upgrade and downgrade my version but still not working.
should I share my mainActivity.kt and manifest file?
if there is no newer version of advance_pdf_viewer, flutter_webview_plugin available with the new android V2 embedding, your can't do anything inside of your app. Keep watching for plugin updates of these 2 plugins... or go to it's github project and open an issue to fix it. Sometime the master branch has already fix it. In this case you could try to link direct to the master branch and not to a version in pub.dev
for advance_pdf_viewer i use $flutter pub add advance_pdf_viewer
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
dependencies:
advance_pdf_viewer: ^2.0.1
Alternatively, your editor might support or flutter pub get. Check the docs for your editor to learn more.
Import it
Now in your Dart code, you can use:
import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
and for webview I try dependencies:
flutter_webview_plugin:
git: https://github.com/nuc134r/flutter_webview_plugin.git
and it all works for me than you.

Flutter | Error: Couldn't resolve the package

I created a package that is a collection of my own helper classes for faster developing...
The package also included firebase_analytics: which requires a native implementation for each platform i want it to run. Even if i dont wanted to use firebase at all, but still wanted to use my package i was forced to create firebase-config files for the app, because the app crashes if the firebase_analytics package does not find a valid file for the specific platform. To avoid those things i splitted my package in two packages.
The Core-Package: All helper classes that run native dart code
Optional extension: Only the classes that need the firebase implementation
So if i want to use the package without firebase i just have to depend on the core.
If i want to use the firebase variant i could simply depend the firebase package, because the extension package itself depends on the core-package in its own pubspec.yaml file.
PROBLEM: Since i restructured my package like i described, all my apps that depend on it are not building anymore. The console says that all packages that i depend on in my two packages can not be found. This error occures both ways: With firebase & without.
ERROR: (Scroll down for the complete console output)
MY ATTEMPTS:
"flutter clean" & "flutter pub get" in every package and app folder
"flutter pub cache repair"
CORE-PACKAGE Pubspec.yaml:
FIREBASE-Extension Pubspec.yaml:
Plain Console Output:
pastebin.com/m14cbqDV
Thanks for any help!!
I am facing the same issue while i was making a build in Xcode 13.So I had upgraded my flutter version 2.8.0 to 2.10.2 and also removed the version of all firebase dependencies, then the issue was finally solved.
I have faced similar issues and resolved them by removing package versions. Issues like this often arise due to mismatched versions of packages (eg firebase_core, firebase analytics). Please try to remove versions of the firebase packages or the whole packages. (like firebase_analytics :).
Sorry, my bad! As you can see i moved my dependencys to the dev section of my pubspec.yaml. They should be placed in the dependency section.

How do you integrate a flutter plugin into an existing flutter project?

I want to install a simple audio recorder which will record a user’s voice. I know I can find plugins on PubDev, however I have difficulty in integrating them into my Flutter project. I have installed ‘audio_recorder 1.0.2. in a new dart file as part of ‘lib’. I don’t know how to integrate this file into the flutter project. I have tried to a button in another dart file which when pressed would take the user to that file, without succes. ‘This class is not a widget’ is the message I get. The ‘GitHub’ version has the errors ‘undefined class’, ‘LocalFileSystem isn’t defined for the type ‘AudioRecorder’. The example version (why this difference?) has quite a few errors after installation. Dependencies and imports are ok. When I install audio_recorder 1.0.2 inside the project via ‘Dart packages’ I get a lot of errors. I have successfully installed an audio recorder in another android app. I would like some help in how to integrate plugins in a flutter project.
The plugins have instructions on how to install it. Got to your pubspec.yaml-file and put it under dependencies.
Make sure that you add your dependency to pubspec.yaml like this:
dependencies:
audio_recorder: ^1.0.2
After that make sure to type "flutter pub get" in console.
Go on a specified file in which you want to use Your dependency and import it like this:
import 'package:audio_recorder/audio_recorder.dart';

Flutter web cannot use packages from mobile project

A few months ago I made an android application using flutter. The application requires various dependencies such as intl, cached network image, stopper, carousel_slider, etc.
Then right now I want to convert the project to flutter_web. Here are the steps that I did:
clone github web flutter
I run the command "flutter packages pub global activate webdev"
Then I edited pubspec.yaml and I adjusted it to pubspec.yaml in the previous project (android project)
Here is the contents of pubspec.yaml on the web flutter project:
name: flutter_web.examples.hello_world
environment:
  # You must be using Flutter> = 1.5.0 or Dart> = 2.3.0
  sdk: '> = 2.3.0-dev.0.1 <3.0.0'
dependencies:
  flutter_web: any
  flutter_web_ui: any
  stopper: ^ 1.0.1
dev_dependencies:
  build_runner: ^ 1.4.0
  build_web_compilers: ^ 2.0.0
dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web_ui
  provider:
    git:
      url: https://github.com/kevmoo/provider
      ref: flutter_web
When I run 'pub dev', an error occurs while resolving the package stopper. Then I tried to open github from the package stopper (https://github.com/aryzhov/flutter-stopper), after that I checked the files in the lib folder. There I found a file called stopper.dart. It turns out that in the file, still using
 import 'package: flutter / material.dart';
So that makes my pubspec error. Because the code should be replaced with
import 'package: flutter_web / material.dart';
Therefore, I tried to outsmart the problem by removing the dependency stopper on pubspec.yaml, then I created a stopper.dart file manually, then I saved it in the lib/mypackages folder. After that, I import stopper.dart from the lib/mypackages folder (it's no longer through the package).
The package stopper is just one of the packages that I use on my Android project. Actually there are many other packages that have the same problem as the package stopper. The point is I have to create the package files manually, then I change "package: flutter / ..." to "package: flutter_web /" manually, then I can import them.
What I want to ask, is there a more elegant and simple way?
Hi the instruction you are following is from an old repository here. As you can see this is discontinued. You can find the informaiton in the REadme.
Instead you should follow the instructions in this page. Read it once carefully and I would suggest to keep a backup of your main project and work on a copy.
First you will have to enable the flutter-web using flutter config --enable-web.
Then you will have to run flutter create .

Error after add plugin simple_permissions on pubspec.yaml

I tried using the simple_permissions plugin and then I got an error to migrate to androidX even though I had migrated to androidX and after I deleted android.Jetifier at gradle.property I didn't get any more errors and the plugin was successfully used. Why did it happen? Will my project get a problem in the future? Thanks!
Make sure that all your packages in the pubspec.yaml are of the latest version. Then open the android project of your flutter app with android studio, select Refactor->Migrate to Androidx. Wait until android studio finishes migrating your project, rebuild your project. Hope it helps!