Android Studio Reload not performed Flutter - flutter

I have an issue when I try to save any modifications on a new project, the hot reload doesn t work on save, because he has an issue that I can t find
I need to mention that I do not modified anything in the project, just started 2 hours ago and searched for the solution
I just tried to modify the title and nothing more first

In android Studio on the top left corner choose File -> Invalidate Caches...
Then you will see a modal
check both option and press the "Invalidate and Restart" button.
When the Android studio starts again, Re-run your application and check if the hot-reload works properly.
That worked for me.

There is a banner on top that says you haven't run pub get. You can press the button on that banner to run the command (Get dependencies).
This is likely because you changed your pubspec.yaml file.
Another thing you can try is to stop and restart, this is sometimes necessary. If this also doesn't work, try to clean using the command flutter clean and/or restart Android Studio

Related

main.dart file cant start "gradle error, exit code 1"

When I try to start my main.dart I get an error called
"Exception: Gradle task assembleDebug failed with exit code 1".
I'm running the default code when you create a new project with flutter create "name". When I run flutter doctor I get no errors, so I don't know what could be the problem. Some people said not enough space on disk. But I have about 50gbs left. I'm running on the android emulator with the pixel 4. Yesterday everything worked fine and today I wanted to create a new project, and now it doesn't work anymore. Even though I didn't change anything in the emulator settings or the VS Code settings/file.
Any help is appreciated
I believe this is the problem where the default gradle is outdated and sucj you need to update it, if you are using android studio, when opening a gradle file in teh top right corner it will say open for editing in android studio , click on it and it will open a new window, in the terminal run gradlew or gradlew upgrade.
also the flutter team said they were working on it, so try to update flutter to the latest version using the command flutter upgrade

flutter error Could not find an option named "platforms"

I'm new to learning flutter when I try to crate a new project on android studio gives me a arror message in the event section enter image description here
The MESSAGE: [Could not find an option named "platforms". Run 'flutter -h' (or 'flutter -h') for available flutter commands and options.]
And another problem is flutter doctor does not see the android studio enter image description here
1(By the way, I want to use this version of flutter, please do not give a suggestion like update.)
2(this problem did not exist before, it happened after turning my computer off and on)
And sorry for my english mistakes
Thank you.
flutter version flutter_windows_v1.12.13+hotfix.9-stable
andorid studio version: 4.1.3
Is this the answer to your question about andorid studio?
and you need to install JDK
You are using the wrong flutter SDK. Too low information in your question. Make sure that you have the right path to flutter SDK in your IDE. Check that the flutter SDK directory has the appropriate structure, all needed files and cetera. Channel and version of flutter also may have an influence on this problem.
Got this today out of nowhere. Things were going well, but suddenly when I tried to relaunch the app from fresh, for the error Could not find an option named "target"
UPDATE:
This appears to happen when I switch branches and merge while app is running/flutter is attached. If you're using VS Code,
open your launch.json
change something, I decided to change type: "dart" to type: "notdart"
save
try to debug which fails
then revert that change.
This should fix the issue.
Previous Answer/If you're not using VS Code
What worked for me was to
flutter clean
close the editor (VS Code for me)
close the emulator
give a minute for things to close down
open task manager and kill any left over processes of dart.exe flutter.exe and java.exe and adb.exe (was doing Android)
start VS Code/Android Studio and try to debug again. (when prompted I chose to cold boot the emulator as well)
This takes a while as the emulator has to cold boot and since flutter clean was run, the compilation hadto start from scratch as well.

Can not change or remove logs from project

I'm facing a weird issue. I inserted some logs just like below:
log('whatever messager you want');
Now, no matter if I comment them or change the message inside them, nothing changes. Thay remain there the way I set it the first time. It happens in both VSCode and Android Studio.
I already tried:
deleting and installing the app again.
reload vscode window
close and reopen vscode
restart windows
Nothing worked for me.
Have you tried to run
flutter clean
in your project directory?
In my case, Ctrl + Shift + B was displaying No build task to run found and ctrl + F5 wasn't updating my code changes when using VSCode.
The solution I found was to migrate to Android Studio. I relaunched the emulator from Android Studio and the Run button updates the app correctly.

VS Code and Flutter/Dart, Widget Autocomplete not working

I'm working with some tutorials to learn Flutter and the one that I'm taking now uses VSCode. I actually prefer it to Android Studio because it doesn't overheat my Macbook. The only frustration I've had with it so far is that there are quite a few times where autocomplete just stops working. For instance, if I wrap a Column in a widget and then start typing Container, Android Studio will pop up an autocomplete showing Container VS Code used to do this for me, but has stopped for some reason. I can still get the autocomplete list if I press Ctrl+Spacebar.
I'm using the following:
VS Code - 1.36.1
Dart Extension - 3.2.0
Flutter Extension - 3.2.0
Material Icon Theme - 3.8.0
This is the latest version for all of these.
Is there some setting or something that I need to change? I've spent the last two hours trying to work out what's going on. In searching, I did see some references to earlier versions of VS Code and the extensions causing problems, but nothing about these versions.
Go to pubspec.yaml and hit save or run get packages. It worked for me, hope it helps
There are generally two reasons for VS Code to automatically open code completion - 1) when you press a key that the extension ahs told VS Code should invoke it and 2) when VS Code thinks it would be useful (for example when you start typing on a blank line). If you're typing in a line of existing code it won't always do this.
Pressing Ctrl+Space is the correct way to open completion in the cases where it doesn't appear automatically.
That said, if you can provide more information about a specific instance, I can take a look if it's something we could/should pop completion open for. It would be best raised at https://github.com/Dart-Code/Dart-Code/issues with a screenshot and details of exactly where your cursor is (and how you got there).
dont use too many flutter extension, I also face this problem , then I realize that 3 flutter extension are installed, use only one , it works for me, try it.
I did have a derivative of this problem when I was working with VS Code and flutter and this is what I did.
This is for windows though. This is what I did ;
Go to C:\Users<your username >\AppData\Roaming\Code and delete all the files and the directory called "Code". Usually the folder AppData is hidden so you'll have to unhide it. Then restart your computer and then reopen VS Code. This I think cleared some of the unwanted cache files which kind of made things right again.
Hope it helped.
Make sure
Preferences > Editor > Intentions > Quick assist powered by the Dart
Analysis Server
is enabled (Screenshot).
If so, most likely your Dart Analysis server is crashing. Navigate to your HOME folder:
cd ~
And then below should resolve your issue:
sudo chown -R $USER .dart .flutter
Clear your cache if the issue still exists:
File > Invalidate Caches > Clear file system cache and Local History > Invalidate and Restart.
Also, Power Save Mode should be disabled:
File > Power Save Mode
Doing a flutter clean and then flutter pub upgrade worked for me. Sometimes flutter clean using the command line does not work if you have android studio then in tools go to flutter and then do flutter clean.
just do flutter clean then flutter create. and then flutter pub upgrade, and also see if your flutter SDK is latest or not.
Check to make sure Android Studio is not on low power mode
Menu>File>Low Power Save Mode
I solved in in my Macbook Pro by
Going to System Preferences > Keyboard > Shortcuts > Input Sources
Disable: Select the previous input source (^ space)
Updating VS Code dart and flutter extensions
Restarting the computer.
And voila! Ctrl + space now shows options in VS Code.

VSCode hot reload for flutter

I've just started playing with Flutter in VSCode. I also installed the Dart Plugin.
Running the demo app I read in the terminal
Is this the only way to hot-reload the app? I mean I should always keep the terminal open and focus on it to type "r" in order to reload my views?
Isn't there a shortcut directly from VSCode?
There's an extension for that. Called Dart Code and another one named Flutter Code
They will detect that your project is a Dart/Flutter project. And allows you to debug it + hot reload using f5.
For 2022, this solution worked.
Steps
Open Settings.
Paste this text > dart.flutterHotReloadOnSave on the settings search box.
And change value from "Manual" to "Always"
If you like to hot reload your app with a keybinding better than Ctrl+Shift+F5, just change the Debug: Restart to Ctrl+S, so whenever you trigger the the Ctrl+S the app will first save your changes according to the workbench.action.files.save and afterwards restart the app (=hot reload, it is the green circle you see in the debugbar).
Keybindings for VS Code:
VSCode debug -> start debuging, make a change and try, That's what you want.
No idea why F5 does not hot reload for me :(
But, you can map the -
Flutter: Hot Reload
command to whatever key combo floats your boat via -
Preferences > Keyboard ShortCuts
as in this screenshot -
open the Debug sidebar from VSCode and use it
then when you save, it will hot reload and apply the changes you make
that is what working with me
use the green reload button to hot reload the app in VS Code
on Mac select
Run without Debugging or Shift+f5
you will see this at top select the electric icon for Hot Reload.
After doing some changes save it. It will auto reflect changes.
yes Here is the plugin Dart Code for VS CODE
https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code
here is official doc for VsCode flutter
https://flutter.io/get-started/editor/#vscode
In VS once installed Dart + Flutter extension, 2 options to hot reload 1) Use combo keys Command + Shift + F5. 2) Save the file by use combo keys Command + S
I have both extensions and VSCode is set to Hot Reload once a document is saved. The only time I can reload my app is by stopping and restarting my debugger
i dont know why but my vscode hot reloading not work if you have this problem you can use ctrl + f5 to refresh app.
hope to work for developers that hot reloading not work for them.
You need to run Flutter app from VS Code's built-in debugger not VS Code's terminal.
Select ▷ then "Run without Debugging" -> You can now use ⌘S on Mac to ⚡ Hot Reload ⚡
===== Aug 2022 UPDATE =====
v3.42 and above: You can enable hot reload on autosave in the latest version by setting Flutter Hot Reload On Save to allIfDirty in your VSCode settings.
===== Old Versions (Early 2022 and below) =====
v3.41 and below: You can enable hot reload on autosave in the latest version by setting Flutter Hot Reload On Save to always in your VSCode settings.
v3.19 only: They disabled hot reload on autosave completely.
v3.18 and below: The extension hot reloads automatically when auto saving.
if flutter and dart extensions already installed on vscode
Set from manual to All
If you run your flutter project from the terminal you will have to manually press r to do a hot reload.
Therefore use the Run and Debug option in the VS Code to test your project.
You may encounter problems with Hot Reload due to VS Code issues like this, which is relevant while writing this answer.
The most convincing way I see to do it without downgrading, updating to Insiders builds and/or loosing dev speed is to use the green restart/reload button in the VS Code run widget or Ctrl+Shift+F5 shortcut, but this option may be inacceptable for projects with trickier navigation and few different views.