Flutter: Garbage Collection - How to check? - flutter

In Flutter, how can I check if I am releasing (dispose) everything correctly?
I am building an application and I have the feeling that the simulator is getting slower after a series of hot reloads.
Many thanks for your answers.

Dart comes with a debugger called Observatory. It does a bit of everything you need. From CPU/Memory usage, to time spent on each functions. Even breakpoints and code coverage.
When running your flutter app, it's available by default on the localhost.
When running flutter run in the terminal, the port will be displayed.
On vscode with Dart code extension, you'll need to use the command Open Observatory timeline.

Related

Run example_radio.dart with JustAudioBackground

I'm experimenting with Ryan Heise's great audio packages in Flutter.
I import the Just Audio Background ("JAB") code from GitHub into Android Studio, and I run flutter pub get where necessary to get rid of any errors in the packages.
I want to replicate the simple radio player in the file example_radio.dart in the Just Audio package. But I need it to run in the background.
Following the setup instructions on the JAB pub.dev page, I make sure the dependencies are correct in pubspec.yaml and I edit the Android Manifest file.
I see some unresolved classes and packages in the Manifest (see screenshot); however, the app runs. But I am not sure about this. I'm new to Flutter and am not sure how important it is to have zero errors in the Android files, because I have seen other SO comments saying to just ignore them. This I must investigate.
When I run the app, everything works fine except the audio stops when it goes into the background.
I also ran the JAB example file, and this works fine, continues to play in the background. I have tried to edit this file so that it plays just the radio stream and shows the simple metadata. I've got it running, but the UI's a mess with my naive editing.
Any pointers, advice, much appreciated.
Thanks.

Flutter: MissingPluginException when calling plugin from isolate spawned by native code

I'm building a Flutter app that will have the capability to execute some actions when the device connects to another bluetooth device. This app should work on Android and iOS but for the sake of simplicity I'll focus on Android in this post. Also, this has to work whether the app is in the foreground, in the background or killed.
Here is the architecture of the app:
I have an Android native code that registers to bluetooth events through a BroadcastReceiver.
I followed this tutorial to set up the communication between the Android code and the Flutter code: https://medium.com/#chetan882777/initiating-calls-to-dart-from-the-native-side-in-the-background-with-flutter-plugin-7d46aed32c47.
When the Android BroadcastReceiver is triggered by a bluetooth event, the information is sent to the Flutter code (even if the app was in the background or killed). A Flutter isolate is created to handle the Flutter code.
Everything works perfectly well. The Flutter code is called and I can use print(data) to log the data that have been provided by the Android code.
Things are becoming more tricky when, from the isolate, I want to call any Flutter plugin (like sqflite, package_info_plus, ...). I get this error every time:
[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception:
MissingPluginException(No implementation found for method xxx on
channel yyy)
I understand that spawned isolate can't natively run Flutter plugins. There are some posts (Unable to understand Flutter Isolate workaround for "'Window_sendPlatformMessage' (4 arguments) cannot be found" error, https://github.com/flutter/flutter/issues/13937) that explain how to create isolates that can run Flutter plugins by using a workaround or a plugin like https://pub.dev/packages/flutter_isolate.
However, I can't create the isolate with this package because the isolate is created from the Android code.
Can one of you tell me how I can achieve this? Is there a way to use Flutter plugins from an isolate that has been created by native code?
Thank you very much in advance
Sounds like the way you create the Flutter isolate may not be compatible with your goal. There are some solutions to integrate Flutter with native Android/iOS projects, such as flutter_boost (disclaimer: I have not tried it and not sure good or not; you may find many other alternatives as well, this is just an example). You can use that to create the Flutter environments. Since the solutions above allow some Android code to open a new normal Flutter page and Flutter code in that page is able to do anything (of course include calling native - otherwise things like flutter_boost is really useless), this should work.

having trouble setting up flutter in vs code

I have trouble in setting flutter and running an app on a real device in vs code. I want to run my apps on physical device and I do not want to use emulators. Is it going to be possible?
Yes, this is very possible. In fact, many flutter developers use physical devices in order to test features like Maps,Camera, etc. I always recommend following a video tutorial to set up environments for development. But you should try the following:
First of all, I recommend the flutter docs https://flutter.dev/docs/development/tools/vs-code to set up vscode.
After this, all you need does not have anything to do with VSCode any longer. You should check https://flutter.dev/docs/get-started/install/windows to connect a physical device.
Im not sure if you have already setup flutter on your machine to start with. If you haven't use this link how to install flutter
the next part is easy just install dart and flutter extensions in vscode.
walla!

Testing React Native code without an Android Emulator

I'm a uni student who has to create a React Native mobile application for an assignment. Initially, we were using University computers for our coding and using Android Studio emulators to test our code once it was written to make sure it works on an android device.
Unfortunately due to the current epidemic, my University has closed all facilities including their 24 hour library which myself and coursemates were using to complete this assignment. This means that all of our assignment work must now be completed on personal computers. My personal laptop doesn't seem to work well with Android Studio, I am assuming it is due to the ageing hardware. I cannot get an emulator to run.
I would like to know if there is a way to use an online emulator or something of the sort to test the code I have written to make sure it actually works. I am aware of expo but since I am using the React Native CLI I don't think I am able to use Expo for an emulator. Is there a way that I can still use the Expo emulator even though this React project is not using Expo CLI?
Unfortunately I also cannot use a personal device as I do not own an Android phone.
Any advice would be greatly appreciated. I have made my course tutors aware of my circumstances and was informed that I can apply for exceptional factors to be taken into consideration when marking my work. However I would much rather complete the work to the best of my ability if possible without needing to apply for the above.
The only solution I know is the genymotion, it should be a bit easier to run on less powerful hardware but take no word from me because I've never used it. Otherwise if you know someone with a more powerful pc/laptop you can clone your project from git to that pc, connect to that pc with teamviewer or remote desktop (vpn needed) and run it from there.
There is another solution at last after making a build for you app you can try running the app on BrowserStack a cloud testing platform. But it's gonna be tough if you have a bug or something. Or you can use Genymotion it runs on a less powerful hardware

Slow content appearing in Windows

I'm testing Flutter for Windows and i noticed that, even with a basic 'HelloWorld' app, the content appears slowly, i have a 1 second blank screen inside the app (see gif below):
The app is packaged with default command (flutter build windows).
How can i improve performance at startup ? Is it possible to show the window when content is ready to display ? Or shall i use a splashscreen (I don't even know if this is possible with windows, and if so how) ?
Thanks to everybody!
How can i improve performance at startup ?
Flutter for Windows currently only supports debug builds, which among other things means that it's using JIT compilation, not AOT as a release build of a Flutter application would. Slower startup time is one of the downsides of JIT.
Is it possible to show the window when content is ready to display ?
There is currently no callback hook for when the first frame is drawn, so this would be difficult, if not impossible, to do accurately.
Or shall i use a splashscreen (I don't even know if this is possible with windows, and if so how) ?
There is no support for splashscreens in Flutter's Windows embedding.