How to get a list of sound notifications? - flutter

I'm building an app where the users can choose the notification sounds inside the app.
The app would display a List of all notification sound that are inside the smartphone.
The Question:
How can I get a list of all notification sounds from the users phone, so the user can choose the preferable sound?
Is there any package in pub.dev or any way to do this (Android & iOS)?

Currently, it is not extensively available. But there is a work around, and that is:
Have a button
On press of that, open up your Sound and Vibration Settings.
Let the user choose from there itself
For that you can use app_settings package.
This is simple representation of how you can open up your location settings on press of a button
Widget build(BuildContext context) {
return Row(
children: <Widget>[
RaisedButton(
onPressed: AppSettings.openLocationSettings(), // here is the magic
child: Text('Open Location Settings'),
),
],
);
}
Consider this as an option. If you don't find anything, you can come back to it, and make use of it :)

First thing there is no plugins available which are fit into your requirement.
For iOS & Android, It is mandatory to keep sound file inside your project to play custom sound when notification received.
You need to get a list of the available sound file inside your project and load it to the widget.
Thanks.

Related

How to launch system File Manager from Flutter app?

From my flutter I want to launch the default File Manager. I don't want to select file from it for my app. I just want to launch it (preferably showing the directory that I want it to show) so that the user can pick a file from that directory and do whatever they want with it.
Can anyone please tell me how to do it? I see a lot of code and examples for picking a file but that's not what I need. Just want to launch whatever is a default file manager.
Please do not suggest FilePicker. That is not what I am looking for. I do not want to "pick" a file. I know how to pick a file. I just want the default file manager app to be launched. I don't want the control to be returned back to the app irrespective of whether the user selects a file or not.
This was causing me grief too. Here's my solution.
Using 'external_app_launcher' you are able to launch apps based on their URL scheme, so we have...
import 'package:external_app_launcher/external_app_launcher.dart';
okButton = TextButton(
child: const Text("Open Files"),
onPressed: () async {
await LaunchApp.openApp(iosUrlScheme: 'shareddocuments://', openStore: false);
},
);
This will launch the app, I'm still working my solution as I want to open my App's folder so will update as I get more.
You can use the file_picker package.
Usage
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
File file = File(result.files.single.path);
} else {
// User canceled the picker
}
Edit: Now I understand what you want. Check https://pub.dev/packages/external_app_launcher

Flutter Web: Right click -> Browser Context Menu -> Open Link in New Tab

I have a basic website using GetX for navigation. I have inkwells with ontap functions which navigate to a new view. Right now, if you right click these buttons there is no "open link in new tab/window", "save link as" or "copy link address".
Is there any way to get this functionality for Flutter Web?
Edit:
Since Flutter version 2.10, you no longer need to switch to channel beta for this.
Maybe I'm answering this late, but this may help someone in the future.
At the moment of writing this it is possible to be done, it is bugged on the stable channel, but it works perfectly on channel beta.
Just switch to channel beta:
flutter channel beta
flutter upgrade
Then follow this instructions to add url_launcher dependency to your project and import this package wherever you want to use it:
import 'package:url_launcher/link.dart';
And finally wrap any widget with this:
Link(
uri: Uri.parse('www.google.com'),
builder: (context, function) {
return InkWell(
onTap: () => print('Do something'),
child: Text('Right clickable text')
);
});

How to Tap on native iOS popup to allow Notifications. (Flutter Integration Test)

Flutter Driver code has to tap on the native "Allow" button to continue and simulate the correct user behaviour.
See this screenshot. Native iOS popup before app starts - Allow Notifications
App has not yet completely started and is waiting for this tap.
How does one get the driver to tap on the native iOS popup?
Any suggestions and ideas are welcome.
Here is the code for one attempt to wait for the app before continuing with other tests; it just awaits indefinitely:
setUpAll(() async {
driver = await FlutterDriver.connect();
await driver.waitUntilFirstFrameRasterized();
});
Here is another attempt at finding the word "Allow" in the popup and tapping on it:
test('Allow app to send Notifications.', () async {
final allow = find.byTooltip("Allow");
await delay(750);
await driver.tap(allow);
});
It does not find the word.
The issue is probably that Flutter Driver is not aware of the iOS native popup.
Other tests are very simple once in the app, for example, to tap on fields, enter text, scroll pages, etc.
Any ideas on how to do this?
Unfortunately this feature is currently not possible. Flutter Driver can't interact with native elements (v1.20.4).
https://github.com/flutter/flutter/issues/34345
https://github.com/flutter/flutter/issues/12561

How to organise a Flutter project with multiple apps (Android, iOS and Web)?

I'm trying to find the best way to organise a project that I'm gonna start with Flutter. Here is what I need to develop:
1 Android & iOS app for customers-side
1 Android & iOS app for professionals-side
1 Web app for administration
Backend will be done with Firebase (Firebase Authentication, Firestore, ...)
Some code (models and logic) and features will be common on the three apps (and it would be nice if I could configure a production and a development environment).
How would you set up your project(s) in order to easily do that?
Does it seems like a good idea to have only 1 project with multiple flavors? I like the idea that I don't have to deal with multiple projects. Just to keep the development flow very simple. And There could be a condition in the main() function of the App that checks the flavor then open the right screen.
Would you prefer to have a common library that is used by multiple project? This seems like a good way to do it. But I'm not sure that this (small) project worth 3 to take the time to organise 3 distinct projects + a library.
Any other idea?
Thank you very much in advance
You should be able to reshare the majority of your code without different projects.
This is the beauty of widgets and of MediaQuery.
Create all your main components in widgets, your list of items can be ItemList();, the main menu can be MainDrawer();, etc.
For widgets that are meant for differing screen sizes, in your layout builder you can either return LargeScreenWidget() or SmallScreenWidget().
Use either a LayoutBuilder or OrientationBuilder, and write the code to respond to changes in screen size, width and orientation. This way it can share most of the same code.
When you return your layout builder, follow the general pseudo code:
isLargeScreen
? return Row(children[LeftWidget(), RightWidget()])
: return SingleChildScrollView(child: MobileWidget());
If somebody has a very small Chrome window on Desktop, it can switch to the mobile layout this way.
Just as a tidbit, I almost always start my code with the following so I can adapt the layout.
var size = MediaQuery.of(context).size;
var isLargeScreen = false;
if (MediaQuery.of(context).size.width > 900) {
isLargeScreen = true;
} else {
isLargeScreen = false;
}
This way when I am building a widget I can do like the following:
Container(
constraints: BoxConstraints(maxWidth: (isLargeScreen ? 700 : size.width * 0.9)),
),
You can also ask the user which operating system they are using with Platform.isIOS/isWindows/isAndroid.
EX:
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) {
return Platform.isIOS ? AndroidPage() : iOSPage();
},
)); // MaterialPageRoute
},
Or when using a FutureBuilder
return Platform.isIOS ? CupertinoLoading() : CircularProgressIndicator();
On top of this, you can use VoidCallbackMethod with the OrientationBuilder to change the way the app functions.
In the articles I share, if the screen is small, it opens a Navigation route, otherwise it passes the data to a widget on the right side. This is good for a messaging app for example.
Here are some articles to help you out.
Develop A Responsive Layout Of Mobile App With Flutter
Developing for Multiple Screen Sizes and Orientations in Flutter
Of course, ultimately it is up to your project, what you and/or your team desires, and how comfortable you are with file-size/extra if statements running all the time.
However I will add, that at least for the mobile apps, I usually only use one project. Web/desktop may be a different project.
Happy fluttering!

Create a button to open another app in Flutter

I would like to create a simple app in Flutter that contains for example 3 button , the event onPressed in the button should open another external app , is that possible in Flutter and how should I proceed?
You can use Column/Row to create your buttons. And after that you can simply use a RaisedButton like this:
ElevatedButton(
onPressed: () {
// use android_intent package to open other app
final intent = AndroidIntent(package: "com.android.facebook", action: "action_view");
intent.launch();
},
child: Text("Open Facebook")
)
It's easy to do it in Android using android_intent_plus and for iOS you can do it natively, this will help you.
In my case action: "action_view" caused app selection dialog getting opened. We can open specific component using below.
You can try android_intent library for launching external app. Documentation has some sample codes.
You may use sample code below.
var map={"AuthParams":authParam};
var intent=AndroidIntent(package:"in.app",arguments: map,componentName: "in.app.ui.splash.SplashActivity",/*action: "action_view"*/);
await intent.launch();