r/FlutterDev • • Aug 14 '22

Discussion How will Flutter apps adapt to Android 13's predictive back gesture?

For those not aware, Android 13 will implement a cool new animation that will hint users on where they will land if they complete the swipe back gesture.

According to the page I linked, for most native apps it will be enough to just add android:enableOnBackInvokedCallback="true" to the Android Manifest, whereas apps implementing a custom navigation logic will require some more work.

I tried the Android Manifest trick and I can indeed see the new animation (running Android 13 beta on my Pixel 4), but that obviously breaks navigation in my Flutter app completely. Now every back gesture will just take the user back to their homescreen, rather than navigating one level up within Flutter's screen stack (I'm just using the regular navigator push/pop methods).

I've been googling around but I couldn't find anything specific to Flutter, so I'm just wondering: do we know if this is something the Flutter team will implement in the framework without us doing anything? Or will we have to adapt anything ourselves?

If it's the former, I'd expect to have seen something by now given how close we are to Android 13's final release, right?

Does anybody have any info on this? Or maybe I'm missing something obvious and this is a non-issue?

177 Upvotes

16 comments sorted by

12

u/ercantomac Aug 14 '22

Is there a video where this new feature is demonstrated with different examples? Looking at the gif you linked, I don't see why/how this would cause problems.

3

u/VMX Aug 14 '22

I'm not saying it would cause problems, I'm just wondering how to add this to a Flutter app.

Right now we have no way to implement this that I know of.

I haven't seen any other videos as Google hasn't provided any that I could find.

1

u/MyNameIsIgglePiggle Aug 15 '22

Well the gif is peeking at the previous app, so that's not really a flutter thing.

However if it's expected to work in app the navigator is based on a "stack" and that stack is still in memory when you push a new route, so hopefully the flutter team will update the navigator if it's not going to exit the app to "peek" at the previous route in the stack.

I expect it's not really a community problem though I am sure the maintainers would like some help if you want to get your hands dirty.

In any case I can't see why flutter can't implement it relatively easily.

3

u/VMX Aug 15 '22

Well the gif is peeking at the previous app, so that's not really a flutter thing.

If you read through the page, you'll see it is indeed a Flutter thing. Every app (including Flutter apps) needs to be adapted to use the new animation, even for the case where they show you the previous app. It won't magically start working for native apps either when people upgrade to Android 13.

Every app developer will need to add at least one line to their Android Manifest, with more work required for complex apps with custom navigation.

As I explained in my post, I added that line to my Android Manifest, and it did enable the new animation, at the expense of breaking Flutter's internal navigation system... because now every single back gesture will take me out of my app. So I had to roll it back.

My point is, they're encouraging (all) app developers to get our apps ready for this new gesture ahead of Android 13's release, and I want to do it... but I can't. There's no way to adapt my Flutter app, and the Flutter team hasn't provided any roadmap or even confirmation that they'll do it themselves.

I'm just asking how to get my app ready before Android 13 drops, because that's what they're recommending us to do.

9

u/timsneath Aug 15 '22

Firstly, a huge thanks to /u/VMX for filing the tracking issue: https://github.com/flutter/flutter/issues/109513

Today, our friends over in the Android team started the rollout of Android 13. As noted in their documentation:

Note: Android 13 doesn't make the predictive back gesture visible to users, but it does provide an early version of the UI as a developer option for testing. We plan to make this UI available to users in a future Android release. In the meantime, we strongly recommend updating your app to ensure you get the latest updates.

This is a "multi-year" feature, meaning that it will take time for the overall ecosystem to adapt, not just Flutter (for example, the supporting JetPack library support is also hot off the press. Of course, we want Flutter to offer a highly polished experience on Android, so you can assume that this is under active investigation by our team.

2

u/VMX Aug 15 '22

Thanks to you for stopping by this thread Tim, much appreciated!

First time I file an issue in a big repo like Flutter's, and it looks like I might've accidentally triggered the Android 13 rollout 😅

93

u/ElluxFuror Aug 14 '22

I’m commenting to give this post some action. I have no idea how this will be handled or if it will cause any frustration. However, I think this post is much higher quality than many of the posts I’ve been getting notified.

0

u/cuongmv162 Aug 15 '22

The link OP provided have a miration paths to use new back navigation API, scroll down a bit anf you will see it.

I think with new api and deprecated the old one, tbat would make flutter team time and effort to imolememt it into their framework, how long is q question depened on their manpower.

1

u/VMX Aug 15 '22

I know... I'm the OP :-)

Yes, the migration path for apps with custom navigation talks about migrating the navigation logic to OnBackPressedDispatcher by implementing OnBackPressedCallback.

The point is... I'm not implementing any of that logic myself. I'm just using the push/pop navigation logic from Flutter, so I have no control over that.

I'd expect the Flutter team would take care of this before Android 13 drops, and let us know what we need to do (if anything) to activate the gesture, such as adding that line to the Android Manifest maybe.

But Android 13 final release is only a few weeks away. Hence my question...

15

u/[deleted] Aug 14 '22 edited Aug 14 '22

[removed] — view removed comment

5

u/VMX Aug 14 '22 edited Aug 14 '22

So I don't know what this will look like when moving between screens of the same app... mainly because, as far as I can tell, Google has only provided the one GIF, which shows the back transition from Chrome directly to the home screen. I've searched everywhere but I can't find any other examples. Maybe somebody who's developing a native app can shed some light on this.

When I added the above line to my Android Manifest, I can confirm I could see just that - a nice animation where you can take a peek at your home screen before completing the gesture.

But it seems very weird to me that they encourage devs to "get their apps ready" before Android 13 drops, and yet they've provided zero information or docs other than that one page... and nothing at all for the behemoth of an SDK that Flutter is.

And yeah, I think it should be very similar to how the back gesture is already rendered in iOS. In fact, I see this feature as a way to bring some "feature-parity" with iOS in terms of visual navigation cues, which is great.

The one thing that seems difficult is previewing the Home Screen. That would require integration with the OS.

Yep, and that already works if you modify your Android Manifest (at the expense of breaking everything else of course 😅). The system will take care of it.

So in my view, I think the Flutter team just needs to make sure that the standard Flutter navigation system implements this in-app when needed, just like they do today with the existing animations: capture the gesture within Flutter when you still have pages below you in the navigation tree, and hand the gesture off to the system when you're at the root of your navigation tree.

5

u/[deleted] Aug 14 '22

[removed] — view removed comment

4

u/VMX Aug 14 '22

Thanks, hand't thought of that. Although I would be really surprised/concerned if nobody at Google or Flutter had already thought of this.

Do you know what the right repo would be for something like this? I've never opened an issue for something as big as Flutter before.

6

u/[deleted] Aug 14 '22

[removed] — view removed comment

4

u/VMX Aug 14 '22

Done.

Thanks!