DEV Community

Cover image for Getting Started with Flutter Modular: My Journey to a More Organized Codebase
Thinnakrit
Thinnakrit

Posted on

2

Getting Started with Flutter Modular: My Journey to a More Organized Codebase

Introduction

Hey there, Flutter devs! ๐Ÿ‘‹ Ever found yourself drowning in a spaghetti mess of routes and dependencies? Yeah, me too. When my Flutter project started growing, managing navigation and dependencies became a nightmare. Thatโ€™s when I stumbled upon Flutter Modular, and let me tell youโ€”it was a game changer! ๐Ÿš€

In this article, I'll share my experience with Flutter Modular, why I love it, and how you can get started with it too. Letโ€™s dive in!


Table of Contents

  1. What is Flutter Modular?
  2. Why Did I Start Using It?
  3. Setting Up Flutter Modular
  4. Breaking Down Modules and Routes
  5. Smooth Navigation Between Screens

1. What is Flutter Modular?

Think of Flutter Modular as your appโ€™s superpower that keeps things tidy. It helps you organize your project by modularizing routes and dependencies. Instead of cluttering your main.dart with a ton of navigation logic, Flutter Modular keeps it clean and structured.


2. Why Did I Start Using It?

Okay, confession timeโ€”I used to hardcode my routes and manually pass dependencies everywhere. It worked for small projects, but as my app grew, maintaining it felt like playing Jenga with my sanity. ๐Ÿคฏ

Then, I came across Flutter Modular, and suddenly, everything clicked:

  • No more scattered route management ๐ŸŽฏ
  • Dependencies are injected where needed ๐Ÿ”ฅ
  • My project became way easier to scale ๐Ÿ“ˆ

3. Setting Up Flutter Modular

Check it out: https://pub.dev/packages/flutter_modular

flutter pub add flutter_modular
Enter fullscreen mode Exit fullscreen mode

Boom! Youโ€™re ready to roll. ๐ŸŽ‰


4. Breaking Down Modules and Routes

In Flutter Modular, you create modules to structure your app. Here's how I structured mine:

import 'package:flutter_modular/flutter_modular.dart';
import 'package:flutter/material.dart';

import 'home_page.dart';
import 'about_page.dart';

class AppModule extends Module {
  @override
  List<Bind> get binds => [];

  @override
  List<ModularRoute> get routes => [
        ChildRoute('/', child: (_, __) => HomePage()),
        ChildRoute('/about', child: (_, __) => AboutPage()),
      ];
}
Enter fullscreen mode Exit fullscreen mode

This makes it super easy to add or update routes without touching your main widget. Love it! โค๏ธ


5. Smooth Navigation Between Screens

Navigation used to be a mess, but Modular makes it a breeze:

Modular.to.pushNamed('/about');
Enter fullscreen mode Exit fullscreen mode

And when I want to go back:

Modular.to.pop();
Enter fullscreen mode Exit fullscreen mode

So clean and simple, right? No more Navigator.of(context).push(...) everywhere! ๐Ÿ˜


Wrapping It Up

Switching to Flutter Modular completely changed the way I structure my Flutter apps. If you're struggling with messy navigation and dependencies, I highly recommend giving it a try. It keeps your project modular, scalable, and easy to maintain.

Iโ€™d love to hear about your experience tooโ€”have you tried Flutter Modular? Letโ€™s chat in the comments! ๐Ÿ‘‡


Let's Connect! ๐ŸŽ‰

If you found this helpful and want to stay updated with more Flutter tips, feel free to follow me:

Dev.to: https://dev.to/thinnakrit

LinkedIn: https://www.linkedin.com/in/thinnakrit

GitHub: https://github.com/thinnakrit

Happy coding! ๐Ÿ˜Š

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup ๐Ÿš€

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

Top comments (0)

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

๐Ÿ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someoneโ€™s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay