I am launching a flutter app (App 1) from another flutter app (App 2) on Android and it works perfectly. However, I keep getting the same error on IOS. It does not recognize the package name.
I have tried with multiple apps but is the same result, it currently just recognizes the calendar package.
pubspec.yaml file flutter_appavailability
main.dart App 2
import 'package:flutter_appavailability/flutter_appavailability.dart';
//Future void method
if (Platform.isIOS) {
_installedApps = [
{"app_name": "example", "package_name": "com.flutter.example"},
];
print(await AppAvailability.checkAvailability("com.flutter.example")); //ERROR
//Widget build
return Container {
child : Row(
...
GestureDetector(
...
onTap: () {
Scaffold.of(context).hideCurrentSnackBar();
AppAvailability.launchApp(installedApps[0].["package_name"])
.then((_) {
print("App ${installedApps[0]["app_name"]} launched!");
}).catchError((err) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
"App ${installedApps[0]["app_name"]} not found!")));
print(err);
});
...
),
}
info.plist App 1
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
project.pbxproj App 1
PRODUCT_BUNDLE_IDENTIFIER = com.flutter.example;
Output App 2
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(, App not found com.flutter.example, null)
#0 AppAvailability.checkAvailability (package:flutter_appavailability/flutter_appavailability.dart:40:9)
Related
Here is my login page, actually it should login, but I got error
I included sign in capabilities in XCODE
Xcode configurations all set
**
Error Message I got : Unhandled Exception: SignInWithAppleAuthorizationError(AuthorizationErrorCode.canceled, The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1001.))**
child: InkWell(
onTap: () async {
final credential =
await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.fullName,
AppleIDAuthorizationScopes.email,
],
);
print(credential);
context.read<SignInBloc>().add(
SignInEvent.signInWithApple(
appleToken: credential.authorizationCode,
),
);
},
Above is my function to sign in with Apple Id
App Identifier create to "Sign in with Apple" checkbox selection
like that
Today, I make application to play music on Android.
I have failed when using MediaPlayer to play an audio file; it can't play any file audio.
ON debug console:
I/flutter ( 5455): taped
E/MediaPlayerNative( 5455): error (1, -2147483648)
E/MediaPlayer( 5455): Error (1,-2147483648)
E/MediaPlayerNative( 5455): pause called in state 0, mPlayer(0xc83ffa40)
E/MediaPlayerNative( 5455): error (-38, 0)
E/MediaPlayerNative( 5455): Attempt to perform seekTo in wrong state: mPlayer=0xc83ffa40, mCurrentState=0
E/MediaPlayerNative( 5455): error (-38, 0)
2
E/MediaPlayer( 5455): Error (-38,0)
This is my code:
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
FlatButton.icon(
label: Text('ss'),
icon: Icon(Icons.ac_unit_outlined),
onPressed: () {
print('taped');
final player = AudioCache();
player.play('yagami.wav');
},
),
],
),
);
}
On pubspec.yaml:
dependencies:
audioplayers: 0.17.0
I've tried an older version of packages, but it didn't work out.
How to solve this problem?
or any other packages to play audio on assets?
Something that might help is creating your player just once at the beginning, and not everytime you press the button as that defeats the purpose of AudioCache.
So remove final player = AudioCache(); from the OnPressed function.
I'm trying to implement Mopub into my Flutter project but I have some issues related to mopub_flutter package.
MopubAdManager class contains the IDs of Mopub stuff.
This is my initState:
void initState() {
try {
MoPub.init(MopubAdManager().publisherId, testMode: true).then((_) => {
loadRewardedAd(),
});
} catch (e) {
print('exception: ${e.toString()}');
}
super.initState();
This is the loadRewaredAd function
void loadRewardedAd() {
videoAd = MoPubRewardedVideoAd(MopubAdManager().rewardedAd, (result, args) {
setState(() {
var rewardedResult = '${result.toString()}____$args';
});
print('$result');
if (result == RewardedVideoAdResult.GRANT_REWARD) {
print('Grant reward: $args');
}
}, reloadOnClosed: true);
This is how I call the function inside a button with onPressed
RaisedButton(
child: Text('Show Video'),
onPressed: () async {
videoAd.load();
var result = await videoAd.isReady();
print('Is Ready $result');
if (result) {
videoAd.show();
}
},
),
Before touching the button, Mopub prints that line in console:
I/MoPub (30148): [com.mopub.network.TrackingRequest$1][onResponse] SDK Log - Successfully hit tracking endpoint: https://ads.mopub.com/m/open
After touching the Show Video button that appears in console:
V/AudioManager(30148): querySoundEffectsEnabled...
I/MoPub (30148): [com.mopub.mobileads.MoPubRewardedVideoManager][fetchAd] SDK Log - Loading rewarded ad request for ad unit 40825097a53247c5a91f9775d3f54298 with URL https://ads.mopub.com/m/ad?v=6&id=40825097a53247c5a91f9775d3f54298&nv=5.15.0&dn=HUAWEI%2CPOT-LX1%2CPOT-LX1&bundle=com.example.anket&z=%2B0300&o=p&cw=1080&ch=2259&w=1080&h=2340&sc=3.0&ct=2&av=1.0.0&abt=%7B%22tapjoy%22%3A%7B%22token%22%3A%221%22%7D%7D&ifa=mp_tmpl_advertising_id&dnt=mp_tmpl_do_not_track&tas=mp_tmpl_tas&mid=mp_tmpl_mopub_id&gdpr_applies=0&force_gdpr_applies=0¤t_consent_status=unknown&vv=4&vver=1.3.4-Mopub&mr=1
I/MoPub (30148): [com.mopub.network.AdLoader][fetchAd] Ad requesting from AdServer: https://ads.mopub.com/m/ad
I/MoPub (30148): {"vv":"4","nv":"5.15.0","mid":"e458ffd9-db59-4753-9878-c923a99ef3fc","dn":"HUAWEI,POT-LX1,POT-LX1","sc":"3.0","current_consent_status":"unknown","vver":"1.3.4-Mopub","id":"40825097a53247c5a91f9775d3f54298","bundle":"com.example.anket","gdpr_applies":"0","ch":"2259","ifa":"fe6b229f-fa21-4367-ac77-f8437ef7ebb6","mr":"1","tas":"authorized","h":"2340","force_gdpr_applies":"0","dnt":"0","o":"p","ct":"2","abt":"{\"tapjoy\":{\"token\":\"1\"}}","cw":"1080","av":"1.0.0","v":"6","w":"1080","z":"+0300"}
I/flutter (30148): Is Ready false
I/MoPub (30148): [com.mopub.network.MultiAdResponse][parseSingleAdResponse] Ad server responded with:
I/MoPub (30148): {"content":"","metadata":{"x-adtype":"clear","x-backfill":"clear","x-refreshtime":60}}
I/MoPub (30148): [com.mopub.network.AdLoader$1][onErrorResponse] Ad server responded with:
I/MoPub (30148): No ads found for ad unit.
I/flutter (30148): Flutter mopub rewarded method error
I/flutter (30148): RewardedVideoAdResult.ERROR
Other Ad types such as banner, interstitial shows the same error.
I have created the ad units and copied the Ids to the MopubAdManager class but yet no ads appear in the app. I have tested the test Ids they work perfectly.
Did I skip something?
I have implemented Google Authentication with FlutterFire. I use the official package to sing in users.
However, if I navigate to a page where the user profile picture is seen and try to render the GoogleUserCircleAvatarar, although the page seems to be working just fine, I get an error in the console:
════════ Exception caught by image resource service ════════════════════════════════════════════════
Exception: Invalid image data
════════════════════════════════════════════════════════════════════════════════════════════════════
On the screen, it takes a few milliseconds, to load up the picture. Before it's loaded, I can see the placeholder image (First letter of the users initials on a filled background) next to the user's name and email address (so the currentUser is loaded) which transitions to the user profile picture. As I am using the recommended Widget, I am confused how should I prevent the error from happening.
Code:
if (widget.userService.currentUser != null) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ListTile(
leading: GoogleUserCircleAvatar(
identity: widget.userService.currentUser,
),
title: Text(widget.userService.currentUser.displayName ?? ''),
subtitle: Text(widget.userService.currentUser.email ?? ''),
),
const Text("Signed in successfully."),
RaisedButton(
child: const Text('SIGN OUT'),
onPressed: _handleSignOut,
),
],
);
} else {
...
currentUser object is created with the official API:
currentUser = await GoogleSignIn().signIn();
and my pubspec.yml:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.14.0+1
provider: ^4.3.2+2
google_sign_in: "^4.5.1"
firebase_core: "^0.5.0+1"
firebase_auth: "^0.18.1+2"
This issue should've resolved on the latest version of the google_sign_in plugin. More details of the fix for the issue is discussed on this pull request.
I am building a Flutter app, and I'd like to open a URL into a web browser or browser window (in response to a button tap). How can I do this?
TL;DR
This is now implemented as Plugin
const url = "https://flutter.io";
if (await canLaunchUrl(url))
await launchUrl(url);
else
// can't launch url, there is some error
throw "Could not launch $url";
Full example:
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(new Scaffold(
body: new Center(
child: new RaisedButton(
onPressed: _launchURL,
child: new Text('Show Flutter homepage'),
),
),
));
}
_launchURL() async {
const url = 'https://flutter.io';
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
throw 'Could not launch $url';
}
}
In pubspec.yaml
dependencies:
url_launcher: ^6.1.7
Check out the latest url_launcher package.
Special Characters:
If the url value contains spaces or other values that are now allowed in URLs, use
Uri.encodeFull(urlString) or Uri.encodeComponent(urlString) and pass the resulting value instead.
If you target sdk 30 or above canLaunch will return false by default due to package visibility changes: https://developer.android.com/training/basics/intents/package-visibility
in the androidManifest.xml you'll need to add the following directly under <manifest>:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
Then the following should word - for flutter 3 upwards:
const uri = Uri.parse("https://flutter.io");
if (await canLaunchUrl(uri)){
await launchUrl(uri);
} else {
// can't launch url
}
or for older versions of flutter use this instead:
const url = "https://flutter.io";
if (await canLaunch(url)){
await launch(url);
} else {
// can't launch url
}
launchUrl has a mode parameter which can be used to control where the url gets launched.
So, passing in launchUrl(uri, mode: LaunchMode.platformDefault) leaves the decision of how to launch the URL to the platform
implementation. But you can also specify
LaunchMode.inAppWebView which will use an in-app web view
LaunchMode.externalApplication for it to be handled by an external application
Or LaunchMode.externalNonBrowserApplication to be handled by a non-browser application.
For Flutter:
As described above by Günter Zöchbauer
For Flutter Web:
import 'dart:html' as html;
Then use:
html.window.open(url, name);
Make sure that you run flutter clean if the import doesn't resolve.
For those who wants to implement LAUNCH BROWSER AND EXIT APP by using url_launcher. Remember to use (forceSafariVC: false) to open the url in default browser of the phone. Otherwise, the launched browser exit along with your APP.
await launch(URL, forceSafariVC: false);
The best way is to use url_launcher package .
Add url_launcher as a dependency in your pubspec.yaml file.
dependencies:
url_launcher:
An example of how to use it :
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Flutter is beautiful'),),
body: Center(
child: RaisedButton(
onPressed: _launchURL,
child: Text('Show Flutter homepage'),
),
),
)),
);
}
_launchURL() async {
const url = 'https://flutter.dev';
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url));
} else {
throw 'Could not launch $url';
}
}
Output :
The launch method takes a string argument containing a URL .
By default, Android opens up a browser when handling URLs. You can
pass forceWebView: true parameter to tell the plugin to open a WebView
instead. If you do this for a URL of a page containing JavaScript,
make sure to pass in enableJavaScript: true, or else the launch method
will not work properly. On iOS, the default behavior is to open all
web URLs within the app. Everything else is redirected to the app
handler.
This is now implemented as Plugin
const url = "https://flutter.io";
final Uri _url = Uri.parse(url);
await launchUrl(_url,mode: LaunchMode.externalApplication);
pubspec.yaml
Add dependencies
dependencies: url_launcher: ^6.0.12
Output
If you want to use url_launcher than please use it in this form
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
url_launcher: ^5.0.2
flutter:
sdk: flutter
This answer is also for absolute beginners: They are thinking behind the flutter sdk.
No that was a failure. The packages were extras and not in the flutter Sdk. These were secondary packages (single small framework helpers).
The PLUGIN plugin works great, as you explain in your examples.
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
final Uri _url = Uri.parse('https://flutter.dev');
void main() => runApp(
const MaterialApp(
home: Material(
child: Center(
child: ElevatedButton(
onPressed: launchUrlStart(url: "https://flutter.dev"),
child: Text('Show Flutter homepage'),
),
),
),
),
);
Future<void> launchUrlStart({required String url}) async {
if (!await launchUrl(Uri.parse(url))) {
throw 'Could not launch $url';
}
}
But when trying to open PDF https://www.orimi.com/pdf-test.pdf it remained blank, the problem was that the browser handled it in its own way. Therefore the solution was to tell it to open with an external application and it worked as expected.
Future<void> launchUrlStart({required String url}) async {
if (!await launchUrl(Uri.parse(url),mode: LaunchMode.externalApplication)) {
throw 'Could not launch $url';
}
}
In pubspec.yaml
#https://pub.dev/packages/url_launcher
url_launcher: ^6.1.5
using the url_launcher package to do the following:
dependencies:
url_launcher: ^latest_version
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url));
}
Note: Ensure you are trying to open a URI, not a String.