Categories
discuss

android fragment livedata remove observer not working

I am using jetpack navigation for navigating. I observer the form submit with viewmodel livedata.

I am observing livedata in onActivityCreated of the fragment (SignUpFragment) like.

viewModel.signup.observe(viewLifecycleOwner, Observer<Resource<BaseResponse<User>>> {
        checkSignUpResponse(it)
})

after i am navigated to the next fragment (OtpFragment) when i am using navigationUp() sign up observer called method in observer (checkSignUpResponse) and sending me to otp fragment again.

i tried

viewModel.signup.removeObservers(viewLifecycleOwner)

and also

viewModel.signup.removeObserver(signUpObserver)

but it doesn’t work.

Answer

I have just used isNavigatedToOtp boolean switched while navigating n check weather is isNavigatedToOtp false n then called checkSignUpResponse.

Categories
discuss

SMS Receiving and Sending in Flutter Application

I am building a flutter app in which i want to capture incoming sms. I searched on pub.dev and found few packages offering similar functionality i.e. sms_maintained and sms_retreiver etc. I tried them but i am not satisfied with the provided functionality. I need more control such as listening to incoming sms messages while app is not running and manual control to start and stop listening for messages. So, i am thinking of writing own SMS handling code from scratch instead of using a package. I want guidance to achieve this. i.e. where to start???
I am new to flutter and mobile app dev, i don’t know whether my question is worthy of being answered or not, that’s why i am asking.

Answer

You are going in a big project by implementing a package like that. But there is no door a dev can’t open 🙂

There are some thing you should know before starting your project:

  • Flutter is not able to do this by nature, Flutter is an UI SDK, every non-UI thing relay to the underlying platform (Android, iOS, Web, Desktop)
  • Flutter is able to communicate with the native platform to do specific platform things (in your case, manage SMS)

You have to learn how to create a native Flutter plugin, a plugin implemented in platform-specific code (Java/Kotlin, Swift/Objective-c, C/C++/Go) which communicate with some Flutter UI code (written in Dart) via Platform Channels.

There are some tutorials found over the web:

Hope this will help, and good luck!

Categories
discuss

How to have Luxon’s Intl API working in React-Native

I’ve been using Luxon for quite sometime as a replacement for moment, being light weight and an overall great documentation, I’ve now bumped into a case where I needed to use luxon’s toFormat function to write the date month name.

Now this problem only occurs in Android and not in iOS, I’m assuming because some of the javascript in iOS also comes from Safari, and the browser does support Luxon’s Intl API.

Basically my question is how do you make Luxon’s Intl Api work on Android?

React-Native version: 0.62.2

Answer

So while I was writting my question I was still reading luxon’s documentation and searching for any possible solution.

From Luxon’s docs I was redirected to JSC Android Buildscripts

Which at first sight looked like a promising solution, while at the same time I had found an issue that was reported in react-native’s github Fresh Install Android Broken on React Native 0.60 RC2

And basically by reading both sides I found that in the app/build.gradle file there’s a variable called jscFlavor, which literally states

For example, to use the international variant, you can use:

def jscFlavor = 'org.webkit:android-jsc-intl:+'

Basically by changing the jscFlavor to ‘org.webkit:android-jsc-intl:+’ I was able to have Intl working in Android with Luxon

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..