How to

graphQL flutter

How To Use GraphQL Flutter: User’s Guide

Have you ever used a translator while you are on a foreign trip, and you want to make your communication with foreigners manageable and more comprehensible? This is what GraphQl Flutter does in the virtual world. It is a translator that assists the communication between the server and the application.  Both Flutter and graphQL work hand in hand to build data-intensive applications with much ease. In combination, Flutter GraphQL provides a personalized experience to create versatile apps with multiple decorative features.  Let’s begin with the intro of GraphQL Flutter in a bit of detail. Don’t worry; we won’t lose your interest.  What is GraphQL? GraphQL is a product of Meta that made its first public appearance in 2015 and has been revolutionizing how data is served from the backend. It is a query language that enables you to structure your data in whatever state you want.  Applications made with GraphQL Flutter are easier to handle since it enables the applications to control the data instead of the server. It allows your app to ask the server for precisely what it wants and nothing more. This makes data loading more efficient. With GraphQL, you can get multiple resources with a single request. With GraphQL queries, you can access the properties between multiple resources by following references. Setting Up Your GraphQL Endpoint  To use GraphQL Flutter, the first step is setting up the endpoints. To do this, you have to follow the following steps:  The first step is to identify what is the source of your data. Check whether it is coming from a database or any other storage system.  The next step is creating a schema, a data blueprint. The data schema determines the structure and link between the component of the data and its related queries.  The next and relevant step is the setting up of the GraphQL server. This server is an intermediary to translate the graphQL request and data instructions.  Now define resolvers. Resolvers are functions that tell the server how to fetch the data identified in the schema. Next, plugin the server with a data source to initiate data fetching.  Finally, you can start testing your endpoint once everything is set up. You can send query requests to your GraphQL server and check if you receive the expected data back. Implementing graphql_flutter Install GraphQL Package: The first and prime step to use the graphql_flutter package in the Flutter app is to add the graphql_flutter to your project. You can mention the graphql_flutter package and its version in the ‘pubspec.yaml’ file. Then run the ‘flutter pub get’ command at the terminal to download the graphql_flutter package. dependencies: graphql_flutter: ^5.1.2 Creating a GraphQL client: The next step is setting up the GraphQL client. This client tackles all the GraphQL queries and mutations sent to the server.  Defining queries and mutation: Defining the queries (to fetch data) and mutations (to change data) per your data’s requirement is essential.  GraphQL Mutation and Queries  Queries  Like a GET request in REST, “Queries” are used to fetch or read data from the server. When you specify the data you require to the server, it only returns that information—nothing else. For example, if you have a music app, you could use a query to get information about a song’s name and artist. Mutations  When you want to alter data on your server, such as by creating, updating, or deleting data, you use “mutations.” You can think of POST, PUT, or DELETE requests in REST as equivalents. The server hears exactly what you want it to do, just like with queries, and executes your request. The server processes GraphQL queries and mutations, which are strings. This string specifies what data to fetch or change. CRUD Operations with GraphQL Flutter  In GraphQL Flutter, CRUD operations use queries and mutations. GraphQL facilitates CRUD operations by utilizing various tools to send the queries and mutations to the GraphQL server.  Create: You would add or create new data with a mutation. This instructs the server to create a new entry in the database using the details you provide. static const String _insertTodo = ”’ mutation(\$title: String!, \$completed: Boolean!) { createTodo(input: { title: \$title, completed: \$completed }) { id title completed } } ”’; Future<TodosModel> addTodo({required TodosModel todosModel}) async { final result = await _client.mutate( MutationOptions( document: gql(_insertTodo), variables: todosModel.toJson(), ), ); if (result.hasException) { if (result.exception!.graphqlErrors.isEmpty) { throw ‘Internet Connection Issue’; } else { throw result.exception!.graphqlErrors.first.message.toString(); } } return TodosModel.fromJson(result.data?[‘createTodo’] ?? {}); } Read: GraphQL uses Query to read the data.Queries allow you to specify the fields and relationships you are interested in, and the server responds with the requested data in the exact shape defined in the query. static const String _getTodos = ”’ query { todos { data { id title completed } } }”’; Future<List<TodosModel>> getTodos() async { final response = await _client.query( QueryOptions(document: gql(_getTodos)), ); return response.data![‘todos’][‘data’] .map<TodosModel>((e) => TodosModel.fromJson(e)) .toList(); } Update: You use a mutation to alter or update data. The server receives instructions regarding the data you wish to modify and the new values that should be used.  static const String _updateTodo = ”’ mutation(\$id: ID!, \$title: String!, \$completed: Boolean!) { updateTodo(id: \$id, input: { title: \$title, completed: \$completed }) { id title completed } } ”’; Future<TodosModel> updateTodo({required TodosModel todosModel}) async { final result = await _client.mutate( MutationOptions( document: gql(_updateTodo), variables: todosModel.toJson(), ), ); if (result.hasException) { if (result.exception!.graphqlErrors.isEmpty) { throw ‘Internet Connection Issue’; } else { throw result.exception!.graphqlErrors.first.message.toString(); } } return TodosModel.fromJson(result.data?[‘updateTodo’] ?? {}); } Delete: A mutation can also be used to remove information. If you want to remove some information from the server, specify it.static const String _deleteTodo = ”’ mutation (\$id: ID!) { deleteTodo(id: \$id) } ”’; Future<bool> deleteTodo({required String id}) async { final result = await _client.mutate( MutationOptions( document: gql(_deleteTodo), variables: {‘id’: id}, ), ); if (result.hasException) { if (result.exception!.graphqlErrors.isEmpty) { throw ‘Internet Connection Issue’; } else { throw result.exception!.graphqlErrors.first.message.toString(); } } return result.data?[‘deleteTodo’] ?? false; } GraphQL Flutter Subscription  A subscription in GraphQL allows

Read More »

How to Remove IconButton Padding in Flutter?

Several widgets in Flutter make the app’s UI more interactive. The IconButton widget is one of the popular widgets in Flutter that allows you to display an icon that reacts to touch events. At times, the padding between the IconButton widgets appears to be disturbed or irregular. In this blog, we are going to discuss how to remove IconButton padding in Flutter in an easy way.  Several elements, icons, or objects form an app’s UI and can undergo any issue. This issue could be due to its position, size, responsiveness, or anything else. That is something a developer lives with. After going through this guide, removing the IconButton padding isn’t going to be a big deal for you. But first, let’s get to know what IconButton widgets are and why we need them in our app. What is an IconButton Widget? IconButton is a widget in the Flutter framework that represents an action as an icon. It commonly provides a touch-responsive icon in your app that triggers a specific action when tapped. Simply put, you can display actions in your app as icons that respond to touch events using Flutter’s IconButtons. For example, you might use an IconButton for a “like” or “favorite” feature in a social media app or a “play” or “pause” button in a music app. These are the icon buttons in terms of development or coding. The IconButton widget is useful in creating an intuitive and user-friendly interface, as it can quickly convey the meaning without taking up much space. They are also easy to implement and customize, making them a popular choice for many developers. Now let’s see what padding has to do with the IconButton in Flutter. Flutter IconButton Padding You must have seen a space that surrounds an icon or the space between more than one icon. That is the padding. Flutter IconButton padding refers to the empty space surrounding an IconButton widget. By default, an IconButton in Flutter has a padding value of 8.0 logical pixels, which means there will be some empty space around the icon. This padding helps to provide a touch target for the user and can improve accessibility and navigation as well. However, sometimes this padding may not be desired, as it can cause issues with the appearance of the user interface, especially if you want your icons to be tightly packed together. In such cases, you can remove the padding by wrapping the IconButton in a Container widget and setting its padding value to zero. Let us step into removing the IconButton padding with useful code examples. How to Remove IconButton Padding in Flutter? By default, the IconButton comes with a padding of 8.0 logical pixels. This means there will be some space around the icon. While this may not seem like a big deal, it can sometimes cause issues with the look and feel of your app.  Let us see an example of it. Output As you can see, both the icon buttons (+, -) are covering up some extra space around the quantity counter. This is because of the default padding of the IconButton widget. And we need to reduce these spaces between the icon buttons to make it look better. That’s why you may need to remove the IconButton padding. By doing so, you can create a cleaner and more attractive user interface that ultimately enhances user experience.  How do you remove the IconButton padding? It’s simple. Let’s do this real quick.  To remove IconButton padding, we just set its padding to zero and adjust the value of constraints.  Here is the code for it. Output As you can see, the padding around IconButton has been removed and there is no extra space around the icon buttons. A cluttered or poorly organized interface can be distracting to users, so removing the padding can help ensure a clean and organized app look. Conclusion This was it for the solution to removing IconButton padding in Flutter. We hope that you find this article helpful. Moreover, we continue to bring such valuable information to the table.    With these few lines of code, you can successfully remove the IconButton padding and improve the overall appearance of your Flutter app. Don’t let padding issues hold you back. Try removing IconButton padding today! Lastly, if you still face any issues while fixing any errors in flutter app development, feel free to reach out to us. Our team of highly skilled flutter developers would be happy to be of help. You can hire flutter developers to turn your complex business ideas into real-world apps.

Read More »

How to Fix setState isn’t Defined Error in Flutter?

Flutter developers come across multiple errors while building any app or adding any particular feature. One of the key features of Flutter is its ability to handle state management, which allows developers to easily update and render UI components based on changes in the app’s data. However, sometimes developers may encounter an error message stating that “setState is not defined” when trying to use this feature. So how to fix the setState isn’t defined error in Flutter? 😕 In this blog post, we will be fixing this common error that developers may encounter while working with the Flutter framework, the “setState is not defined” error. We will discuss what causes this error, and provide you with the best possible solutions to fix it. First, let’s talk about what setState Flutter is and why it’s important for state management in Flutter. What is setState in Flutter? The flutter setState method is a built-in function in Flutter that allows developers to update the state of a specific widget and cause a re-render of the UI. This is important for state management in Flutter because it allows the developer to easily update and render UI components based on changes in the app’s data. Now let’s get to know why the error Flutter setState is not defined occurs. Why does the error ‘Flutter setState isn’t defined’ occur? This error can occur when the developer is trying to use setState within a stateless widget, which is not possible as setState can only be used within stateful widgets. Didn’t get it? Let us explain this further. The “setState is not defined” error occurs when the developer is trying to use the setState method, but it is not being imported or properly utilized within the app’s code. The setState method is a built-in function in Flutter that allows developers to update the state of a specific widget and cause a re-render of the UI. In order to use setState, it must be imported from the ‘flutter’ package and the stateful widget must be extended. How do you fix the error ‘Flutter setState isn’t defined? The setState method can only be used in stateful widgets, which are widgets that can change over time. So, if you have a widget that changes its state, you can call setState as it recalls the build method. While if you don’t have the widget that changes its state, you will face the error ‘Flutter setState isn’t defined. So make sure that the widget you are trying to update using setState is extending the StatefulWidget class. Let us give you an example of it. As you can see, the setState has been called and it’s showing the error. Let’s use the stateful widget and see if it still says hi or not. 😛 You can see in the screenshot below that the error is gone 😉 This is how you fix Flutter setState isn’t defined error.

Read More »

A Quick Guide to Remove Debug Banner in Flutter

While building any app, Flutter shows a debug banner on the top right corner of the screen. This is to indicate that the app is in debug mode and it’s not fully developed yet. Any changes are can be expected at the moment and the whole app might get revamped as well. Interestingly, it won’t need more than 2 minutes for you to remove the debug banner from any Flutter app. In the previous blog, we discovered how to change package name in Flutter. Today, we will be figuring out the only reliable way to remove debug banner in Flutter.  The debug banner may or may not bother you, but we thought why not find out how to remove it in Flutter? So, without belating, let’s jump right into it. 😉 How to Remove Debug Banner in Flutter?  To remove debug banner in Flutter, simply need to use MaterialApp() widget and call the ‘debugShowCheckedModeBanner’ and set this property to false. This will disable the debug banner to display on the screen.  Here is an example of removing debug banner in Flutter. As you can see in the screenshot below, there is the debug banner is displayed on the app screen. Now, let’s remove it. Here is the code. Output: That’s it. As you can see, there is no banner in the app anymore. This is the only way you can remove debug banner in Flutter. What Does the Debug Banner do? A debug banner in Flutter is a visual indicator that displays information about the current build configuration of the app. This information can include the current build mode (debug or release), the Flutter version, and the device information. The purpose of the debug banner is to provide developers with a quick and easy way to identify the build configuration of the app while they are testing and debugging. This can be especially helpful for identifying problems that may only occur in a specific build mode or on a specific device. Conclusion This was it for the quick guide to removing debug banner in Flutter. We hope you got to learn a new thing today. We, at FlutterDesk, keep sharing such valuable information related to Flutter app development. Feel free to reach out to us with any questions or suggestions that you may have. Or you can hire flutter developers to take on your app development and help your business build a substantial product. Thank you for standing by! See you in the next blog. 😉

Read More »

How to Convert int to Double in Flutter?

In Flutter, while coding in Dart, you might need to convert an int (integer) to double. There are two ways to do it. One is by using the toDouble method and the other is by adding double (0.0) to the int. In this blog, we will discuss both of these methods and learn how to convert int to double in Flutter with code examples. Interestingly, Dart itself recommends using int or double instead of num. This is because if we use ‘num’, we will have to assign the values each and every time. Whereas, if we use int or double, We can just make all variables dynamic and get rid of all strong typing annoyances in one strike. This is what made it necessary for us to come up with this guide. Without further ado, let’s jump right into it. 😉 As we stated earlier, there are only two ways in which we can convert int to double in flutter. Let’s get to know how you do it. Using the toDouble Method  The toDouble method is a built-in function that can be used to convert an int to a double. It is a simple and straightforward method that can be used to convert integers to doubles in a single line of code. Here is an example of how to use the toDouble method: Output Adding double (0.0) to int Another way to convert an int to a double is by adding double (0.0) to the int. This method is also simple and you can easily do it in one line of code. Here is an example of how to convert an int to a double by adding double (0.0) to the int: Output Both of these methods will give you the same result, but the toDouble method is more explicit and can be more readable. Related Post – Flutter StreamBuilder Conclusion As you just explored, converting an int to a double in Flutter can be done using either the toDouble method or by adding double (0.0) to the int. Both methods are simple and straightforward and give the same result. It is up to the developer to choose the method that best suits their needs and style. If you’re looking to develop a Flutter app and need help, consider hiring Flutter developers. Furthermore, if you still have any questions or suggestions, feel free to comment below. We, at FlutterDesk, strive to provide a plethora of information and tutorials related to Flutter app development. Your feedback is much appreciated and it motivates us to bring more resources for you to the table. Thank you for standing by. See you in the next blog 😉

Read More »

How to Change Package Name in Flutter? Step-by-step Guide

Changing the package name of a Flutter app can be a bit of a tedious process, but it’s necessary if you need to publish your app under a different name or if you’ve accidentally set the wrong package name in the beginning. In this blog post, we will go over the steps required to change the package name of a Flutter app for both Android and iOS, with code examples. Let’s first get to know what packages in Flutter are. What are Packages in Flutter? In Flutter, a package is a collection of reusable code that is bundled together and can be easily shared and integrated into other Flutter projects. Packages can include Dart code, assets, and resources, and can be used to add functionality to a Flutter app, such as adding new widgets, integrating with external APIs, or providing support for specific platforms. Packages can be easily added to a Flutter project using the pub package manager and can be found in the official Dart package repository or on GitHub Copilot. Interestingly, developers from all across the world actively contribute to flutter by identifying pitfalls and suggesting improvements to it. This is one of the reasons which make flutter a reliable platform for cross-platform app development. Now, let’s move toward changing the package name in Flutter. How to Change Package Name in Flutter? Here are the quick steps which you can perform to change the package name in the Flutter app. Let’s go! 😉 Step 1: Updating the package name in the pubspec.yaml file The first step in changing the package name of a Flutter app is to update the package name in the pubspec.yaml file. You can find this at the root of your project and it contains the metadata for your app. To update the package name, simply change the value of the name field to the new package name. Here is the code:   Step 2: Updating the package name in the Android build.gradle file For Android, the next step is to update the package name in the build.gradle file. This file is located in the android/app directory of your project. Look for the applicationId field and update it with the new package name. Run the command: Step 3: Updating the package name in the iOS Info.plist file For iOS, the next step is to update the package name in the Info.plist file. This file is located in the ios/Runner directory of your project. Here, look for the CFBundleIdentifier key and update its value with the new package name. Use the following code to do this: Step 4: Updating the package name in the Dart code The final step is to update the package name in the Dart code of your app. This can be done by doing a global search and replace of the old package name with the new package name in all the Dart files of your app. Step 5: Updating the package name in the AndroidManifest.xml file Another step for Android is to update the package name in the AndroidManifest.xml file. This file is located in the android/app/src/main directory of your project. Look for the package attribute and update it with the new package name. Here is the code: Step 6: Updating the package name in the AppDelegate.m file For iOS, the next step is to update the package name in the AppDelegate.m file. This file is located in the ios/Runner directory of your project. Look for the NSBundle and update its value with the new package name. You can use the following command: Key Takeaways: Once you have completed all of the above steps, you should have successfully changed the package name of your Flutter app for both Android and iOS. We would recommend you test your app on both platforms to ensure everything is working correctly. It’s worth noting that this process is a bit error-prone, so be sure to double-check all the files you’ve changed, and test your app thoroughly after making the changes to ensure that everything is working as expected. It’s also recommended to use some tools like flutter_launch_checks to verify the package name across the app and the files. Changing the package name will cause some issues with the app like it will lose the installed data and previous user’s data. So we recommended you inform the users about the change and ask them to log in again if necessary. Conclusion: This was it for the quick guide to changing the package name in Flutter. After reading this quick guide to changing package name in Flutter, it should be quite easier for you. As always, be sure to thoroughly test your app after making any changes to ensure that everything is working as expected. If you have any questions or run into any issues, feel free to reach out for help. Our team of skilled flutter developers will love to be of help. See you in the next blog. 😉

Read More »

A Quick Guide to Set Flutter Drawer Header Height

You must have seen the slider-like menu that comes out from the left side of the screen (mostly) as you tap on the AppBar icon. We call it Drawer and it has a couple of actionable buttons that you can access and navigate to their page directly. In Flutter, a drawerheader is the same menu that appears when we type the three lines button that appears on the top left side of the Gmail app and has the buttons like “All inboxes, primary, social, promotions”, etc. In this blog, we will discover how to change flutter drawerheader height in an easy way. We will be giving you a demo of this and providing the output screenshot with a sample code as well. Sounds exciting? 😛  Let’s jump right into it. 😉 How to add Drawer Header in Flutter? To add a drawer header in Flutter, you can simply use DrawerHeader class and assign any color using the ‘color’ property in the ‘BoxDecoration’ class. Let’s do this by giving you an example. Code   Output Now, let’s move toward knowing how to change drawer header height in Flutter.  How to change drawer header height in Flutter?  If you want to change drawer header height, you will need to wrap the DrawerHeader class inside the SizedBox widget. This is because DrawerHeader class doesn’t have any property that could handle drawerheader height.  So we use the SizedBox widget to change drawer header height because it has properties of ‘height’ and ‘width’. You can specify Flutter drawer header height as much as you can. Just change the value of the ‘height’ class and you’ll notice the change in DrawerHeader height.  Let’s do it ourselves. 😍 Code Output As you can see, we have used the SizedBox widget to wrap the DrawerHeader class. It will allow you to change the DrawerHeader height according to your needs. In this way, we can specify any height for the DrawerHeader using the height property. Moreover, you can change the drawer header color as well. Simply choose any color from the colors property of BoxDecoration and that’s it. Conclusion The DrawerHeader height in flutter can be set using the height property as it’s an important aspect of customization for the flutter drawerheader. It also helps in providing an optimal user experience. Drawer Header height can be adjusted according to the requirement, which will help in providing a better view of the Drawerheader contents. That was it for this quick guide to adding Drawer Header and changing its height. We hope you may find this article helpful for you.  If you’re looking for a Flutter app development company to hire Flutter developers then you can count on us for that. We have a team of highly qualified Flutter developers who can turn any of your complex business ideas into real-world applications.  See you in the next blog. Cheers!

Read More »

How to Show Custom Snackbar in Flutter?

Snackbar is a quick piece of information bar that appears briefly at the bottom of the screen. It’s used to display short messages that the user doesn’t necessarily need to interact with, such as “Changes saved successfully.” or “No internet connection.” In Flutter, it’s easy to create a Snackbar using the Scaffold.showSnackBar() method. Using Snackbar in Flutter is a quick and easy way to provide feedback to the user. It’s a great alternative to Toast in Flutter, which is a native Android widget because it allows the user to interact with it by dismissing it or performing an action. Let’s have a sneak peek at Flutter toast vs snack bar. Flutter Toast vs Snackbar Toast and Snackbar are both used to display brief messages to the user, but there are some differences between them. Toast is a native Android widget that appears at the bottom of the screen and disappears after a certain period of time. It’s not interactive and the user cannot dismiss it. On the other hand, Snackbar is a material design element that appears at the bottom of the screen and can be dismissed by the user by swiping it away or tapping on an action button. Snackbar also allows the user to undo an action by tapping on the “Undo” button. How to Show Snackbar in Flutter To show a Snackbar in Flutter, you need to use the Scaffold.showSnackBar() method. The Scaffold is a widget that provides a framework for organizing the visual structure of your app. It’s often used as the top-level container for an app. Here’s an example of how to show a Snackbar in Flutter:   In this example, the Snackbar will appear at the bottom of the screen and display the message “This is a Snackbar“. You can see that here in the screenshot: Output: How to Show Flutter Snackbar on Top Position? There is no such property of snackbar to assign the top position to it as in Toast. So, if you want to show snackbar on the top of your screen, you need to exclude the height, taking the bottom as a reference. As you can see the code here and the result in the screenshot:   Output Flutter Snackbar Without Context There are certain times we don’t have the context to define depending upon certain business logic. In that case, we use scaffoldMessengerKey to show snackbars without needing context with just one GlobalKey. Here is the code. Now, let’s move toward changing snackbar color. How to Change Flutter Snackbar Color You can customize the color of the Snackbar using the backgroundColor property. Here’s an example of how to show a Snackbar with a red background color:   Output: Flutter Snackbar Duration If you’re wondering how long would snackbar stay there then mind that the default snackar duration is set up to 4 seconds. However, you can specify a different duration using the duration property. Here’s an example of how to show a Snackbar that lasts for 8 seconds:   So this will allow you to display the snackbar for 8 seconds. Moreover, you can specify any number of seconds to show the snackbar up to. Flutter Floating Snackbar You can create a floating Snackbar by setting the shape property to RoundedRectangleBorder and the elevation property to 8.0. Here’s an example of how to create a floating Snackbar:   This will create a Snackbar with rounded corners and a shadow. Conclusion In this tutorial, we learned about Snackbar in Flutter and how to use it to display brief messages to the user. We also learned about the differences between Toast and Snackbar, and how to customize the duration, color, and shape of the Snackbar. We hope this tutorial helps you show snackbar and give you ways to customize it fully. Feel free to share your thoughts or queries in the comments below. Or you can hire Flutter developers who would love to assist you to build highly intuitive apps for your business.

Read More »

How to Show Custom Toast Message in Flutter?

You must have seen a quick pop-up-like message that appears on the lower portion of the screen (mostly) and disappears after a couple of seconds. That message is to address the users about the action that they perform at that moment. An example would be displaying “Welcome to the app (your app name)“ when a user successfully logs in to your app.  In this blog, we will be exploring how to show toast in Flutter with a flutter toast package. You can show any custom toast in flutter depending on your need or the client’s requirements. So, after going through this quick guide, you won’t need to look further because we will be discussing in detail with code examples about how to show custom toast in Flutter. While building mobile apps, you should value adding little elements to your apps. They collectively make your app’s UI more interesting and enhance the user experience to much extent. These small additions could be a button, icon, or text field (at certain places), or basically anything that could help users leverage your app’s features more efficiently.  Flutter Toast Package Fluttertoast is a package for the Flutter framework that allows developers to easily display lightweight, transient notification messages in their apps. These messages, also known as “toasts,“ can be used to inform the user of an action they have taken, provide a brief update or message, or simply acknowledge that an action has been completed. Toasts can be displayed as banners at the top or bottom of the screen and can include text, images, or both. They are designed to be unobtrusive and easy to use, making them useful tools for developers building Flutter apps. Related topic: How to Custom Snackbar in Flutter? Let’s begin with learning how to show toast in Flutter. We will be covering everything related to the Flutter toast package including how to show toast in flutter and how to customize the toast messages. How to Show Toast in Flutter? Flutter does not have a widget just for showing toast messages, so we use the flutter toast package. Interestingly, fluttertoast plugin offers you complete customizations same as you can do with the snack bar in Flutter.  Hold on! We are about to dive into exploring what customizations we can do to show toast in Flutter. So, how do you add toast in Flutter? Here are the simple steps to do that. After it, we will be doing customizations to the toast message. First of all, you need to add the dependency in the pubsec.yaml file of your project.  So go to the pubsec.yaml file and paste the following line to add the fluttertoast dependency. Next, you need to import fluttertoast package into the dart file where you want to show toast message in Flutter. Use this code: Now that you have successfully imported flutter toast package, you can easily show toast in Flutter. Here is a Flutter toast message example for you to show toast message using the following code.   Output Replace the ‘msg’ with any random text you want to display as a toast in Flutter.  Now let’s explore how can you show a custom toast in Flutter. Custom Toast in Flutter You might wonder if we can change the toast message that appears on the screen. The answer to this question is yes. You can make show custom toast in Flutter by changing its position, font size, background color, and font color. Seems interesting, right? 😍 Let’s make a custom toast in Flutter. If you want to show toast message somewhere top, left or right side of the screen then you can call gravity property. It allows you to show toast message anywhere within your app.  Let’s see how can we leverage the gravity property in fluttertoast.   Output: As you can see, if we call the ToastGravity.TOP property, the toast message will appear on the top of the screen. Similarly, you can call several other properties to show toast messages differently on the screen. Some other properties of the flutter toast package are: You can use any of these properties to show toast in Flutter accordingly, i.e bottom, center, top left, etc.  Next, we can also change the font size of the toast in Flutter. It’s that simple:   Output And if you want to change the background color of the toast message, here’s how you do it.   Output Similarly, if you want to change the text color of toast message, here’s the way.   Output Conclusion That’s a wrap for now and we hope that you get to have a clear understanding of how to show toast message in Flutter. We have given a flutter toast message example for each of the different uses. You can get an idea of the code and make the changes on your own and build highly interactive Flutter apps. If you want to lighten your load of developing apps or want to hire a flutter developer then you can count on us. We have a team of skilled developers with a proven background in building intuitive and innovative apps for businesses worldwide. You can have a glimpse of our portfolio here. Furthermore, if you have any questions related to Flutter app development, you can put your queries in the comment section. We would love to hear from you.

Read More »

How to Create Custom Cards in Flutter?

Let’s see what we’ve got at the start. Result: What now? Is this it? No, not really. We will need to customize the Flutter card ourselves. For now, this code will just create a default card on your app’s screen as in the screenshot above. Now, let’s customize Flutter cards.  Changing Flutter Card Color We can change the card color using the color property. As you can see in the code below: Result: Flutter Card Rounded Borders To make the card borders round, wrap the card’s child around a Container widget. Specify the rounded rectangle border for the card. And then do the same with the colored border side for the container. Result: As you can see the borders of the card have been rounded. Card Shadow in Flutter To make the card look more prominent, we use the elevation property that adds a shadow behind the card in Flutter. And you need to pass the elevation property for this. See the code: Result: Change Card Shadow Color in Flutter Now if you want to change the shadow color then you need to use shadowColor property. Here is the code: Result: As you can see, the shadow color has been changed to purple. Not a big deal for you now, isn’t it? 😉 Create Custom Card with Image and Buttons in Flutter Here is the final form of the Flutter card with customized shadow, border, and colors as well. Final Form: Here is the final form of the card with the image and button in Flutter. You can use the code and make the changes yourself to practice creating cards in Flutter. Conclusion In this blog, we have briefly discussed and learned about creating custom cards in Flutter. We have also learned how to create a card with an image and button in Flutter. Moreover, changing the Flutter card color and creating a rounded border won’t be an issue for you now.  In the end, we have provided you with the complete code for creating a card in Flutter. Use it and make changes according to your needs and enjoy enriching the user experiences. We continuously share such valuable information about Flutter app development. Just head over to our blog and you’ll find plenty of guides and information related to Flutter app development services. If you still have any questions, please feel free to ask in the comments section. Our team of highly experienced flutter developers would love to assist you in any way possible.  Lastly, if you have a business idea and want to transform it into an app then you can hire flutter developers. We have a team of skilled Flutter developers entitled with open source contributors delivering top-notch tech solutions to businesses worldwide. Feel free to book a free discovery call with a Flutter developer today.

Read More »