MaterialApp must it be only one in the whole application? - flutter

I have an interesting question. Seeing Flutter's MaterialApp class, you will find congruences with an activity on the entire application that we are going to build for Flutter. But my doubt is this. Do I have to enter N MaterialApp for each section where I can't go back? Or is it thought to be unique?

The internal design of MaterialApp indicates that it is designed to be used only once in the application. It has fields like localizationsDelegate,theme, and routes, which will be bad design if it used more than once , because most of these field will resort to default values causing a significant memory waste.
If you just want to use it to prevent navigating back to other screens or "sections", there are plenty of options provided by flutter like Navigator and WillPopScope.

Related

Navigate routes not recommended for most applications flutter in flutter docs

I was reading here about navigate with named routes, and in the document itself it says that it is no longer recommended to use it in many applications. Can anyone recommend me what is correct to use now? Or some article talking about.
Flutter docs suggests using go_router package for Navigation.
Explanation:
Limitations of trivial approach
Although named routes can handle deep links, the behavior is always the same and can’t be customized. When a new deep link is received by the platform, Flutter pushes a new Route onto the Navigator regardless where the user currently is.
Suggested Better Approach
Flutter applications with advanced navigation and routing requirements (such as a web app that uses direct links to each screen, or an app with multiple Navigator widgets) should use a routing package such as go_router that can parse the route path and configure the Navigator whenever the app receives a new deep link.
Reference questions regarding go_router:
Flutter: go_router how to pass multiple parameters to other screen?
Go_Router Pass Object to new route

How to document Flutter widgets and screens classes in my app?

I don't know what is the common way and best practices used in documenting UI widgets and components in a Flutter app, I could find a good resource on how to document dart code in general here
And how you can describe a function behavior or a model attribute.
But what is the best way to add comments for UI Classes, Screens, Refactored Widgets, etc..
so that it can be helpful and describes the widget or the screen contents?
The whole flutter project is open source. You could always check how the flutter team documents its widgets.
For example, here is the source of the Container widget:
https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/container.dart
Personally, I would only document widgets which I publish as part of a library. But tastes are different :D

Stateful Classes Flutter project

I'm trying to generate a Flutter app, to create a stateful text field that I can call from other class (passing a name of the field and a limit for the field)., but I don't know how to do that,
Basically, I'm trying to be concise and reduce the amount of code for (variables)consecutive text fields.
Could someone help me?
In Flutter, you don't usually work like that.
Instead, use state management classes to store any manage state information, and provide a Stream instance that is then used to update your widgets (TextField) when state changes.

Which is the best way of Routing in a Flutter App

Which is the best way of Routing in a Flutter App?
I've tried named routes, routes array, flutter navigation 2.0. But I am still not sure which is the best.
Flutter docs suggests using go_router package for Navigation.
Explanation:
Limitations of trivial approach
Although named routes can handle deep links, the behavior is always the same and can’t be customized. When a new deep link is received by the platform, Flutter pushes a new Route onto the Navigator regardless where the user currently is.
Suggested Better Approach
Flutter applications with advanced navigation and routing requirements (such as a web app that uses direct links to each screen, or an app with multiple Navigator widgets) should use a routing package such as go_router that can parse the route path and configure the Navigator whenever the app receives a new deep link.
Reference questions regarding go_router:
Flutter: go_router how to pass multiple parameters to other screen?
Go_Router Pass Object to new route
Navigator 1.0 and 2.0 are usable. None is deprecated.
For mobile app only Navigator 1.0 is the best, I use onGenerateRoute field from MaterialApp and that's all I can handle all my routes and deep links. Some times, I used the Navigator widget for specific routes in app page but it's rare.

Which is the better way to white-label a flutter app

I have one project that I have to sell to another clients, so I wanna found a way to unify the code to, when I release some updates, I have to manipulate only one code (and, of course, keeping the specificities from each one)
I found an article HERE which the guy creates a new folder named 'config' and set some variables there to be used in the parent project. I tried this but find out that would be very tough to do because the first app was developed specifically by one client, and with it I would need so much time to make all the aspects dynamic... Another problem is firebase, in first app I used firebase but in the second i won't. How to make it possible?
And in this article they say about 'flavours' that can be used to do something similar.
Someone knows about this approaches or there is another to reach my goal? With flavours I will have less re-factor than with config?
I appreciate any help
A third way to do this with no client specific app configuration is to make an api call to get back your client specific theme, and then set the flutter theme based on this.
If you need web support see below:
First update your assets in index.html that aren't white labeled, leaving stubs in their place that we'll fill in later. i.e.
Next show a nice loading indicator while flutter loads. To do this, just put the html for it in the body element of the index.html file.
Finally update the webpage title and favicon using javascript inside Flutter. I used package
universal_html: 2.0.8
https://pub.dev/packages/universal_html
then you can update the favicon
import 'package:universal_html/html.dart';
var favicon = document.getElementById('favicon');
favicon?.setAttribute('href','insertLinkToYourImage');
Updating the title can be accomplished in various normal ways like just setting the title attribute of a MaterialApp widget.