What widget for Swiping entire page with data from sqflite? - flutter

Does anyone know what kind of Flutter widget can do left/right page swipe to move to another page like in the reference that takes in the data from sqflite database to generate the contents?
I found this package https://pub.dev/packages/swipeable_page_route which does the swiping nicely, but the page is required to be hardcoded, so in my case, it's not quite efficient to do it.
Thanks in advance!

Related

Flutter - web app - what's the best practice for displaying a modal data entry form?

I'm building a web app with Flutter, and I was wondering what the best options are for displaying a modal data entry form that does not need to take the whole screen space.
Initially, I was looking at pushing another Scaffold based screen, but that takes up the whole screen space.
Any suggestions?
My humble solution is to wrap your Scaffold's body's Widgets in a Stack.
You can choose whether or not to display the form using if (someState) ... inside the children list.
The form itself can be wrapped in a Card that is wrapped in a Center Widget.
There might be better solutions but that's what I use.

Flutter: Live Mirror Content of Widget to another Widget

I'm trying to live copy the content 1:1 to another widget. Is there some Widget that already has this functionality?
For some Context: I have the Surface Duo and the hinge blocks some of the content in the middle (under the hinge) when spanning the app across both screens. There seems no way to avoid that, so I'm trying to build an app that prevents this as follows:
Build a custom browser
Render at full screen resolution
Copy content to second widget
Overlay/stack second widget on top of first widget, clip/crop and move it so that the content continues without loss of information.
I'm happy to elaborate on the problem if you have any questions. Of course any other solution that you might come up with is appreciated (for example, if there is some way to skip rendering a Widget for part of the screen).
Thanks in advance and best,
Daniel

Is it necessary to optimize pageview with large amount of pages in Flutter?

I have a PageView with a large amount of pages in my app. Each of the pages is very complex with a PageView and its own pages.
I'm new to Flutter and my first hunch is that it needs optimization. So within the build() function of the outmost PageView I check the index and only make full page for current, previous and the next page(I guess swipe animation needs current page and the page next to it built ahead). For other pages I just give it an empty Container().
Is this necessary and the right thing to do? I felt this is an obvious optimization that the Flutter should do, but I can't find any related discussion online. Any suggestions are appreciated!
Flutter's PageView is lazily calling itemBuilder you provided. For an index it's called only when the page is really needed and you don't need to do anything more. But for further improvements you can make your view hierarchy simpler and prevent unnecessary build method calls. Here you can read more about Performance best practices.
No, it's not. ListView, GridView, and widgets alike are already optimized to build and render only what is needed in the moment. You get a hint of that in the PageView.builder description :
Creates a scrollable list that works page by page using widgets that
are created on demand
I think the difference between a regular PageView and a PageView.builder is that PageView initializes all children at startup, while PageView.builder are initialized lazily.

How to prevent Stateful Widget stored in List to be disposed?

Let me start by explaining the problem. I have several buttons which are created based on data I'm getting from a server. On each button click I need to create and display a widget which will present me some data (this widget is also built dynamically). The state of this widget has to be preserved during the lifetime of the app. (for example if I click another button and show a different widget, I need to be able to click on the first button and show the first widget in its preserved state). Number of buttons can also be changed during the app lifetime.
I tried using IndexedStack to achieve this, but when the number of buttons is changed I need to add "pages" to IndexedStack, therefore I need to recreate a new IndexedStack which will have some of my old widgets, so I pull widgets from a List or create new ones if needed. This works great, except Flutter calls dispose() method on my widgets which are stored in the list. I tried using the AutomaticKeepAliveClientMixIn but it didn't help.
I'm guessing this has something to do that the widgets get detached from the parent, but when I reattach them to new parent (new Indexed stack) Flutter doesn't figure out this properly.
Any ideas?
Try to store data to local storage or sqlite for persistence data.

How to load data on a screen on the press of a button without routing and rebuilding whole screen

Pardon me if this is a naive question but I am trying to figure out a way in Flutter to load different data when the user clicks a button. The way I currently see is routing the user to a new screen everytime but I am sure there would be a better approach without loading the whole screen everytime
You should use a Stateful Widget
I would create a Future Builder / ListView Builder. Depending on how you want it to behave you could have the ListView items clear before regenerating the list of items to show.
Future Builder you could create a function to return certain widgets depending on the request you make with the function.