Articles by FavTutor
  • AI News
  • Data Structures
  • Web Developement
  • AI Code GeneratorNEW
  • Student Help
  • Main Website
No Result
View All Result
FavTutor
  • AI News
  • Data Structures
  • Web Developement
  • AI Code GeneratorNEW
  • Student Help
  • Main Website
No Result
View All Result
Articles by FavTutor
No Result
View All Result
Home Trending

These New Flutter/Dart Features Make My Life Easier

Hoon Wee by Hoon Wee
May 28, 2024
Reading Time: 7 mins read
Flutter Dart New Features
Follow us on Google News   Subscribe to our newsletter

My favourite cross-platform framework has gone to the next level!

Flutter is a great choice for building cross-platform applications, not only mobile but also web and desktop. You can do the same with Javascript, using React Native, Electron and other frameworks, but the unification of the codebase and the developer experience of Flutter is unbeatable, especially for solo developers like me.

Also the language, Dart, is a great choice for building applications. Some say it’s just a “better Typescript”, and although I partially agree with that, I found myself more productive with Dart than with Typescript.

Despite these advantages, Flutter and Dart are still young compared to other frameworks and languages. But the Flutter team has been working hard to make it better every year.

This year, in 2024, they have introduced some new features that make my developer life even easier. There are many new features (Impeller enhancement, Game dev support, etc), but I want to share my personal favorite 3 features that I found very useful in my projects.

1) Google AI Dart SDK

We’re living in the era of AI! As a solo developer who helps startups build MVPs, I often get requests to build AI-powered features from my clients. But Dart’s AI ecosystem was not as mature as Python or Javascript, so I had to build an ad-hoc solution for each project.

Due to this popular demand, Google has released an AI SDK for Dart in 2024. This SDK makes it super easy to integrate AI features into your Flutter applications, using Google’s Gemini models.

Here’s an example of how you can use it:

First, install the package:

$ flutter pub add google_generative_ai

Then, you can use it in your code. If you have used LangChain before, you’ll find this API very similar:

import 'package:google_generative_ai/google_generative_ai.dart';

final apiKey = Platform.environment['GOOGLE_API_KEY'];

void main() async {
final model = GenerativeModel(model: 'gemini-pro', apiKey: apiKey);
final content = [
Content.text("Explain what's the difference between Dumplings and Gyoza"),
]

final response = await model.generateContent(content);

print(response.text);
}

Not only can you generate text, but you can also generate images, videos, and even code snippets. The possibilities are endless.

Since Google has always made it easy to interoperate with their products – Flutter, Firebase, Google Cloud, etc. – I expect they’ll also make it easy to use the AI SDK with other Google products in the future. I personally think this will broaden the use of AI in the mobile/web development space significantly.

2) Flutter meets WebAssembly

I see many people say “Don’t use Flutter for web development“. If they are talking about “website”, then I agree. In that case, you should use HTML, CSS, and Javascript. But if they are talking about “web applications”, then I strongly recommend using Flutter.

Modern web applications are getting more complex, and Flutter is a great choice for building complex web applications with decent performance. The problem is, when we want even more performance, sometimes the WebJS generated from Flutter isn’t enough.

That’s why I was so excited when I heard that Flutter has added support for WebAssembly in 2024.

WebAssembly is a new standard that allows you to run high-performance code written in languages like C, C++, and Rust in the browser. It’s a great way to speed up your web applications, especially if you have computationally intensive tasks.

Unfortunately, until recent years WebAssembly did not support garbage collection, which made it hard to use with languages like Dart that rely on garbage collection. Hence, to use WebAssembly features in Flutter projects, developers had to compile C, C++, or Rust code to WebAssembly and then call it from Dart using FFI (or use bridge libraries).

Flutter WebAssembly

Recently WebAssembly has added support for garbage collection, and many modern browsers have implemented this new version of WebAssembly. This means now it’s possible to compile Dart code into WebAssembly, which the Flutter build system will do.

According to the Flutter team, Flutter web apps compiled into WebAssembly are 2x faster than the ones compiled into Javascript. This is a huge improvement, and it opens up a lot of possibilities for building high-performance web applications with Flutter, without using system-level languages.

Of course, if you really need the best-of-the-best performance, you should still consider using C, C++, or Rust, but for most web applications, Flutter WebAssembly should be more than enough.

3) Finally, Dart macros! (experimental)

Almost in every Flutter project that communicates with backend API, you have to write codes for JSON serialization/deserialization and data class equality. Since these features are very common, there are dedicated packages like json_serializable, freezed to help you with that.

For example, you can use freezed to generate data classes with equality and serialization/deserialization methods:

@freezed
class User with _$User {
const factory User({
required int age,
required String name,
required String username,
}) = _User;

factory User.fromJson(Map json) => _$UserFromJson(json);
}

Writing only this much code + running build_runner, you can get a lot of features like equality, serialization/deserialization, and more. The problem is that running build_runner every time you make a change in your data class can be annoying. Also, many of the times I don’t need all the generated code, but it’s kinda hassle to build my own code generator.

And of course, I wasn’t the only one who had complained about this. The community has been asking for meta-programming tools better than mere code generations, and finally, they have introduced an experimental “macro” feature. Unlike code generation tools, macros are “static metaprogramming” tools, which means they run at compile-time, not at runtime.

Also, you do not need to run build_runner to generate the code, because macros are fully integrated into the Dart language and executed automatically in the background by Dart tools.

How to use Macros in Dart?

Currently, Macros are experimental, but you can try it out.

The Dart team has implemented the JsonCodable macro in Flutter’s json library, and here’s how you can use it. Make sure you have the Dart version 3.5.0-152 or later.

First, you have to enable it with a flag in your analysis_options.yaml file:

analyzer:
enable-experiment:
- macros

Next, install the package:

$ flutter pub add json

Run the project with the experimental flag:

$ dart run --enable-experiment=macros bin/my_app.dart

Then, you can use it in your code. This example shows how you can use the JsonCodable macro to generate JSON serialization/deserialization code for your data classes:

import 'package:json/json.dart';

@JsonCodable() // Macro annotation.
class User {
final int? age;
final String name;
final String username;
}

void main() {
// Given some arbitrary JSON:
var userJson = {
'age': 5,
'name': 'Roger',
'username': 'roger1337'
};

// Use the generated members:
var user = User.fromJson(userJson);
print(user);
print(user.toJson());
}

How to create your own macros?

You can create your own macros by creating a macro class. Every macro class should implement a specific macro interface. For example, if you want to create a macro that generates class declarations, you should implement the ClassDeclarationsMacro interface:

macro class MyMacro implements ClassDeclarationsMacro {
   const MyMacro();
  
 // ...
}

You can have fun with macros by comparing the original code and the “augmented code”, which is generated code from macros in the background.

Conclusion

I’ve introduced only 3 features that I found very useful in my projects, but there are many more features that Flutter and Dart teams have introduced in 2024. If you’re a game developer, you might be interested in the new “Devtools plugin for Flame”. If you are a savvy developer who really cares about performance, you might be interested in the new “Impeller enhancement”.

Many people used to say “Flutter will meet its end soon, just like many other Google projects”. But I don’t think so. Google has been investing a lot in Flutter, and the ecosystem is getting better every year. And also, Google is already using Flutter in many of their products, like Google Earth. So I can say the Flutter is most likely to stay for a long time.

I’m excited to see what new features Flutter and Dart teams will introduce in 2025. What were your favorite Flutter/Dart features in 2024? And what features do you expect in 2025? Let me know in the comments!

ShareTweetShareSendSend
Hoon Wee

Hoon Wee

I am Hoon Wee, a software engineer from South Korea. I've been working as a full-stack developer for more than 5 years, joining various projects including learning management systems, e-commerce websites, SaaS, etc.

RelatedPosts

GPT-4.5 Examples

People Pushed GPT-4.5 to Its Limits With These 10 Questions

February 28, 2025
15 Essential Skills for Software Engineer

15 Key Skills to Thrive as a Software Engineer in 2025

February 26, 2025
GitHub Copilot Agent Mode

Is the New GitHub Copilot Agent, the Future of Coding?

February 14, 2025
Top Chrome Extensions for Web Developers

15 Must-Have Chrome Extensions for Web Developers in 2025

January 31, 2025
No Code Tools

10 No-Code Tools for Developers in 2025 (with Best Use Cases)

January 24, 2025

About FavTutor

FavTutor is a trusted online tutoring service to connects students with expert tutors to provide guidance on Computer Science subjects like Java, Python, C, C++, SQL, Data Science, Statistics, etc.

Categories

  • AI News, Research & Latest Updates
  • Trending
  • Data Structures
  • Web Developement
  • Data Science

Important Subjects

  • Python Assignment Help
  • C++ Help
  • R Programming Help
  • Java Homework Help
  • Programming Help

Resources

  • About Us
  • Contact Us
  • Editorial Policy
  • Privacy Policy
  • Terms and Conditions

Website listed on Ecomswap. © Copyright 2025 All Rights Reserved.

No Result
View All Result
  • AI News
  • Data Structures
  • Web Developement
  • AI Code Generator
  • Student Help
  • Main Website

Website listed on Ecomswap. © Copyright 2025 All Rights Reserved.