The error “Closure: ()=> Map from Function ‘toJson’” usually occurs when there is an issue with converting a class instance to a JSON object. Here are methods to solve this issue Step-by-Step Guide: Avoid Using Closures in toJson: Ensure no closures are being returned by the toJson method. It should directly return a map. Check…
Category: Dart
Fixing setState() Error During Build in Flutter: Using addPostFrameCallback for Safe State Updates
The addPostFrameCallback method solves the problem because it schedules the callback to be executed after the current frame has been rendered. Here’s a detailed explanation of why this approach works: Understanding the Error The error message Unhandled Exception: setState() or markNeedsBuild() called during build indicates that setState() was called during the widget’s build phase. This…
Dart Ternary Operator with Flutter
Here we will see dart ternary operator along with flutter usage. Dart ternary operator looks like below ?: Now this may look like confusing. There are two parts of it. The first part is ? and the other part is : and they are used separately. Next thing we need to know that, we use…
Dart time formatter and current time difference
Let’s take look look at the code. The below code helps to convert time to human readable time with correct format. It helps to convert time from Firebase to human readable time format. It can auto detect if we need to show the time in seconds, minutes or hours. Here you may also DateTime to…
What is call() function in Dart?
It’s very innate in Dart’s core how the call() function works. It’s very interesting. You may create a class and this class may have a function name call(). If there’s a function name call(), then you may call it from the object. Yes by using object or instance of this class. If you create an…
Flutter Google Map PlaceMark | Geocoding
Placemark is a class that contains information like place’s name, locality, postalCode, country and other properties. You should be using this once you get String address from google map api. You may pass your string address to Placemark() class. The above code should be put inside a controller and the snippet tells you how to use…
Flutter Responsive Helper Class
Let’s learn how to create a responsive helper class, in flutter dart. Here we will focus on how to detect Mobile, Desktop or Tablet. In this class, we will create some basic functions and these functions should have access to a context. And based on the context we will if we are on Mobile, Desktop…
Flutter Custom Date Converter
Learn about creating a date converter class in flutter. You may use this convert string to date and to different format. It supports below features formatDate dateToDateAndTime dateTimeStringToDateTime dateTimeStringToDate estimatedDate convertStringToDatetime isoStringToLocalDate isoStringToDateTimeString stringToLocalDateOnly localDateToIsoString convertStringToDatetime
Flutter format time to minute and seconds
Let’s how to format a bigger amount of seconds to minutes and seconds. The above function takes any kinds of seconds and converts it minutes and seconds( if more seconds are left over) It also checks for if we want to return just minutes or seconds.
Dart Map inside Map | Flutter
Here we will learn how to use map inside map or created nested map in dart flutter. Map itself could be a little confusing for beginners in Dart. So map inside map is complex at first sight. But it’s actually easy. First take a look at a Map object. What’s the format or syntax of…