Url Launcher does not work with MissingPluginException Flutter - android

I am trying to launch a url in my flutter application. What i'm trying to do is very simple and it works in all other projects except for this one! The browser should be launched on an inkwell onTap event. I tried the exact same code in other projects and worked. I also tried to create a new flutter project and the code worked.
The app does not crash and i don't get any error but on Debug i get a missing plugin exception.
I tried flutter clean and flutter run but didn't work! I tried invalidating cache and restart but also didn't work! I tried removing and re installing the plugin but also didn't work!
Here's the code:
_launchMapsUrl() async {
final url = 'https://www.google.com';
if (await canLaunch(url)) {
await launch(url);
} else {
print('Could not launch $url');
}
}
the onTap:
onTap: () {
_launchMapsUrl();
},
The Compiled and Target SDK versions are 29 and the version of the launcher in my pubspec.yaml is url_launcher: ^5.7.10
For the record the other projects that the code worked in are of the same versions
I think it has something to do with caching issue i'm not really sure, i'm very new to flutter.
Can you please recommend a solution.

Related

Infinite splash screen on android

In my project, I was using flutter 3.0.3. Once I updated to 3.0.4 and updated dependencies, suddenly when I launched the app on android, the splash screen is showing continuously(never going to the main app). I tried by moving to my previous commit, downgrading flutter but to no avail.
This happened before but I luckily fixed it by upgrading kotlin jdk to 8(was 7 before).
I am using flutter_native_splash library. But it looks it doesn't have any impact on my project.
This question talks about only release mode. But, in my case it is happening both release and debug modes. I would really appreciate your help on this!
My main function:
void mainCommon() {
WidgetsFlutterBinding.ensureInitialized();
SentryFlutter.init(
(options) => options.dsn = Config.sentryDsn,
appRunner: () async {
await Firebase.initializeApp();
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
final GlobalKey<ScaffoldMessengerState> messengerKey = GlobalKey<ScaffoldMessengerState>();
await BlocOverrides.runZoned(
() async => App(
api: Api(Config.grpcChannel),
database: await Config.db,
appDirectory: await getApplicationDocumentsDirectory(),
notificationManager: await NotificationManager.init(Config.grpcChannel),
messengerKey: messengerKey,
),
blocObserver: AppBlocObserver(errorCallback: BlocErrorHandler(messengerKey).errorCallback),
);
},
);
}
This is not for all cases. But, upgrading firebase_core and firebase_messaging could solve for some cases. In my case, it solved the problem for the first. But, once I upgraded all my other packages, it occurred again.
Android studio sucks. When I used Visual Studio Code, the exception was thrown in main where I initialised firebase. But in android, it ignored exception so I wasted a lot of time finding where the problem was.
To see the error in Android studio, you need to get mainCommon in try/catch bloc:
try {
await Firebase.initializeApp();
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(App(
api: Api(Config.grpcChannel),
database: await Config.db,
appDirectory: await getApplicationDocumentsDirectory(),
notificationManager: await NotificationManager.init(Config.grpcChannel),
));
} catch (e) {
logger.e("Got exception in mainCommon: $e");
rethrow;
}

Why won't expo-updates provide checkForUpdateAsync?

When I transitioned to Expo's Managed Workflow (SDK 37 and now 38 as well), in-app update checking broke.
My code:
import * as Updates from 'expo-updates';
async checkForUpdate() {
const update = await Updates.checkForUpdateAsync();
if (update.isAvailable) {
this.updateApp();
}
}
async updateApp() {
await Updates.fetchUpdateAsync();
Updates.reloadAsync();
}
Logcat shows me that the checkForUpdateAsync() promise is being rejected with this message:
Error: The method or property Updates.checkForUpdateAsync is not available on android, are you sure you’ve linked all the native dependencies properly?
For the record I did install it via expo install expo-updates
Thanks.
I solved this by creating a new Expo project and looking for differences from my many-times-upgraded one. I found two:
I was using off-the-shelf React Native instead of the Expo build, so I changed the dependency in package.json to "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.1.tar.gz"
I also updated my expo version to ^38.0.8, as used by the new project.
Finally, I also deleted some build relics that I had generated during the way, but I think the fix came from one of the steps above.

Flutter sms_autofill plugin is conflicting with razorpay_flutter

I'm trying to use the following two Flutter plugin in my flutter project.
razorpay_flutter 1.1.2
sms_autofill 1.2.0
My Flutter code -
_askPhone() async {
const MethodChannel _channel = const MethodChannel('sms_autofill');
String phoneNo = await _channel.invokeMethod('requestPhoneHint');
print(phoneNo);
setState(() => _phone = phoneNo);
}
I'm trying to use only requestPhoneHint method through platform-channel to ask phone number from user. But alone sms_autofill plugin is working fine in this case but when I added razorpay_flutter plugin to my dependency it only prompts phone number but nothing happens on selecting.
Problem is that String phoneNo = await _channel.invokeMethod('requestPhoneHint'); line doesn't returns anything now. From my experience I think that it is probably might be due to duplicate request code in startIntentSenderForResult method in these both plugin so I tried changing that but still no result.
P.S. - I would like to make changes in sms_autofill plugin, please suggest anything.
I got it fixed by modifying razorpay_flutter 1.1.2 plugin to return false from inactivity result when requestCode is for sms_autofill plugin.

Xamarin.forms - Xam.Plugin.Media throwing error This functionality is not implemented in the portable version of this assembly

I am using Xam.Plugin.Media for implementing functions for taking and picking a photo on Android and iOS. I installed the latest stable version of Xam.Plugin.Media NuGet package (version 4.0.0.9) and followed the steps from Author on GitHub and when I press the button this message pops up and no matter what I do it wont go away. So if you any of you had this problem and resloved it please help me, and if you have any additional information about this error, please, help me.
I have tried the following to resolve this, but with no success:
Re-installing package several times
Deleting Obj and Bin folders
Clean + build
This is my view model:
public ICommand UploadImageCommand => new Command(async () =>
{
await Resiliency.TryAsync(IsBusy, async () =>
{
await UploadImageAsync();
});
});
private async Task UploadImageAsync()
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DialogService.ShowExceptionAlertAsync("No Camera");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
SaveToAlbum = true
});
if (file == null)
return;
_imagePath = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
return stream;
});
}
Additional information:
When debbuging it crashes on the first line of the method - "await CrossMedia.Current.Initialize();"
This is happening on Android and I am using physical device (Huawei P9 Lite 7.0 API 24), but the same happens on Emulator API 23 6.0
I am using Visual studio 2015 enterprise with update 3
Yes the package is installed on the core project and on the android and iOS project
Check out the response of the original Developer on the GitHub Repository
Xam.Plugin.Media throwing error This functionality is not implemented in the portable version of this assembly #559
You can also download the sample and see how it works

Error while trying to access files in the app

I'm building a react-native app that uses tensorflow to recognize images, I'm following the steps in this tutorial.
I did everything according to the explanations, including the part of "Fetching files". I created the assets folder and put the files in it (the path is correct).
But when I run this code:
const tfImageRecognition = new TfImageRecognition({
model: require('./assets/tensorflow_inception_graph.pb'),
labels: require('./assets/tensorflow_labels.txt'),
});
The app gives the following error:
I already tried to create a new project, I imported the react-native-tensorflow import { TfImageRecognition } from 'react-native-tensorflow';, I updated the cache, I deleted the folder node_modules and also I created the file "rn-cli.config.js" that is requested in the tutorial to give access to the files in the assets folder. Any idea how to fix this?
I'm using expo to run the app on mobile (android).
npm: 5.51
expo: 51.4.0
react-native: 0.54.0
react-native-cli: 2.0.1
This problem didn't occur with me. Try react-native start --reset-cache and then run the app again.
There is a better way to this.
import model from './assets/tensorflow_inception_graph.pb';
import labels from './assets/tensorflow_labels.txt';
const tfImageRecognition = new TfImageRecognition({
model,
labels
});
Restart your server.
I tried the same example as you mentioned I got accessed Image and Text.
I stored files inside assets in the same directory. Can you share code to produce an error that you faced?
async recognizeImage() {
try {
const tfImageRecognition = new TfImageRecognition({
model:require('./assets/tensorflow_inception_graph.pb'),
labels: require('./assets/tensorflow_labels.txt')
})
const results = await tfImageRecognition.recognize({
image: this.image
})
const resultText = `Name: ${results[0].name} - Confidence: ${results[0].confidence}`
this.setState({result: resultText})
await tfImageRecognition.close()
} catch(err) {
alert(err)
}
}
As you mentioned your using expo then I'm assuming that run npm eject already. As react-native-tensorflow this library require native changes
You must add extensions in your rn-cli.config.js, in order to require tensorflow_inception_graph.pb and tensorflow_labels.txt
module.exports = {
getAssetExts() {
return ['pb', 'txt']
}
}
Replace ./ with so ../ , so final code will be -
model: require('../assets/tensorflow_inception_graph.pb'),
labels: require('../assets/tensorflow_labels.txt')

Categories

Resources