Take user to device settings to active gps in flutter - flutter

I have a problem with gps management in a flutter application.
I've seen in this answer:
Is GPS activated - Flutter
how I can check if a gps is active in a flutter app.
If is not active (GeolocationStatus.denied) how can I take with flutter a user to device settings for turn on gps?
Thank you.

Install plugin :
https://pub.dartlang.org/packages/android_intent#-installing-tab-
Import in your dart :
import 'package:android_intent/android_intent.dart';
Add method :
void openLocationSetting() async {
final AndroidIntent intent = new AndroidIntent(
action: 'android.settings.LOCATION_SOURCE_SETTINGS',
);
await intent.launch();
}
Invoke it done...

Related

Badge counter on launcher icon in flutter

I am trying to implement badger count on app launcher icon in flutter for all android based devices. I've tried flutter_app_badger and flutter_dynamic_icon as well but both of them aren't compatible with android. I wan't a unamious solution it's awesome if it works both for android or ios as well.
I am trying to find solutions but there isn't enough data present. Onesignal push notification I am using for the app provides default badge count but it's not in all devices either.
Please help me with the situation.
setLauncherNumber()async{
// set batch number
try {
print('LauncherBadge inside try');
// FlutterAppBadger.updateBadgeCount(10);
await FlutterDynamicIcon.setApplicationIconBadgeNumber(93);
print('LauncherBadge Success');
} catch (e) {
print('LauncherBadge error $e');
}
}
flutter_app_badger and flutter_dynamic_icon arent compatible with all devices
Use this package flutter_app_badger: ^1.5.0
import 'package:flutter_app_badger/flutter_app_badger.dart';
FlutterAppBadger.updateBadgeCount(1);

How should I make some differences between Flutter mobile and web version of my app?

If I want to use one codebase for my application, but add some specific widgets/features for mobile app and some for web version of my app, how should I do that? Should I write all the code and just add an if statement before those specific widgets to see what platform the application is running on by the user and show/hide that widget/feature, or I must separate mobile and web widgets in different files?
For example I want to show a camera feature on mobile version and another feature on web version. How should I do that?
You can check de platform of the device, and then display or not your content.
You can do this by few ways, the easyes one is:
import 'dart:io' show Platform;
if (Platform.isAndroid) {
// Android-specific code
} else if (Platform.isIOS) {
// iOS-specific code
}
The options are:
Platform.isAndroid
Platform.isFuchsia
Platform.isIOS
Platform.isLinux
Platform.isMacOS
Platform.isWindows
Specific for web:
import 'package:flutter/foundation.dart' show kIsWeb;
if (kIsWeb) {
// web
} else {
// not web
}
Or you can also calculate the dimensions of the screen using MediaQuery.
To show or not the feature you can use the Widget Visibility
https://api.flutter.dev/flutter/widgets/Visibility-class.html
You can check your app is run on the web like that
import 'package:flutter/foundation.dart' show kIsWeb;
if (kIsWeb) {
// It's running on the web!
} else {
// NOT running on the web!
// You can also check for additional platforms here.
// Or you only develop for web and mobile this is mobile
}
Read Documentation from this Link for more understanding : https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html

How can i stop music apps from playing when clicking a button in my flutter application

I'm creating a flutter application to stop any music apps (like youtube music, gaana, spotify) from playing by clicking a button on my APP. How to implement that? Is there any built in packages in flutter to achieve this?
I have tried with a package named audio_service (https://pub.dev/packages/audio_service), but it didn't worked.
This can be achieved using the audio_session package:
final session = await AudioSession.instance;
await session.setActive(true);
On iOS, this equates to activating the AVAudioSession and on Android it equates to requesting audio focus. If you want to be a little more specific about exclusivity/ducking behaviour, you could configure the audio session to your liking (following the per-platform documentation for each option):
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
avAudioSessionCategoryOptions: AVAudioSessionCategoryOptions.allowBluetooth,
avAudioSessionMode: AVAudioSessionMode.spokenAudio,
avAudioSessionRouteSharingPolicy: AVAudioSessionRouteSharingPolicy.defaultPolicy,
avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
androidAudioAttributes: const AndroidAudioAttributes(
contentType: AndroidAudioContentType.speech,
flags: AndroidAudioFlags.none,
usage: AndroidAudioUsage.voiceCommunication,
),
androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
androidWillPauseWhenDucked: true,
));
await session.setActive(true);
Note that audio_session is used under the hood in the just_audio plugin to stop or duck other audio apps when playing audio.

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 can I disable some functionality only if web on Flutter app?

I see that up today flutter has a beta web support. But if I have some view or in general some functionality that support only mobile devices, how can disable it only when I build for the web? is it possible ?
import 'package:flutter/foundation.dart';
if (kIsWeb) {
// running on the web!
} else {
// NOT running on the web! You can check for additional platforms here.
}
Also if you want to check for inside widget and not show mobile widget
child: kIsWeb ? Container():<Mobile Widget>
https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html