Facing a problem to set up the emulator in flutter - flutter

I have the following problem.....
Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
Try adding the name of the type of the variable or the keyword 'var'.
int _counter = 0;dsggfsgfh;
^^^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
I'm a beginner with Flutter. How can I solve this problem?

Your code has junk words or sentences, check your line ended with dsggfsgfh; which might be added unfortunately. Just remove it this will work.

It's possible that it's a compatibility issue between flutter framework and engine. You can try and:
Upgrade flutter to the latest version
Create a new project
Copy the code from the old project in steps
If you have plugins from the old project, add them one by one as you run the emulator
(It's possible that a certain version of a plugin has a compatibility issue with flutter)

Related

The method 'FocusTrapArea' isn't defined for the class '_PinputState?

I have tried repairing the cache using flutter pub cache repairand also cleaned the project cache using flutter clean.It still doesn't work.
/C:/Users/Phili/AppData/Local/Pub/Cache/hosted/pub.dev/pinput-2.2.20/lib/src/pinput_state.dart:339:14: Error: The method 'FocusTrapArea' isn't defined for the class '_PinputState'.
'_PinputState' is from 'package:pinput/src/pinput.dart' ('/C:/Users/Phili/AppData/Local/Pub/Cache/hosted/pub.dev/pinput-2.2.20/lib/src/pinput.dart').
Try correcting the name to the name of an existing method, or defining a method named 'FocusTrapArea'.
child: FocusTrapArea(
^^^^^^^^^^^^^
Failed to compile application.
anyone answer please
sorry this is coming late! I experienced mine when I updated my Flutter version to 3.7 so what I did was to update the Piput package version to the latest version and that solved mine for me. I hope it helps. I could not fully figure out what happen why it broke my app the first time but it was intuitive for me to upgrade the pinput package.

Flutter Redux Navigation library import error

I have been developing application and one of the libraries I have used was Flutter Redux Navigation. Everything was working fine, until recently, when I started getting following error
../../lib/src/navigation_middleware.dart:3:1: Error: 'NavigationDestination' is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_redux_navigation/src/navigation_destination.dart'.
import 'package:flutter_redux_navigation/src/navigation_destination.dart';
^^^^^^^^^^^^^^^^^^^^^
../../lib/src/navigation_middleware.dart:35:26: Error: 'NavigationDestination' is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_redux_navigation/src/navigation_destination.dart'.
this._setState(NavigationDestination(
^^^^^^^^^^^^^^^^^^^^^
../../lib/src/navigation_middleware.dart:55:26: Error: 'NavigationDestination' is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_redux_navigation/src/navigation_destination.dart'.
this._setState(NavigationDestination(
I even tried to copy example project from their git, and got exactly same error. This is something in library, or perhaps some settings of my IDE? Please let me know if anyone encountered this error.
The problem was that I have upgraded Flutter version from 2.5.1 to 2.8.0. The newest Flutter version contains upgraded Material library, which contains the method called NavigationDestination. Thus both, the library and Material design have the same name of the class, of course, resulting in error.

Undefined name 'Lottie' - Error in flutter

How can i solve bellow mentioned errors in a simple flutter program
Errors :
Target of URI doesn't exist: 'package:lottie/lottie.dart'.
Try creating the file referenced by the URI, or Try using a URI for a file that does exist.
Undefined name 'Lottie'.
Try correcting the name to one that is defined, or defining the name.
Check first your pubspec.yaml file if you have lottie under dependencies. If you do, press this button at top right corner if you are using Visual Studio Code
Ohterwise type flutter pub get at your cmd to get the dependencies you are missing.

How to Mix Sound Null Safety and Unsound Null Safety in Flutter

I am building a Flutter app and I need to use the flutter_redux package for my global state management.
Unfortunately when I added it and try to execute my app I am getting the below error:
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:
- package:redux
- package:flutter_redux
Please, how can I resolve this?
// #dart=2.9 - add this as is to the top of main.dart file
Alternatively, set the language version in the entrypoint — the file that contains main() function — to 2.9. In Flutter apps, this file is often named lib/main.dart. In command-line apps, this file is often named bin/.dart. You can also opt out files under test, because they are also entrypoints.
https://dart.dev/null-safety/unsound-null-safety
From dart.dev, I used it when I was having problems with packages without null-safety.

Why the app produced by flutter build web sometimes doesn't work?

I have 2 issues that only appear when executing flutter build web.
Sometimes flutter build web fails complaining (wrongly) about types that were not compatible (see below).
Sometimes the build process finishes but then the web app doesn't work: doesn't display anything and there are no messages in the console.
The error I mention is something like this:
% flutter build web
Target dart2js failed: Exception: lib/main.dart:24:31:
Error: A value of type 'ApiUsersRepository' can't be assigned to a variable of type 'UsersRepository'.
- 'ApiUsersRepository' is from 'package:my_app/api_users_repo.dart' ('lib/api_users_repo.dart').
- 'UsersRepository' is from 'lib/users_repo.dart'.
final UsersRepository usersRepository = ApiUsersRepository();
^
Error: Compilation failed.
The app is working in iOS and web when developing.
The solution
I changed all imports of my files like:
import 'package:my_app/users_repo.dart';
To:
import 'users_repo.dart';
More Details
Investigating the error about types, I found this issue, where the important part is this comment: after changing every import to relative format it resolves my problem.
So I did that, and it solved the 2 issues, the compilation error, and the runtime error.
for me I had to remove a package that was corrupted. c:\src\flutter.pub-cache\hosted\pub.dartlang.org\localstorage-4.0.0+1 Apparently, a file had become corrupted by me invertly. I removed the package and did a flutter pub get then recompiled and it worked.