Checking device volume level in Flutter for iOS and Android? - flutter

I have an application built with Dart/Flutter that has user interaction that depends on the device's volume being on/turned up. I'm not seeing any obvious tutorials or packages available to determine this. How would I best go about approaching this? Am I overlooking a package or solution?

Most of the current packages support Android only.
https://pub.dev/packages/volume - Android only (example)
https://pub.dev/packages/flutter_volume/ - iOS and Android (example)
import 'package:flutter_volume/flutter_volume.dart';
// Return relative volume as double between 0.0 and 1.0
await FlutterVolume.volume;

Related

How to detect Apple User Agents in a Flutter web app?

I'm making a cross-platform mobile app with Flutter targeting iOS, Android and Web. I want to show the Cupertino theme to users of Apple devices and the Material (3) theme to users of all other devices.
As for iOS and Android builds, I detect the OS using the Universal Platform library and present the corresponding theme, no problem with that. However, as for the Web builds, I would like to detect the OS using the User Agent string.
By "users of Apple devices" I mean users who open my app on either macOS, iOS or iPadOS (or any other OS by Apple I missed, if possible), regardless of their browser. I would also include users of other OSs who specifically changed their User Agent string to make it look like they're using an Apple device, as I think it's safe to assume that they would prefer (or at least expect) to see the Cupertino theme; and I would exclude those who did the opposite, for the same reasons.
What would be the best way to detect such "Apple device users" in my Flutter Web app via User Agent? Right now I'm inclined to just look for /Mac/ in the User Agent string, but I'm afraid of getting many false positives. Thank you!
Try this package from pub.dev: https://pub.dev/packages/web_browser_detect
This example is what you are looking for:
import 'package:web_browser_detect/web_browser_detect.dart';
void main() {
final browser = Browser.detectFrom(userAgent: userAgent, vendor: vendor, appVersion: appVersion);
print('${browser.browser} ${browser.version}');
}

Flutter IOS & ANDROID Widgets Implementation

I wanted to ask about the implementation of IOS & Android Widgets for Flutter.
Current Scenario :
Basically, i have developed the app on android platform and now i want to convert it to IOS platform. Since this is my first app, i really need some experienced voice on some issues i am facing.
Questions :
1 - Is there any simple way to detect that the widgets currently used are of Android/IOS Platform ?
How can we know for sure that a specific widget is of Android platform and is not going to work on IOS platform and vice versa.
2 - If somehow we know for sure that the current widget we are using is of Android platform, then how can we find its equivalent widget to implement for IOS platform.
3 - Are these widgets specifically required when we are going to upload/publish to these platforms respective stores. For example in a scenario where i hadn't converted all of my android app widgets to ios widgets and when i try to publish the app for IOS store, does the IOS Store rejects that or not?
Any suggestions or help is greatly appreciated.
All standard widgets will work on iOS as is. Flutter paints the UI, rather than call the native APIs. You might use a plugin that does not support iOS, but I have not yet come across such a plugin on pub.dev.
If you want to write platform specific code, you can import dart:io and use the boolean Platform.isIOS or Platform.isAndroid.
Both the App Store and Play Store have specific requirements before your app is approved.
In case you really want to have Android specific widgets on Android devices and iOS specific widgets on iOS devices, then use the Flutter Platform Widgets package. This will exactly do that - drawing iOS buttons using the Cupertino library and Android buttons using the Android library (and most other widgets as well).
As #Mudassir mentioned in the other comment this is not a requirement. In case you go with the default widgets, you will have the same look on all devices (even web, Windows, etc.).

Increase in app size on adding mlkit in flutter

I recently added mlkit in my app for smile detection and then .abb size increased from 48mb to 185mb. How can i reduce this size...
Are you using a flutter plugin or a direct ML Kit dependency. You could try use app bundle to include only one arch in your app, or use dynamic feature to download the feature. If you could depends on Google Play Service, you could use the unbundled version which is only hundreds of KB in size: https://developers.google.com/ml-kit/vision/face-detection/android
Please refer to https://developers.google.com/ml-kit/tips/reduce-app-size to reduce your size of the android app. Also, 48MiB to 185MiB doesn't sounds right. The native android sdk is about ~20MiB even without any of the above optimization.

Compatibility of Flutter with Car Play and Android Auto

I developed an app on Flutter and I'm looking at a way to link it with Car Play and Android Auto. For my understanding Flutter is not compatible yet. Anyone know if it will be in the future (if yes, when we should expect this)? Is there any turnaround I can look into?
Flutter Apps are now compatible with Apple CarPlay!
flutter_carplay aims to make it safe to use apps made with Flutter in the car by integrating with CarPlay. CarPlay takes the things you want to do while driving and puts them on the car’s built-in display. Currently, it supports only iOS 14.0+.
Feel free to like, star, comment, share, and contribute to support more!
In pub.dev: https://pub.dev/packages/flutter_carplay
GitHub: https://github.com/oguzhnatly/flutter_carplay
Flutter has yet to have Car Play and Android Auto support as of this writing. As previously mentioned in the comments, it's best to keep track for its updates in this GitHub thread.
I got audio app working on carplay easily enough. Based on
https://pub.dev/packages/flutter_radio_player/example
And then using my apple developer account, setting entitlements to allow carplay, basically. I cam add details if requested. Also, I used a mac/xcode to check things worked etc.
Android auto I can't yet get working.. funny that!

It is possible to use flutter to create something to Watch OS or Android Wear?

I'm studying some possibilities to use in my project, I would like to know if I can to communicate a Watch OS project with the IOS flutter project.
At the moment, neither watchOS, nor Android Wear is supported by Flutter.
The lack of watchOS support is due to the lack of Bitcode support for iOS, as discussed in this GitHub issue. You can track the state of Adding Bitcode support for iOS - Flutter GitHub issue, but currently it seems to have a low priority for the Flutter development team.
For Android Wear, there seems to be no official reasons, but it is still not supported. You can track the progress of that in this GitHub issue.
There are open issues about watchOS and Android Wear
https://github.com/flutter/flutter/issues/2057
https://github.com/flutter/flutter/issues/15288