As Flutter becomes more and more popular, people keep coming with amazing ideas to make hard stuff easier and easier. The plugin I m about to talk about is the same, saving time by converting the JSON file to a dart class for you, so you can focus more on the logic building side of things.
The JSON to Dart plugin helps us achieve exactly that, Its a wonderful plugin with many build in features to make the life of developer easier.
Now, before we dive into installing and using the plugin, let us first discuss what exactly is JSON?
JSON stands for JavaScript Object Notation, It is a lightweight format used for storing and transporting the data, it is used when you make a call to server and it has to return some data, which the server returns in the form of JSON.
The main rules of creating a JSON is that you must use double quotes (“ “) and every values must be a pair of name and value, the name is the field name which is on the left side and on its right side is its corresponding value.
In the example, the names is a List which contains a Map of names of employee which have following fields
first_name
middle_name
last_name
To gather more information on JSON you can look up W3Schools.
Now we move onto getting the plugin itself, To install all you need to do is go to
File -> Settings -> Plugins
Then write in JSONtoDart and install the first one that comes up, and you are now done with the installation part
Here is some example JSON you use, curtesy of dummy.restapiexample.com
Alright after navigating to the page you can select all the text and copy it,
Now move onto your project and click on the folder you want to place your file in, personally i would keep it under lib/core/models
Now right click on models directory and then
New ->Json To Dart
Note : Alternatively you can also press Alt + shift + D
Now this will come up
Where you can put in all the JSON text you copied earlier, like this :
Be sure to press the format button right after you paste the data, so you can see it properly formatted.
All that’s left is now to give it a name in the Class Name field , since this is employee data you can give it something like Employees, there are also options as well like,
generate comments which will basically put in all the JSON data you entered as a comment so its better to turn it off,
or generate private fields which will generate variables with an ‘_’ before them,
you can even create separate inner classes if you wish to use them using the generate inner classes.
After that all you need to do is hit Generate button and in matter of seconds your class will be generated, completely ready for you to use.
The generated class
This plugin helped me many times by instantly creating classes for me to use in my project instead of me manually seeing each and every field name and writing a variable for it, so I thought I should let everyone know about this amazing plugin too, If you have any issues installing or using let me know in the comments below, I will try to resolve it ASAP, see you guys in the next blog.
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
Feel free to connect with us: And read more articles fromFlutterDevs.com.
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
In this blog, I will talk about creating a ClipRRect and Custom path using CustomClipper and use it in ClipPath in flutter application. In this app, we can circular the shape of any image using ClipRRect while we can create any type of shape using ClipPath. It will not contain any kind of package in it. We will implement a demo of the ClipRRect and ClipPath in a flutter in your flutter applications. Now let’s start.
“ Flutter is Google’s UI toolkit that helps you build beautiful and natively combined applications for mobile, web, and desktop in a single codebase in record time”
ClipRRect:
The ClipRRect widget is used to clip your child using a round import. It connects with the clippers family. The main function of the clippers is to print any part of the widget as per it’s a requirement. It is similar to ClipRect. It is used to clip the import part of the child widget. ClipRect has its own side per its requirement. We can do circulars. But Clippath is the one used to clip widgets in a customized fashion. We can do widgets as per our requirement. It has two Properties Clippers and ClipBehavior. Clippers what happens takes a custom clipper that defines how the text will be clipped and the clippings are clipped according to this option in the clip behaviour property.
Demo Module :
Code Implement :
1.ClipRRect:
This is a widget used to clip a round import. You can specify the radius of the corner in the borderRadius property of this widget. while you can not resize it in an image with rounded corners without this widget container widget decoration properties.
Create a new dart file calledcliprrect_demo inside the lib folder.
When the custom clip needs to be updated, it is called the getClip method. and this method has a parameter that gives the value of width and height.
The shouldReclip method is called when providing a new instance of the class. If the new example has different information than the old one, it should be returned true or it is false.
As you can see above, the x- increases horizontally, and Y-axis increases downward.
lineTo:
Using this method one can cut the widget with a line from the given point . x and y are two destinations points where the line stops.
quadraticBeizerTo:
with the help of quadraticBeizer method, you can clip your widget with curves.we can draw a quadratic bezier curve using the control point and endpoint.
In this article, I have explained a ClipRRect and Clippath demo, you can modify and experiment according to your own, this little introduction was from the ClipRRect and Clippath from our side.
I hope this blog helps will provide you with sufficient information in Trying up the ClipRRect and Clippath in your flutter project. So please try it.
❤ ❤ Thanks for reading this article ❤❤
If I got something wrong? Let me know in the comments. I would love to improve.
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
Feel free to connect with us: And read more articles fromFlutterDevs.com
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.
It’s an acronym for 5 design principles for writing code which is maintainable, scalable and easier to understand. These principles are given by Bob. C Martin (uncle bob) more familiar to the developer world.
Things To Understand Firstly :
What Problem these S.O.L.I.D principles solved?
working with the legacy code.
Re-reading the code multiple times to get to the part you need to change
Hard to understand what the method does. jumping multiple methods of the same name
spending a lot more time to fix a minor bug
Basically, we spend a lot more time reading than writing code.
1. Single Responsibility principle
As it’s clear from its name single responsible. A class should only be responsible for one thing that means a class could change for only one reason.
Let’s first see the bad practise in which maintenance is not pleasant. Because of all the things in one single place validation, getRequest, painting.
// get request searchResult() { // return result; }
//painting showResult(ResultModel model) { // show result in pleasant way }
}
class ResultModel {
}
After applying the Single Responsibility principle
Now the developer can focus on the desired functionality.
info :: class Result is responsible for the flow.
class Result { checkResult(int rollno) { bool isRollnoValidate = Validate().isRollnovalidate(); if (isRollnoValidate) { ResultModel resultModel = NetworkApi().searchResult(); Printing().showResult(resultModel); } else { return "Invalid rollno"; } } }
class Validate { // this is responsible for validate isRollnovalidate() { return true; } }
class ResultModel {}
class Printing { // this class is responsible for printing showResult(ResultModel model) { // show result in pleasant way } }
class NetworkApi { // this class is responsible for fetching result searchResult() { return ResultModel(); } }
2. OPEN-CLOSED PRINCIPLE
An entity should be open for extensions but closed for modification
It states that for good practise you should be able to add new features without modifying the existing code.
Let’s first see the bad practice. In this, if we need to mechanical branch result feature then we need to edit the existing code.
class Result { mechanicalCheckResult() { // some code }
civilCheckResult() { // some code }
}
After applying Open CLOSED PRINCIPLE. In this, we create a class for adding new functionality.
abstract class Result { checkResult(); }
class ComputerScience implements Result { @override checkResult() { // some code } }
class Civil implements Result { @override checkResult() { // some code } }
class Mechanical implements Result { @override checkResult() { // some code } }
3. Liskov Substitution Principle
It means how good is your design from abstraction perspective
The architecture guarantee that the subclass will maintain the logic correctness of code.Basically prefer composition (with interfaces) over inheritance
As above let’s first see bad practice
abstract class Result { checkResult();
codingTestResult(); }
class MechanicalBranch extends Result { @override checkResult() { // some code }
/* * Here it is logically incorrect * */ @override codingTestResult() { // some code } }
class ComputerScienceBranch extends Result { @override checkResult() { // some codet }
@override codingTestResult() { // some code } }
After Applying the Liskov Substitution Principle
abstract class OfflineResult { checkResult(); }
abstract class CodingResult { codingTestResult(); }
class MechanicalBranch implements OfflineResult { @override checkResult() { // some code } }
Abstractions should not depend on details(concrete implementations). They should depend on abstractions.
Basically, you should able to change the implementation(background or low level code) without altering the high-level code(actual class you interact to).
Its good to extending a abstract class or interface but reverse (means with no abstract method) is a bad practise.
Depending on abstractions gives the freedom to be independent of the implementations. Let’s dig into it.
abstract class Payment { payment(); }
class PaymentViaCreditCard implements Payment { @override payment() { // some code } }
class PaymentViaDebitCard implements Payment { @override payment() { // some code } }
class PaymentViaBhimUPI implements Payment { @override payment() { // some code } }
class Checkout { // our checkout class knows nothing about how payment works // its knows pay.payment() is paying method checkOut(Payment pay) { pay.payment(); } }
I highly recommend watching this video. That’s the minimum thing I can do to express my gratitude.
Conclusion :
Don’t get trapped by Solid
: S.O.L.I.D Principles are principles, not rules
: Always use common sense while applying this. Your goal is to achieve to make your code maintainable, easy to extend.
: Avoid over- fragmenting your code for the sake of SRP or S.O.L.I.D
: Don’t try to achieve S.O.L.I.D, use S.O.L.I.D to achieve maintainability. It’s a tool, not your goal
A warm welcome for all the queries and suggestion. If you find anything that could be improved please let me know, I would love to improve
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
Feel free to connect with us: And read more articles fromFlutterDevs.com
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences!
Flutter team come up with a new update. A declarative API to set the history stack of the Navigator and a new Router widget to configure the Navigator based on events.
Now Navigator that allows setting the navigator’s history stack in a declarative way by providing a list of immutable Pages
For those who don’t know the difference between declarative and imperative programming?
Brief introduction :
“Imperative programming is like how you do something, and declarative programming is more like what you do.”
when pop is invoked but the current Route corresponds to a Page found in the pages list. And The result argument is the value with which the route is to complete. This callback is responsible for calling Route.didPop() and returning whether this pop is successful.
The Navigator widget should be rebuilt with a pages list that does not contain the Page for the given Route. The next time the pages list is updated, if the Page corresponding to this Route is still present, it will be interpreted as a new route to display.
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
Feel free to connect with us: And read more articles fromFlutterDevs.com
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences!
In this blog, I will talk about how to create a stateful dialog form using the stateful builder. Where you can take TextField checkbox or any other type input on dialog. which you may need. We will create our own state of a dialog using the stateful builder and we will use a form widget with a global key which flutters to validate textfield. Let us now implement stateful dialog in your flutter application. Now let’s start.
“ Flutter is Google’s UI toolkit that helps you build beautiful and natively combined applications for mobile, web, and desktop in a single codebase in record time”
Stateful Dialog Form:
A StatefulBuilder is such a builder. In which there is a mutable. Which can have a change of state. what makes it special is that it has to rebuild its special widget which comes under the Statefulbuilder. Stateful builder widget that we use can be used to update a specific element in the UI if the stateless widget. and moving the stateless widget to the stateless widget and getting rid of the stateful builder can store the same result. and the whole widget is not rebuilt again and again.
Demo Module :
Code Implement :
Create a new dart file calledflutter_sateful_dialog inside the lib folder.
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
Using the Global key we use the global key to access and manipulate the status of our form and external Scaffold widget. The Global case allows us to access unique identities that our widget in the flutter widget tree is assigned. As we create a form application using it. In this, we have a separate input box. we stop the rudimentary validation check on it and when it satisfies those validation conditions and the user interface changes to show that.
We have used the alert dialog in this screen, inside which we have used the SatefulBuilder. A Statefulbuilder widget that has the power to the state setter function it is. used to build itself rather than the typical state of the entire widget to pass to the builder. And in this, we have taken the input box of type TextFormfield and used the checkbox.TextFormField has a function of the type validator that we have used for applying in the input box.
In this article, I have explained a Creating Stateful Dialog Form demo, you can modify and experiment according to your own, this little introduction was from the Creating Stateful Dialog Form from our side.
I hope this blog helps will provide you with sufficient information in Trying up the Creating Stateful Dialog Form in your flutter project. So please try it.
❤ ❤ Thanks for reading this article ❤❤
If I got something wrong? Let me know in the comments. I would love to improve.
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
Feel free to connect with us: And read more articles fromFlutterDevs.com
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.
Need expert help building your Flutter app?Talk to FlutterExperts for architecture, development, and consulting support.
In this blog, I will talk about The New material Button Version 1.22 in a flutter. We will implement a demo of the New material Button in a flutter in your flutter applications. Now let’s start.
“ Flutter is Google’s UI toolkit that helps you build beautiful and natively combined applications for mobile, web, and desktop in a single code base in record time ”
New Material Buttons Version 1.22 :
Flutter New material button has come with flutter new version 1.22. While the old buttons still there. It basically involved creating and using custom buttons. While this is not the case with 1.22. Now you can easily set that theme in it. This will apply to all buttons of the type chosen globally.
As you can see a table below. That the buttons and their themes replace the existing ones:
Demo Module :
Code Implement :
TextButton: The TextButton is a replacement for FlatButton.We are commonly used for dialogs and low pronunciation functions, including those in cards. It does not have visible limitations. This is also the case with the button theme data is sent to the theme we pass these to the property. This is the new property in them data. And one of them is the TextButtonTheme related subject property. This TextButton accepts the theme data. within which we can set the color of the button, etc.
The style of a TextButton can be override with its style parameter. The style of all text buttons in an app can be override with the theme data TextButton end. And to override the background color of the button create a Button Style with the help of TextButtonTheme.The selected button state measure the background color.
2.ElevatedButton: Elevated Button is a replacement for RaisedButton which is used as the primary actions in the app. And also we can change the size color of the button globally with the help of ElevatedButtonThemeData: .
3. OutlinedButton: The OutlinedButton is a replacement for OutlineButton. And this is a medium thrust button. They have actions that are important. But they do not perform primarily in any app.
The style of an OutlinedButton can be override with its style parameter. The style of all text buttons in an app can be override with the theme data OutlinedButton end. And to be override the background color of the button create a Button Style with the help of OutlinedButtonThemeData.The selected button state measure the background color .
class _FlutterNewMaterialButtonState extends State<FlutterNewMaterialButton> { final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
double _height; double _width;
void _showMessageInScaffold(String message) { try { _scaffoldKey.currentState.showSnackBar(SnackBar( content: Text(message), action: SnackBarAction( label: 'Undo', onPressed: () { print('Action in Snackbar has been pressed.'); }, ), )); } on Exception catch (e, s) { print(s); } }
In this article, I have explained a New Material Buttons Version 1.22 demo, you can modify and experiment according to your own, this little introduction was from the New Material Buttons Version 1.22 from our side.
I hope this blog helps will provide you with sufficient information in Trying up the New Material Buttons Version 1.22 in your flutter project. So please try it.
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
Feel free to connect with us: And read more articles fromFlutterDevs.com
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.
Spacer widget is used to create a customized spacing between the widget. It is mainly used to create an adjustable spacing between the widgets in a flex container like Rows and Columns.
Flutter although provides spacing alignments that are already predefined such as spaceAround, spaceEvenlyand spaceBetween but still provides an additional Spacer widget just for adjustable spacing as per their need accordingly. The main advantage of using Spacer is that the spacing provided between the widgets is set according to our requirements.
Properties used in Spacer class :
key: Controls how one widget replaces another widget in the tree.
flex: This property is used to define how much space is required to take up between the widgets. This property creates a space between widgets in form of ratio division. It takes an integer value and its default value is 1.
Sample :
This is how the spacing between the container looks like :
As you can see above the space between the container is equally divided in an equal ratio accordingly.
Now let’s try to understand this widget by taking more examples:
Let’s Start:
Here above the code, we have usedflex property with its different-different values inside the Spacer widget. Spacer widget uses flex value 3 between the first two containers and flex value 2 between the second and third container, and value 1 between the third and fourth container while no Spacer widget is used after the fourth container.
This is how it looks ::
In the above example, the flex property is used inside the Spacer widget. The flex value in total is 3 + 2 + 1 = 6 .
Now let’s understand the spacing ratio. The space between the first and second container will be 3/6 of the applied space while the space between the second and the third container will be 2/6 of the space while the flex value between the third and fourth container is 1 so it will be having 1/6 of an applied spacing.
Remember the default value of flex is 1. If the flex property is not used inside the Spacer widget it will automatically set it as its default value.
Note:: The same concept can also be applied to Column as already mentioned above.
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences!.
Wrap class is a widget that is used to display its children or widget in a multiple horizontal or vertical direction. Wrap class is basically used to wrap our children in a direction as provided which looks similar to somewhat Rows and Columns.
Wrap class is used to align or adjust multiple widgets vertically or horizontally similar to Rows and Columns. It can be adjusted either in form of Row or Column as required. Wrap class automatically align or fit the widgets accordingly in its cross-axis area without displaying an Overflow message similar to Rows and Columns.
Properties :
alignment: this property is used to describe how the children should align in the main axis. Its default value is WrapAlignment.start.
clipBehavior: This property takes in Clip enum as the object and decides whether the content should be clipped or not according to the option.
crossAxisAlignment: this property is used to describe how the children should be aligned relative to each other in the cross-section part. Its default value is WrapCrossAlignment.start .
direction: This property uses a direction as the main axis. By default axis is horizontal and we can change it to vertical by using Axis.verical its value.
runAlignment: this property describes how the run should be placed in the cross axis. Its default value is WrapAlignment.start.
spacing: this property is used to place a space between children in the main axis.
runSpacing: this property is used to place a space between the children along a cross axis.
textDirection: this property is used to arrange the children inside Wrap class in the given direction.
verticalDirection: this property is used to determine the order to lay children out vertically and how to interpret start and end in the vertical direction.
Sample :
This is how this sample looks :
But if we have used Rowinstead of this Wrap class then the widget may have Overflowed by pixels as shown below…👀
To fix such issues we uses Wrapclass instead of using Rows and Columns.
Implementation:
As shown above we can also apply other properties also…👍
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences!.
In this article, We will explain about The dropdown button in a flutter. A dropdown button is a material design button. So let’s apply a demo of the dropdown button in your flutter applications.
“ Flutter is Google’s UI toolkit that helps you build beautiful and natively combined applications for mobile, web, and desktop in a single code base in record time ”
Dropdown Button:
We use the Dropdown Button to display any Dropdown List item as we can change its style according to it. Such as its background color, border secular etc. As this Dropdown list because it is a clickable widget. Which shows the list item we have selected. The Dropdown Button has DropDownMenuItem. We initialize whatever is to be shown in the list. and the Dropdown button has a function named onChnaged. When a user clicks on an item from the dropdown. So it triggers and executes the triggered function.
Demo Module :
Code Implement :
Create a new dart file calledflutter_dropdown_button_demo inside the lib folder.
We have explained the Dropdown in this screen. We list items using the Dropdown Button. To show on the click of a button, in the Dropdown Button we have initialized some list items. Which is of string type. That will show us the item.
Seeing the screen above. There is a list showing in this screen, which will initialize the value of the DropdownMenuItemin the Dropdown Button and will show the click value on the click of its item in onChanged.
In this article, I have explained a Dropdown Button demo, you can modify and experiment according to your own, this little introduction was from the Dropdown Button from our side.
I hope this blog helps will provide you with sufficient information in Trying up the Dropdown Button demo in your flutter project. So please try it.
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
Feel free to connect with us: And read more articles fromFlutterDevs.com
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.
How to implement authentication into your flutter app?
How to use the provider package for state management?
How to use git_it package to inject dependencies?
How to implement routes for navigation?
Introduction To Provider
Provider is not a state management, it is just a state management helper. Provider package provides us various widgets that help us to consume various changes in values and then rebuild the widget when any changes occur. The most frequently used classes of provider package are Consumer, ChangeNotifier, ChangeNotifierProvider. The model class that is made available to the app widget tree, extends the ChangeNotifier. This class contains all the app state managing methods and variables and objects. Whenever we update the state of the app we need to call notifiyListeners()to notify all the widgets who are listening to that particular change so that the UI can be rebuilt and updated. ChangeNotifierProvideris wrapped at the top of the app widget so that all the widget of the app widget tree can listen to the change made. There are two methods that can be used to consume the updated data. Using Provider.of() and Consumer widget.
Install the bellow packages inside your pubspec.yaml file
MaterialApp provides us onGenerateRoute, initialRoutefunctionality to implement navigation using routes. onGenerateRoutetakes RouteSetting as a parameter and returns a Route.
Let’s create a separate class to initialize all the navigation cases using the switch method. We will make a static Route<dynamic>type method that takes RouteSettings parameters.
class Routers { static Route<dynamic> generateRoute(RouteSettings settings) { switch (settings.name) { case 'home': return MaterialPageRoute(builder: (_) => HomePage()); case 'landing': return MaterialPageRoute(builder: (_) => LandingPage()); default: return MaterialPageRoute(builder: (_) { return Scaffold( body: Center( child: Text('No route defined for ${settings.name}'), ), ); }); } } }
Now we can provide the onGenerateRouteproperty also initialize the initalRoute .
class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( initialRoute: 'landing', onGenerateRoute: Routers.generateRoute, ); } }
For navigation, we can use pushNamed method to navigate to another screen using the name of the route name defined in the router.dart .
Here we have created two methods to change the state. setViewStatemethod is used to switch the ViewStatefrom Idel to Busy and vice-versa. setAuthStatemethod is used to switch theAuthStatefrom SignInto SignUpand vice-versa.
Now create a AuthModel class that extends BaseModel . This class will contain all the auth methods.
The above class will be used to provide the various methods that will handle the authentication of our app. Now we will make all the methods that will be used to handle all the UI changes when the user will switch between the sign-in and sign-up option.
Till here we have made all the required methods that will be used to update the UI of different screens. Now we will create a BaseView class that is used to update the UI, pass the model data that we have made earlier.
BaseView takes a builder function that takes BuildContext, Model, and a Widget as a parameter.
BaseView widget can only be used for the model class that extends BaseModel.
class AuthPage extends StatelessWidget { final TextEditingController emailController; final TextEditingController passwordController; final AuthModel authModel;
Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
Wewelcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences!.