Skip to main content
【ChatGPT × Flutter】Tips Of Build A Todo-App In 5 Minutes
  1. Posts/

【ChatGPT × Flutter】Tips Of Build A Todo-App In 5 Minutes

1358 words·7 mins· 0 ·
Tech AI Mobile App Development GPT-4

Welcome to this exciting tutorial on building a mobile app in just 5 minutes! With the power of ChatGPT and Flutter, creating an application has never been easier. You might think it’s impossible to achieve such a feat, but we assure you that by following the steps outlined in this blog post, you will have a simple yet functional app running on your device in no time. So, grab a cup of coffee, follow our step-by-step tutorial, and amaze yourself with the magic of ChatGPT and Flutter!

Build a Todo App With ChatGPT × Flutter : Prerequisit #

Alt text
create a todo app within 5 min by ChatGPT & Flutter
In this section, we will briefly introduce ChatGPT, an AI-based language model, and Flutter, the open-source UI toolkit developed by Google. We will also discuss how the combination of these two technologies simplifies and accelerates mobile app development.

Prerequisit For Todo App By ChatGPT × Flutter : Install Flutter On Your PC #

First of all, you need to install Flutter on your PC. Please visit this flutter official page to install Flutter.

Warning! In this post, I just run the app on Mac OS app, but if you want to run your app on your iOS/Android device, you need to install Android Studio & Xcode as well.

Prerequisit For Todo App By ChatGPT × Flutter : Install Merlin ChatGPT #

Next, you need to install Merlin ChatGPT on your google browser. Merlin ChatGPT is a google extension to use ChatGPT. We can use it for free, just jump to google extension page and hit the install button.

For more details, please see my another post detailed about Merlin ChatGPT.

Merlin : Best AI Chatbot Powered By GPT-4 - Perfect Guide For AI Beginner
647 words·4 mins· 0
Tech AI ChatGPT
If you are looking for a AI Chatbot powered by GPT-4, let’s explore Merlin on this blog

Build A Todo App With ChatGPT × Flutter #

Now, you are all set to see the amazing magic by ChatGPT & Flutter. Let’s deep dive into the fun part now:)

1.Create a flutter project #

So first, you need to create your own flutter project to create scaffold for todo app. Open terminal and run this command to create your flutter project.

flutter create project_name

When you successfully created your project folder, let’s open the folder by VS code (any IDE is Okay).

2. Prompt Merlin GPT To Generate Codes #

This is the main part of this blog post. First, let’s open the merlin GPT and input the following prompt.

You can open merlin GPT by Cmd + M key on google browser. If you can’t call merlin GPT, please check you installed merlin on your google extension appripriately.

generate source code with flutter for todo list app

If you can successfully send your prompt to merlin GPT, you will get the source code for todo app by flutter like this.

Here's a simple example of a todo list app in Flutter:

1. Set up the project and import necessary packages.

```dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: HomeScreen(),
  ));
}
  1. Create a Todo class.
class Todo {
  final String title;
  bool isDone;

  Todo({
    required this.title,
    this.isDone = false,
  });
}
  1. Create a list of todos (inside StatefulWidget).
class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  List<Todo> todoList = [];
}
  1. Build a UI to display todos.
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Todo List'),
      ),
      body: ListView.builder(
        itemCount: todoList.length,
        itemBuilder: (context, index) {
          return ListTile(
            title: Text(todoList[index].title),
            leading: Checkbox(
              value: todoList[index].isDone,
              onChanged: (bool? value) {
                setState(() {
                  todoList[index].isDone = value!;
                });
              },
            ),
            trailing: IconButton(
              icon: Icon(Icons.delete),
              onPressed: () {
                setState(() {
                  todoList.removeAt(index);
                });
              },
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _showAddTodoDialog(context);
        },
        child: Icon(Icons.add),
      ),
    );
  }
  1. Add a method to show an Add Todo dialog.
Future<void> _showAddTodoDialog(BuildContext context) async {
  final TextEditingController _todoController = TextEditingController();
  return showDialog<void>(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text('Add Todo'),
        content: SingleChildScrollView(
          child: ListBody(
            children: <Widget>[
              TextField(
                controller: _todoController,
                decoration: InputDecoration(
                  hintText: 'Enter Todo Title',
                ),
              ),
            ],
          ),
        ),
        actions: <Widget>[
          TextButton(
            child: Text('Cancel'),
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),
          TextButton(
            child: Text('Add'),
            onPressed: () {
              setState(() {
                if (_todoController.text.isNotEmpty) {
                  todoList.add(Todo(title: _todoController.text));
                }
              });
              Navigator.of(context).pop();
            },
          ),
        ],
      );
    },
  );
}

ChatGPT generated the ingredient codes for Todo App in a min:) But we are not sure how to use these ingredients.

So let me explain how to do one by one:)

3. Edit main.dart On Your Project Folder #

Alt text
edit a todo.dart
First of all, we will create the UI for todo app by flutter. Please open the lib/main.dart on your project folder.

We will use the source code for step1, step3, step4 and step5 generaged by ChatGPT. You can copy & paste of my code as follows. Eventually, your main.dart should look like this.

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'todo.dart';

void main() {
  runApp(MaterialApp(
    home: HomeScreen(),
  ));
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  List<Todo> todoList = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Todo List'),
      ),
      body: ListView.builder(
        itemCount: todoList.length,
        itemBuilder: (context, index) {
          return ListTile(
            title: Text(todoList[index].title),
            leading: Checkbox(
              value: todoList[index].isDone,
              onChanged: (bool? value) {
                setState(() {
                  todoList[index].isDone = value!;
                });
              },
            ),
            trailing: IconButton(
              icon: Icon(Icons.delete),
              onPressed: () {
                setState(() {
                  todoList.removeAt(index);
                });
              },
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _showAddTodoDialog(context);
        },
        child: Icon(Icons.add),
      ),
    );
  }

  Future<void> _showAddTodoDialog(BuildContext context) async {
    final TextEditingController _todoController = TextEditingController();
    return showDialog<void>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Add Todo'),
          content: SingleChildScrollView(
            child: ListBody(
              children: <Widget>[
                TextField(
                  controller: _todoController,
                  decoration: InputDecoration(
                    hintText: 'Enter Todo Title',
                  ),
                ),
              ],
            ),
          ),
          actions: <Widget>[
            TextButton(
              child: Text('Cancel'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            TextButton(
              child: Text('Add'),
              onPressed: () {
                setState(() {
                  if (_todoController.text.isNotEmpty) {
                    todoList.add(Todo(title: _todoController.text));
                  }
                });
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }
}

It’s ok to get an error at this moment. We will create the data class accordingly:)

4. Create Todo Item Class #

Alt text
create a todo.dart
In order to handle the data class (class to manage the state of each todo item), first let’s create the file on the same folder with main.dart. It means inside lib folder.

After that, you can just copy & paste the source code of step2 on this blog. It’s ok if you can have the same code like this.

class Todo {
  final String title;
  bool isDone;

  Todo({
    required this.title,
    this.isDone = false,
  });
}

5. Run Your Code #

Now everything is ready for running your todo app! All you have to do is to save your code & hit the run button on your IDE:)

Or you can run your app from the terminal, pls run the command on your terminal!

flutter run

You should get the result like this video if everything works ok!

Conclusion #

As you can see, creating a mobile app within 5 minutes is not a far-fetched dream when you harness the power of ChatGPT and Flutter. This tutorial demonstrated how quickly and easily you can build a functional, AI-powered mobile app with these cutting-edge tools. Armed with our step-by-step guide and the endless possibilities offered by ChatGPT and Flutter, it’s time to let your creative juices flow and start designing your next revolutionary application!

About me #

I hope this post is informative to you:) For someone who doesn’t know me, here is the summary about me:)

  • I started my IT career without any CS background
  • I have a couple of years of working experiences as software developer (mainly mobile & web) in Japan
  • I got tired of the life in Japan and moved to Vietnam, Da Nang
  • I love to create the mobile apps, Youtube videos and share the life in Vietnam
  • I hope I can create the space to connect devs all over the world:)

For more details, I am waiting for you on my Youtube channels:)