VOOZH about

URL: https://www.geeksforgeeks.org/flutter/flutter-avoiding-jank/

⇱ Flutter - Avoiding Jank - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Flutter - Avoiding Jank

Last Updated : 15 Jul, 2025

Parsing large JSON files can lead to poor performance of apps and shuttering animations. If parsing and computing a large JSON file take more than 16 milliseconds, the users will experience Jank. Dart by default uses a single thread to perform these tasks, though being simple and fast for less expensive computation, it fails when the computation in large.

To avoid these janks, isolates can be used to perform all computations in a different thread in the background. In this article, we will explore the process of parsing JSON in the background.

Steps to implement Avoiding Jank in Flutter

Step 1 : Create a new flutter application

Create a new Flutter application using command Prompt. For creating a new app, write flutter create YOUR_APP_NAME and run this command.

flutter create jank_flutter

To know more about it refer this article: Creating a Simple Application in Flutter

Step 2 : Adding the Dependency

To add the dependency to the pubspec.yaml file, add shimmer as a dependency in the dependencies part of the pubspec.yaml file as shown below:

dependencies:
http: ^1.3.0

Now run the below command in terminal.

flutter pub get

Step 3 : Importing the Dependency

Use the below line of code in the main.dart file, to import the shimmer dependency :

import 'package:http/http.dart' as http;


Step 4 : Requesting Data

We can use the http.get() method to fetch the sample data of 5000 images from JSONPlaceholder REST API as shown below:


Step 5 : Parsing and Converting the Data

We now have 50 photos in JSON form received from the http.response and these need to be parsed and converted into a list of Dart objects. To do show First create a Photo class as shown below.

Here we will create a Photo class that contains the JSON data as shown below:


Now update the getPhoto() function to returns a Future<List<Photo>> through the below steps:

  • Make a Photos_parser() function to convert the response body into a List<Photo>.
  • Use the Photos_parser() function in the getPhotos() function.


Step 6 : Moving work to a different Isolate.

The compute() function can be used to move the work to a separate isolate where it will be parsed and converted in the background. It runs expensive functions in a background isolate and returns the result. 


Complete Source Code

main.dart:

To know more about GridView in flutter refer this article: Flutter – GridView

Output:


Comment
Article Tags:

Explore