Access Flutter route outside MaterialApp - dart

I have a "fixed" custom app bar Widget that sits outside my Material App. I want this app bar to constantly sit at the top and the Widget views to change.
I would like this app bar widget to be able to listen to the routes being updated in the MaterialApp and react accordingly.
I think I need to use a RouteObserver but am struggling to have this app bar subscribe to any route events. I have tried broadcasting a stream to notify any widgets listening to it but this fires from the initState lifecycle hook so only is fired once and not received when calling Navigator.pop()
I have tried this https://docs.flutter.io/flutter/widgets/RouteObserver-class.html.
Any ideas on how this can be achieved?

I'm not sure if this is the correct way of handling the Route outside MaterialApp but this is how I have solved the problem.
I moved to use the Fluro navigator https://github.com/goposse/fluro which has given me a nicer route framework to use.
I now have a Static method that handles the Fluro route as well as broadcasting a view change Stream event to any components listening for my new Application.doRoute(context, path).
Inside the Application.doRoute(..) I add to my own custom _history List which has a context and path for each new Route. I can then call another static function called Application.doBack() which then pops the last item in the _history and broadcasts the view change Stream again.
I now can have root display list level Widgets react to changes within the MaterialApp.
Navigator.pushNamed and Navigator.pop() have now been replaced with Application.doRoute() and Application.goBack()

Related

How to add Buttons to a iOS 14 Widget

I'm trying to add buttons to a widget having family type ".systemLarge". I want to execute some code without opening the app.
Anyone knows how to do that?
For example the Shortcuts App Widget includes buttons you can tap to execute a shortcut without opening the app.
Widgets are read only. The Shortcuts app is an exception.
https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension
Widgets present read-only information and don’t support interactive elements such as scrolling elements or switches. WidgetKit omits interactive elements when rendering a widget’s content.
You can add Link controls on medium and large size widgets to get a button like behavior.
This won't allow you to create interactive widgets, which change their content by clicking elements inside the widgets.
But you will be able to tell which "link" was clicked based on the widgetUrl provided when your app gets activated through the widget.
See the chapter Respond to User Interactions here:
https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension

Flutter touch events passing through Drawer Element to underlying UIKitView with embedded WKWebView

I've got a Plugin which uses a UIKitView which contains a WKWebView on iOS and a AndroidView with WebView on Android. The Android solution is working as expected, but I've got two problems on iOS. First, some contents of the web-view, e.g. HTML content, is overlaying the AppBar and second, i can click right through a Drawer element which triggers some click events of my HTML page. I've been able to "solve" the first problem by putting the plugin view into a ClipRect.
Any ideas what causes this behaviour and how to solve it, especially the second one?

Mark menu item selected on push in Flutter app

In my Flutter app there is Drawer that shows menu items.
Selected menu item has different color, I handle it storing selectedItemIndex in Drawer. I want to solve two issues:
When app receives push notification it changes screen so now selectedItemIndex should be changed outside Drawer.
Routes that are used while handling push notifications are almost similar to routes used in Drawer menu. So I want to avoid code duplication.
What way of storing and updating selectedMenuIndex as well as handling routes should be used in Flutter?

Slot not displayed while using vaadin applayout

I'm trying to build application using vaadin's vaadin-app-layout-flow.
here is sample app where I want to create slot-ed parts while using mainlayout which is using app-layout. I want to create some kind of master-detail view so in my UserMasterView i'm trying to set entire component/element as master-content slot with this code getElement().setAttribute("slot", "master-content");.
When I display the view on localhost:9999 which should use mainlayout the content of UserMasterView is not displayed. However when I navigate to localhost:9999/users where mainlayout is not used content of UserMasterView is displayed without problem.
So the question is...is it possible to use slot with app-layout? Or is there any other problem which I don't see?

What method to override to know when the application exits from any screen

I have to do a clean up of some app generated files, when the application is completely closed. The close can happen from any screen. Which method or where should i override globally to caputure Menu Close event, rather than overriding onClose() on each screen of the application ?
And when the application is closed using Menu Close in the middle of the application, is onClose() called for each screen on the stack and are popped off the stack, or it just removes the application from memory ?
I don't believe there's a method that does exactly what you want but I think you can get the behavior you want. First off, based on the testing I've done the close menu item simply calls onClose() for the current screen. The default close menu item does not close the entire application, it just closes one screen.
The closest method I can think of is deactivate(), this is called when the app is sent to the background but not when it's actually closed (i.e. this method will be called if you press the red "end call" button but not if you press close in the menu). This would probably be overkill but what you could do is select "Auto-run on startup" and "Do not display the application icon on the BlackBerry home screen" in your BlackBerry App Descriptor. This would make the app invisible to the user so that it's always in the background, to have an icon on the homescreen and display a GUI you would create an alternate entry point that will bring up the UI. Then when the user selects the close menu item all it's really doing is sending the application to the background and you can put your cleanup code in deactivate().
A much better approach would be to just override onClose() in a parent class and then just make all of your screens inherit from that class. You can put your cleanup code in there. Or if you want the close menu item to close all screens override the makeMenu() method and add a MenuItem that will execute the appropriate cleanup code before calling System.exit().
In my app, I just have all the screens inherit from a common parent class. In that parent class, I implement my standard exit handling.
The correct place to put code that runs when a screen is popped is Screen.onUiEngineAttached(boolean). That method gets called when a screen is actually pushed or popped from the display stack. The other methods are only relevant if you are overriding the behavior of menu items or dirty screen handling.
Another option would be to have a single listener object that handles all this behavior, and use Screen.addScreenUiEngineAttachedListener() to subscribe it to all screens before pushing them on the display stack.

Resources