Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Accountancy
  • Business Studies
  • Economics
  • Organisational Behaviour
  • Human Resource Management
  • Entrepreneurship
  • Marketing
  • Income Tax
  • Finance
  • Management
  • Commerce
Open In App
Next Article:
Creating a Simple Application in Flutter
Next article icon

Creating a Finance Tracker Application in Flutter

Last Updated : 16 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Developing a new tracker for finance is a good practice to improve your skills and build a helpful application. Through Flutter, an open-source UI toolkit developed by Google, it is possible to design for iOS/ Android, web, and desktop. Here you will find out the recipe of how to create a finance tracker application in Flutter excluding UI components that are not essential to such an application. By the end you should have a functional Android application with a feature for tracking expenses with a category, and an amount and a date and the data is stored locally using SQLite.

How to Build a Finance Tracker App in Flutter

To develop a finance tracker app using Flutter, follow these steps:

Project Directory Structure

Before diving into the code, let's look at the directory structure of our project:

structure


Steps to Create a Finance Tracker App in Flutter

Step 1: Create a New Flutter Project

Open your terminal and create a new Flutter project by running the following command:

flutter create finance_tracker
cd finance_tracker

Step 2: Add Dependencies

To manage state and store data, we need to add the provider, intl, sqflite, and path_provider packages. Open the pubspec.yaml file and add the following dependencies:

Dart
dependencies:   flutter:     sdk: flutter   provider: ^6.0.3   intl: ^0.17.0   sqflite: ^2.0.0+4   path_provider: ^2.0.2 


Run flutter pub get to install the packages.

Step 3: Define the Data Model

Create a file lib/models/transaction.dart to define the Transaction data model:

Dart
class Transaction {   final String id;   final String category;   final double amount;   final DateTime date;    Transaction({     required this.id,     required this.category,     required this.amount,     required this.date,   }); } 


Step 4: State Management with Provider

Create a file lib/providers/transactions.dart to manage the state using the Provider package:

Dart
import 'package:flutter/foundation.dart'; import '../models/transaction.dart'; import '../helpers/db_helper.dart';  class TransactionsProvider with ChangeNotifier {   List<Transaction> _transactions = [];    List<Transaction> get transactions => _transactions;    void addTransaction(String category, double amount, DateTime date) {     final newTransaction = Transaction(       id: DateTime.now().toString(),       category: category,       amount: amount,       date: date,     );     _transactions.add(newTransaction);     notifyListeners();     DBHelper.insert('transactions', {       'id': newTransaction.id,       'category': newTransaction.category,       'amount': newTransaction.amount,       'date': newTransaction.date.toIso8601String(),     });   }    Future<void> fetchAndSetTransactions() async {     final dataList = await DBHelper.getData('transactions');      _transactions = dataList         .map(           (item) => Transaction(             id: item['id'],             category: item['category'],             amount: item['amount'],             date: DateTime.parse(item['date']),           ),         )         .toList();     notifyListeners();   } } 


Step 5: Main Application Setup

Update lib/main.dart to set up the main structure of the app:

Dart
import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import './providers/transactions.dart'; import './screens/home_screen.dart'; import './screens/add_transaction_screen.dart';  void main() {   runApp(const MyApp()); }  class MyApp extends StatelessWidget {   const MyApp({super.key});    @override   Widget build(BuildContext context) {     return ChangeNotifierProvider(       create: (ctx) => TransactionsProvider(),       child: MaterialApp(         title: 'Finance Tracker',         theme: ThemeData(           primarySwatch: Colors.blue,         ),         home: const HomeScreen(),         routes: {           AddTransactionScreen.routeName: (ctx) => const AddTransactionScreen(),         },       ),     );   } } 


Step 6: Home Screen

Create a file lib/screens/home_screen.dart to display the list of transactions and provide a button to add new ones:

Dart
import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../providers/transactions.dart'; import '../widgets/transaction_list.dart'; import 'add_transaction_screen.dart';  class HomeScreen extends StatelessWidget {   const HomeScreen({super.key});    @override   Widget build(BuildContext context) {     final transactionsProvider = Provider.of<TransactionsProvider>(context);      return Scaffold(       appBar: AppBar(         title: const Text('Finance Tracker'),       ),       body: FutureBuilder(         future: transactionsProvider.fetchAndSetTransactions(),         builder: (ctx, snapshot) => transactionsProvider.transactions.isEmpty             ? const Center(                 child: Text("No transactions!"),               )             : TransactionList(transactionsProvider.transactions),       ),       floatingActionButton: FloatingActionButton(         child: const Icon(Icons.add),         onPressed: () {           Navigator.of(context).pushNamed(AddTransactionScreen.routeName);         },       ),     );   } } 


Step 7: Transaction List Widget

Create a file lib/widgets/transaction_list.dart to display the list of transactions:

Dart
import 'package:flutter/material.dart'; import '../models/transaction.dart';  class TransactionList extends StatelessWidget {   final List<Transaction> transactions;    const TransactionList(this.transactions, {super.key});    @override   Widget build(BuildContext context) {     return ListView.builder(       itemCount: transactions.length,       itemBuilder: (ctx, index) {         return GestureDetector(           onLongPress: () {            },           child: Card(             child: ListTile(               title: Text(transactions[index].category),               subtitle: Text(transactions[index].date.toString()),               trailing: Text('\$${transactions[index].amount.toString()}'),             ),           ),         );       },     );   } } 


Step 8: Add Transaction Screen

Create a file lib/screens/add_transaction_screen.dart to add new transactions:

Dart
import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../providers/transactions.dart';  class AddTransactionScreen extends StatefulWidget {   static const routeName = '/add-transaction';    const AddTransactionScreen({super.key});    @override   _AddTransactionScreenState createState() => _AddTransactionScreenState(); }  class _AddTransactionScreenState extends State<AddTransactionScreen> {   final _formKey = GlobalKey<FormState>();   String _category = 'Food';   double _amount = 0;   DateTime _selectedDate = DateTime.now();    void _submitForm() {     if (_formKey.currentState!.validate()) {       _formKey.currentState!.save();       Provider.of<TransactionsProvider>(context, listen: false)           .addTransaction(_category, _amount, _selectedDate);       Navigator.of(context).pop();     }   }    void _presentDatePicker() {     showDatePicker(       context: context,       initialDate: _selectedDate,       firstDate: DateTime(2020),       lastDate: DateTime.now(),     ).then((pickedDate) {       if (pickedDate == null) {         return;       }       setState(() {         _selectedDate = pickedDate;       });     });   }    @override   Widget build(BuildContext context) {     return Scaffold(       appBar: AppBar(         title: const Text('Add Transaction'),       ),       body: Padding(         padding: const EdgeInsets.all(16.0),         child: Form(           key: _formKey,           child: Column(             children: <Widget>[               TextFormField(                 decoration: const InputDecoration(labelText: 'Amount'),                 keyboardType: TextInputType.number,                 validator: (value) {                   if (value!.isEmpty) {                     return 'Please enter an amount';                   }                   return null;                 },                 onSaved: (value) {                   _amount = double.parse(value!);                 },               ),               DropdownButtonFormField(                 value: _category,                 items: ['Food', 'Travel', 'Entertainment']                     .map((label) => DropdownMenuItem(                           value: label,                           child: Text(label),                         ))                     .toList(),                 onChanged: (value) {                   setState(() {                     _category = value as String;                   });                 },                 onSaved: (value) {                   _category = value as String;                 },               ),               Row(                 children: <Widget>[                   Expanded(                     child: Text(                       'Date: ${_selectedDate.toLocal()}'.split(' ')[0],                     ),                   ),                   ElevatedButton(                     onPressed: _presentDatePicker,                     child: const Text('Choose Date'),                   ),                 ],               ),               const SizedBox(height: 20),               ElevatedButton(                 onPressed: _submitForm,                 child: const Text('Add Transaction'),               ),             ],           ),         ),       ),     );   } } 


Step 9: Local Storage Setup

Create a file lib/helpers/db_helper.dart to set up SQLite for local storage:

Dart
import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart';  class DBHelper {   static Future<Database> database() async {     final dbPath = await getDatabasesPath();     return openDatabase(       join(dbPath, 'transactions.db'),       onCreate: (db, version) {         return db.execute(           'CREATE TABLE transactions(id TEXT PRIMARY KEY, category TEXT, amount REAL, date TEXT)',         );       },       version: 1,     );   }    static Future<void> insert(String table, Map<String, Object> data) async {     final db = await DBHelper.database();     db.insert(       table,       data,       conflictAlgorithm: ConflictAlgorithm.replace,     );   }    static Future<List<Map<String, dynamic>>> getData(String table) async {     final db = await DBHelper.database();     return db.query(table);   } } 

Output:

Congratulations! You have created a simple but operational Finance Tracker Application in Flutter. This app enables users to enter transactions with categories, amounts, and dates and downloads and stores the data with the use of a SQLite database. You can improve it with adding a feature to edit the transaction, filter the data by date, and more useful tools to illustrate the data.

Git Application for the Finance Application : Finance Flutter Application


Of course, do whatever you need to do to develop and grow the app and its capabilities. Happy coding!



Next Article
Creating a Simple Application in Flutter

Y

ypathatxp1
Improve
Article Tags :
  • Project
  • Flutter
  • Android
  • Finance
  • Android 13
  • Flutter
  • Dart-Time

Similar Reads

  • Creating a Simple Application in Flutter
    Flutter is an open-source cross-platform mobile application development SDK created by Google. It is highly user-friendly and builds high-quality mobile applications. The intention behind this article is to guide readers through the process of building an application through Flutter by creating a si
    5 min read
  • Expense Tracker Application Flutter
    In this tutorial, we will create a Flutter app that allows users to track their daily expenses and income, visualize spending patterns through charts, and store transaction data locally using Hive. This application will showcase how to handle user input, visualize data, and ensure local data persist
    10 min read
  • Recipe Finder Application in Flutter
    This app will display a list of recipes in a card format, each containing the recipe title, a rating, the cooking time, and a thumbnail image to give users a visual preview. The app is dynamic and flexible, allowing you to easily update the recipe list or modify the UI as needed. By the end of this
    5 min read
  • Photo Editing Application in Flutter
    With the introduction of the powerful image_editor_plus package, editing images directly within your Flutter app has become significantly more accessible. In this article, we'll dive deep into building a user-friendly image editor app. Users will have the ability to select an image from their camera
    7 min read
  • EBook reader Application in Flutter
    EBook reader Application brings the library to your fingertips. This application will be the travel partner of every book lover who loves to read books of their choice. The app is developed using Flutter and provider state management. It uses the Google Books API to fetch the data of books. The app
    8 min read
  • How to Create a Desktop Window Application in Flutter?
    The Flutter team recently released Flutter version 2.10 with Desktop support. Desktop support allows you to compile Flutter source code to a native Windows, macOS, or Linux desktop app. Flutter’s desktop support also extends to plugins—you can install existing plugins that support the Windows, macOS
    3 min read
  • How to Create a NFC Reader and Writer Flutter Application
    NFC that stands for Near Field Communication, is a very short range wireless technology that allows us share small amount of data between devices. Through this technology we can share data between an NFC tag and an android device or between two android devices. A maximum of 4 cm distance is required
    6 min read
  • Flutter - Creating App Intro Screens
    Flutter is known for its easiness to create cross-platform applications. Either it is creating introduction screens for the app or any screen. We got an easy way to create Intros for the app using the intro_slider library of Flutter. In this article, we are going to implement it in the sample app.
    4 min read
  • How to Build a Bitcoin Tracker Flutter App?
    In this article, we will be building a Bitcoin Tracker Project using Flutter and Dart . The application will display the current rates of Bitcoin in different countries using Bitcoin API. There are many free APIs available and for this project, we will be using API by Coinlayer. The API will return
    3 min read
  • Flutter Quill - Rich Text Editor in Flutter Application
    This post will explain how to integrate a rich text editor into your Flutter application so that it may enable rich text editing. There are many more things we can do with Flutter Quill, but they can get a little involved. The example below is a pretty basic demonstration of what we mean. Let's firs
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences