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!.
In this blog, I will talk about the GridView List widget in a flutter by implementing a demo of the GridView List widget 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 ”
GridView List widget:
GridView Flutter has a widget that. Which displays the item in 2D. As its name suggests. We then use it. When we have to show the grid’s form items. We can tap on them. And go to another page. In this, we can take image text icon etc. as per our requirement.GridView widget is also considered to be scrollable. Because it is scrollable. To see an example of a grid view, we have many such apps like an e-commerce app such as snapdeal, etc. in which an example will be found.
GridView widget individually it has four more options.
GridView.count
GridView.builder
GridView.custom
GridView.extent
First of all, the following property is important to understand when we implement the grid view widget.
scrollDirection: Axis.Vertical or Axis.Horizontal. We can change the direction vertical and horizontal.
physics: We use scrolling to scroll the item. The utility scrolls from the list end of the list to the beginning.
shrinkWrap: If shrinkwrap is false then the item takes up more space to scroll. which is not good, This causes memory loss. And reduce the performance app. So we set it to avoid memory leakage while scrolling.
padding: It is used to specify the space around the whole list of widgets..
crossAxisSpacing: The crossAxisSpacing use to specify the number of pixels between widgets to all the children listed in the cross axis.
crossAxisCount: It is used to specify the number of columns in a grid view.
mainAxisSpacing: The crossAxisSpacing use to specify the number of pixels between widgets to all the children listed in the main axis.
Demo Module :
Code Implement :
GridView.count:
GridView.count is the most commonly used grid layout. Because we already know the size of the grid. The GridView count has a required end, known as the crossAxisCount.The essential property in the GridView is taken in the grid SliverGridDelegateWithFixedCrossAxisIt is known in the same way as the crossAxisCount.This is obviously the most common.
Let us understand this with the help of a reference.
class RandomColorModel { Random random = Random(); Color getColor() { return Color.fromARGB(random.nextInt(300), random.nextInt(300), random.nextInt(300), random.nextInt(300)); } }
GridView.builder:
We use the GridView.builder when we want to make a big item grid list with a large number of children you can displays data dynamically or data on demand can be shown. Then we can use GridView.builder.
The following are 3 common features of GridViewbuilder.
itemCount: The itemCount is used to define the amount of list item data.
gridDelegate: The gridDelegate determines the divider. Its argument must not be null.
itemBuilder (BuildContext context, int index): The gridViewBuider we use is used to create the item that is displayed on the grid view.
Let us understand this with the help of a reference.
class RandomColorModel { Random random = Random(); Color getColor() { return Color.fromARGB(random.nextInt(300), random.nextInt(300), random.nextInt(300), random.nextInt(300)); } }
GridView.custom :
Grid view is custom. It creates its own custom grid view. All property is the same. It has two essential assets. Which need to be defined using GridDevigate, GridDelegate, and ChildDelegate. Let us discuss Childelgate. Childelgate takes it in two different types of slivers.
SliverChildListDelegate.
SliverChildBuilderDelegate.
This is another way to show both the data or the length of the data. SliverChildListDelegate in which the specified number can specify the number of children. In SliverChildBuilderDelegate we can display many items.
Let us understand this with the help of an reference.
class RandomColorModel { Random random = Random(); Color getColor() { return Color.fromARGB(random.nextInt(300), random.nextInt(300), random.nextInt(300), random.nextInt(300)); } }
GridView.extent:
GridView Extent property is used when we want to create a grid with custom extent values. It means each tile has a maximum cross-axis extent.
Let us understand this with the help of a reference.
class RandomColorModel { Random random = Random(); Color getColor() { return Color.fromARGB(random.nextInt(300), random.nextInt(300), random.nextInt(300), random.nextInt(300)); } }
In this article, I have explained a GridView List widget demo, you can modify and experiment according to your own, this little introduction was from the GridView List widget from our side.
I hope this blog helps will provide you with sufficient information in Trying up the GridView List widgetin your flutter project. In this demo explain the GridView List widget in flutter. 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 from FlutterDevs.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.
Named Routes is the simplest way to navigate to the different screens using naming concepts. When a user needs multiple screens in an app depending on its need then we have to navigate from one screen to another and also return back many times back on the previous screen then it becomes a very hectic task, there we use a naming concept so as to remember screens with its name provided by the user and then we can directly access that route or page directly through Navigator.pushNamed() method.
Here above the code, we have created two routes or screens.
Defining the routes with names :
Note: We cannot use home property and initialRoute property both inside this MaterialApp as they both contradict each other.
Navigate from one route to another :
We will navigate from one screen to another using Navigator.pushNamed() method.
Using static modifier to call naming routes :
If we use the routes method to navigate from one page to another with a naming concept then we have to remember the string that we have provided to its route. When there are multiple screens in an application then it becomes tough to remember each string. So we create one string datatype of it with the static modifier so that we can assign it by directly calling it through its class.
As you can see above we have used a static modifier with string datatypte to both our screen and assign it with the string variable.
Now we have to see how we will call these class in our routes::
As you can see now easily remember the routes by directly remembering its class name as shown above we have used Home.idand Second.id in place of using naming string routes and remembering each string name.
We can directly access it easily and can navigate from one page to another with the same name as provided 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!.
In this blog, we will explore the Animated Align Widget in a flutter. We will be using some core functions available in a flutter. We will implement a demo of theAnimated Align Widget in your flutter applications. So let’s get started.
“ 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”.
Animated Align Widget:
The Animated Align Widget align that automatically positions the child’s position in a given period in a given alignment. And you can choose a period with a curve for the animation. And the widget will animate the alignment to the new target.
Let’s talk about some main constructors of the animated Align Widget. This widget has 3 properties. which do this work in our entire animation. As follows.
alignment(Alignment): where initially the child widget is placed.
curve(Curve): Easy curves are used to adjust the rate of changes in curve animation. This allows the speed to be slow and fast. there are some different-different types of options available.
duration(Duration): the Duration we can decide the time taken for a change of alignment according to ourselves.
Demo Module :
Code Implementation:
Create a new dart file calledanimated_align_demo inside the lib folder.
As I have understood above about the animated align widget. I have considered this as a demo in this screen. And a little code of this widget has been given above. As this screen has an image whose arrangement will go from Alignment.topRight to Alignment.bottomLeft. The duration time is also set as per our It has the option of the curve. There are many types of the curve. We have used the curves (Curves.easeInOutBack).
Code File :
import 'package:flutter/material.dart'; import 'dart:math' as math;
In this article, I have explained an Animated Align Widget demo, you can modify and experiment according to your own, this little introduction was from the Animated Align Widget our side.
I hope this blog will provide you with sufficient information in Trying up the Animated Align Widget 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 from FlutterDevs.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 is really a fantastic tool to build mobile apps. Flutter is a free and open-source tool to develop mobile, desktop, web apps with a single code base. The technical architecture of flutter apps is a much easier, clean, and precise code structure. The community of flutter developer is constantly growing, helping us to provide a better experience and by developing various plugins. Plugins are great, help us to implement various functionality with lesser code and time.
The plugin page provides us an insight into the package quality. We must always prefer to use the package that has better maintenance, continuous improvement, good responses, and Flutter Favourite.
To implement the phone call functionality we need to use the bellow package:
url_launcherpackage will be used to implement phone call using the default app of your mobile phone. This package will auto direct the phone to the default phone call making app and open the dialer screen to make the call.
flutter_phone_direct_callerpackage is not the best package but we will learn how to implement direct phone calls directly from our phone without the intermediate dialer.
Install the following dependencies inside your pubspec.yaml file:
dependencies: flutter: sdk: flutter cupertino_icons: ^latest version flutter_phone_direct_caller: ^latest version url_launcher: ^latest version
Making Phone Calls using the flutter_phone_direct_caller:plugin
To implement the phone call using this plugin is really very easy. This package provides us FlutterPhoneDirectCaller class that provides us callNumber()method that takes a phone number.
This package provides us launch(URL) method that takes an URL with schema. Scheme is very essential as it directs the URL. In the case of phone calls, we use ‘tel:’ schema.
Here we have made a simple method that takes a String phoneNumber, this method will check whether the URL is correct or not if yes then the launch method will launch it else it will throw an error.
Pass this method inside the onPressed property of the above RaisedButton
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!.
Today mobile users expect their apps should have a beautiful UI design, smooth animations, and great performance. To achieve this developer needs to create a new feature without compromising on quality and performance. That’s why Google build Flutter.
In this article, I’ll explain how to use the IgnorePointer widget in Flutter
Flutter is Google’s open-source UI toolkit for building beautiful, natively compiled applications for mobile, web, anddesktopfrom a single codebase.
Widgets
Widget is a way to declare UI in a flutter. Flutter provides several widgets that help you build apps that follow Material Design that takes inspiration from React. The central idea is that you build your UI out of widgets. Widgets describe what their view should look like given their current configuration and state.
IgnorePoiner
IgnorePointer is a built-in widget that prevents their children’s widget from pointer-events like tapping, dragging, scrolling, and hover. This widget ignores the pointer-events without terminating them.
Constructor: Creates a widget that is invisible to hit testing.
Properties
ignoring -> takes bool value and decides whether to ignore pointer event or not
ignoringSemantics -> Whether the semantics of this widget is ignored when compiling the semantics tree
Code Implementation
Let’s move on the coding part
This widget is used to prevent unnecessary touch of UI. It is very simple just wrap your widget inside the IgnorePointer widget.
First, we create a widget and wrap it into the IgnorePointer widget.
In this snippet, we are using a button that is wrapped with the IgnorePointer widget. When ignoring is true RaisedButton can’t perform any action. So, IgnorePointer ignoring all the pointer-events. The code is shown below.
// set up the button Widget okButton = FlatButton( child: Text("OK"), onPressed: () { Navigator.pop(context); }, );
// set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("Message"), content: Text("Button is pressed."), actions: [ okButton, ], );
// show the dialog showDialog( context: context, builder: (BuildContext context) { return alert; }, ); }}
Conclusion
In this article, I have explained the IgnorePointer widget demo, which you can modify and experiment with according to your own. This little introduction was about to prevent user touch of UI.
I hope this blog will provide you with sufficient information in trying up IgnorePointer Widgets in your flutter projects. We will show to prevent the UI from user interaction, some properties using in “ignoring”, and make a demo program for working IgnoringPointer in your flutter applications. 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.
In this blog, We are going to discuss about the TabBar. How the TabBar works. And why we use Tabbar. and we will discuss how to display a horizontal row of tabs and display a widget that corresponds to the currently selected tab. We will explain all these in a demo. 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 ”
TabBar:
The TabBar is used mainly to navigate different screens in one screen. This is what you need first to build the TabBarController. There are two ways to do this. By using the DefaultTabbarController or by creating a TabController.
We mainly need 3 components to create this TabBar.
Create a TabController.
Create the tabs.
TabBarView.
TabController: The TabController is used to control the movement between created tabs.
TabController(length: list.length, vsync: this);
Create Tabs: We need a scaffold to create a TabBar. It should have a bottom attribute. Tabs are a list of forms. This means that it is necessary to have as many tabs as you are making.
TabView: When we press any TabBar using the TabView, we see a new page.
For Example, We can see the WhatsApp App as if we click any tab, then a different page appears on the different tabs.
Demo Module:
Code Implementation:
There are two buttons in this screen, which on clicking will navigate us to the result of the tabbar on the screen.
DefaultTabBarController:
In this screen, we have used the DefaultTabBarController for TabBar. The TabBar DefaultTabBarController is an inherited widget. It is used to share a TabController with a TabBar or TabBarView.If you are using the stateless widget. The best approach is to use DefaultTabController.And in TabBar we have used 3 different icons. On Tap its icon, we have shown different view in TabbarView.
Let us understand this with the help of a reference.
DefaultTabController( length: 3, child: new Scaffold( appBar: new AppBar( title: new Text("TabBar Widget"), bottom: new TabBar( tabs: <Widget>[ Tab(icon: Icon(Icons.cake)), Tab(icon: Icon(Icons.android)), Tab(icon: Icon(Icons.phone_android)), ], ), ), body: new TabBarView( children: <Widget>[ Container( color: Colors.deepOrangeAccent, child: new Center( child: new Text( "Cake", style: textStyle(), ), ), ), ], ), ), )
The DefaultTabController results can be seen in the image.
Custom TabController:
In this screen, a custom TabController is used in the TabBar. For This stateful widget is used.
Let us understand this with the help of a reference.
First of all create a Stateful Widget.which should be SingleTickerProviderStateMixin.
In this article, I have explained a TabBar widget demo, which you can modify and experiment with according to your own, this little introduction was from the TabBar widget from our side.
I hope this blog helps will provide you with sufficient information in Trying up the TabBar List widgetin your flutter project. In this demo explain the TaBar widget in flutter. 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 from FlutterDevs.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.
Hello and welcome to my new blog on Passcode authentication. In this blog, we shall learn and explore how we can implement a simple local authentication using a passcode. This type of authentication is much secure and private also it is extremely fast. Another user how doesn’t know your passcode can’t access your app content directly. This type of authentication removes the server-side errors and provides clean checkout to access the app.
Please give it a try by yourself and try to find out how we can implement this type of functionality with ease. Hopefully, we will require some pub packages as well so please try to find out by yourself which package might help to implement this functionality.
Demo Module:
So what your thought on this? please share your approach on this functionality. Now here is mine, so let’s go……
We will use the provider package for state management.
shared_preferencespackage us various methods to store our data inside our app locally and safely.
get_ithelp us to register our services in a very simple and easy way.
State management technique used in this module
Before getting into the functionality part let’s first learn the state management structure of the app.
We have created a file baseModel.dart that contains a BaseModel class that extends ChangeNotifier . In this file, we will write all the common methods that we will use throughout our app such as implementing circular progress indicator when and method is awaited.
For each screen, we will create a separate file that will contain all the code that will handle all the methods that will provide the data for that particular screen from the internet server or local server. Each file will extends BaseModel in general ChangeNotifier.
We will create a separate widget that we will use to access the provider methods or class.BaseView can only be used for the model class that extends BaseModel.
Please go through the bellow blogs for a better understanding of this state management technique.
Create a baseModel.dart file that extends ChangeNotifier.
import 'package:flutter/material.dart';
class BaseModel extends ChangeNotifier {}
Create a sharedPrefs.dart file that will contain the passCode uploading and fetching code from the local store and this model will be used for the passcode check out screen.
sharedPreferencesis an object of SharedPreferencesthat will provide us access to all the methods. This method takes a passCodeValue int that will be stored under the ‘passCode'key.
getPassCode() async { SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); int code = sharedPreferences.getInt('passCode'); //fetch the passCode value print("**************" + code.toString()); _passCode = code; notifyListeners(); //informs the passCode getter that the value has been changed and it will update the ui wherever it is used. } }
class BaseView<T extends BaseModel> extends StatefulWidget { final Widget Function(BuildContext context, T model, Widget child) builder; final Function(T) onModelReady;
This page is our main page that will contain a simple TextField that will take the passCode from the user and verify it with the fetched Passcode, if both the values are the same then we will navigate it to the HomePage .
Here we will require the sharedPrefs fetch and upload methods that we have created in sharedPrefs.dart file.
To use SharedPrefsclass we need to use the BaseView class. BaseView class provides us builder, onModelReadyproperty to build the builder of the Consumer and onModelReadywill be used to initialize the methods or values inside the initStatemethod.
Data Flow of this file:
When this Widget is called inside the init state model.setPassCode(1234), model.getPassCode()will be called so that the passCode getter in the sharedPrefs.dartcan get the value of the passcode. BaseView provides us onModelReady method to initialize the methods inside the initState() method.
Now we can use use the value of the passCode getter inside our builder.
We have created a TextField that will take the value of passCode form the user and when the user will click on the right arrow button then the onPressed property of icon will check the condition if it is true then the user will be navigated to the HomePage.
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 order to maintain app performance, we make every possible effort but any app’s performance relies on two main things which are time and space. The space-related issue is explained in my previousblogwhere I have explained how to reduce app size and make your app performant.
Rendering is the key factor that provides smoothness to the app and it depends on the fps.
You must be thinking about how no of frames per second can help in the app performance and you must have heard a lot about 60 fps and 16 milliseconds barries. So for information Human mind reacts according to the visual signals sent by the eyes and there is no concept of frames in this regard but the concept of motion has its own effect in this regard. By displaying images at a faster speed you can trick the mind into perceiving motion and here the concept of fps(Frames per second)comes into the effect. It means a concept of motion is a kind of hack of mind.
It needs a minimum of 10–12 frames per second when the human mind starts perceiving motion but it does not look smooth, 24 frames per second allow the human eye to see fluid motion but in movies and videos it takes at least 60 frames per second where a human mind easily feels a smooth motion with fluency.
So the formula would look like
1000ms / 60 frames = 16.666 ms/frame
It means you need to replace every frame in 16.66 milliseconds to do your work computing, input, network, and rendering if you are not able to do this you need to find out where your app lacks and where it needs improvement.
Identifying Performance
In order to identify the performance issue, you just need to open tools here you can identify the no of times the widget is rebuilding and where you need to correct or need to make some changes to your code.
Improve Rendering performance
If the performance is the issue rendering is the factor that comes first in the list we need to deal with, but flutter’s Skia engine takes care of it. Generally, if we are dealing with performance issues there are some common pitfalls
Rebuilding more of the UI in every frame
So try not to write code for the whole screen in a single Stateful Widget that may cause unnecessary UI building, you need to split code into smaller widgets and smaller build functions.
Building a large list of children directly and operating things up higher in the tree using setState().
So setState() affects apps rendering performance more than anything so instead of calling high up on the tree try to call it on the specific part of the subtree.
How to Improve Performance?
In order to improve build performance, there are some steps which we need to improve and some of them are
Controlling build()
Repetitive code and heavy work should be avoided in the build() method so the build() method can be invoked frequently when widgets are rebuilt.
Apply Effects when needed
Applying effects are always expensive because it causes or responsible to create saveLayer() behind the scenes.
Why is savelayer expensive?
Calling saveLayer() allocates an offscreen buffer. Drawing content into the offscreen buffer might trigger render target switches that are particularly slow in older GPUs.
Some rules need to be followed
Use the Opacity widget if it is necessary if you using it for a single image there are various options to doing so because For example, Container(color: Color.fromRGBO(255, 0, 0, 0.5)) is much faster than Opacity(opacity: 0.5, child: Container(color: Colors.red)).
Directly drawing an Image or Color with opacity is faster than using Opacity on top of them because Opacity could apply the opacity to a group of widgets and therefore a costly offscreen buffer will be used. Drawing content into the offscreen buffer may also trigger render target switches and such switching is particularly slow in older GPUs.
Clipping doesn’t call saveLayer() (unless explicitly requested with Clip.antiAliasWithSaveLayer) so these operations aren’t as expensive as Opacity, but clipping is still costly, so use with caution. By default, clipping is disabled (Clip.none), so you must explicitly enable it when needed.
Some widgets are costly because they call saveLayer() and are potentially costly
Shader Mask
color filter
chip
text
There are also some other widgets you may call instead such as to provide fading in an image we can call FadeInImage because it applies gradual opacity using GPU’S fragment shader. In order to provide a rounded corner, we should prefer a border-radius instead of clipping.
Rendering Grids and Lists lazily can help to build up the potion which is going to be seen firstly.
Manage Shader Compilation Jank
If any animation seems janky during the first run but after it works fine maybe this is an issue of shader compilation jank.
More deeply and technically, Shader is a set of code that runs on a GPU( Graphics processing unit). A smooth frame needs to be drawn within 16 milliseconds for a 60 fps display but during the compiling shader takes more time than it should take. it could be nearly a few hundred milliseconds and it causes tens of frames to be missed and drops the fps from 60 to 6.
How to sort it out?
As a Solution for this after the release of Flutter 1.20, Flutter provides command-line tools for developers and by this developers can collect shaders that might be needed for the end-users in the Skia Shader Language format. Once SkSL shader will be packaged into the app then it will automatically be pre-compiled when the end-user opens the app.
There are few commands to perform the action
Run the app with --cache-sksl turned on to capture shaders in SkSL:
flutter run --profile --cache-sksl
If the same app has been previously run without --cache-sksl, then the --purge-persistent-cache the flag may be needed:
flutter run --profile --cache-sksl --purge-persistent-cache
This flag removes older non-SkSL shader caches that could interfere with SkSL shader capturing. It also purges the SkSL shaders so use it only on the first --cache-sksl run.
Build the app with SkSL warm-up using the following, as appropriate:
These are some techniques to improve rendering performance that may help to make the app performant. Sometimes animations, growing list, some widgets (generally call saveLayer()) make an app janky and more rendering so in order to maintain these things we must make focus on the points mentioned above.
Thanks for reading this article if you find anything that could be improved please let me know, I would love to improve.💙
If this article has helped you a bit and found interesting please clap!👏
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!.