0% found this document useful (0 votes)
4 views3 pages

Flutter Expense Tracker App Code

The document is a Flutter application for tracking expenses, featuring a user interface to add and display expenses. It includes a bar chart to visualize daily expense totals and allows users to input expense details through a dialog. The app maintains a list of expenses and updates the chart dynamically as new expenses are added.

Uploaded by

vasanthks8782
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Flutter Expense Tracker App Code

The document is a Flutter application for tracking expenses, featuring a user interface to add and display expenses. It includes a bar chart to visualize daily expense totals and allows users to input expense details through a dialog. The app maintains a list of expenses and updates the chart dynamically as new expenses are added.

Uploaded by

vasanthks8782
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import 'package:flutter/material.

dart';
import 'package:fl_chart/fl_chart.dart';

void main() => runApp(ExpenseTrackerApp());

class Expense {
String title;
double amount;
DateTime date;

Expense({required [Link], required [Link], required [Link]});


}

class ExpenseTrackerApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Expense Tracker',
theme: ThemeData(primarySwatch: [Link]),
home: ExpenseHomePage(),
debugShowCheckedModeBanner: false,
);
}
}

class ExpenseHomePage extends StatefulWidget {


@override
_ExpenseHomePageState createState() => _ExpenseHomePageState();
}

class _ExpenseHomePageState extends State<ExpenseHomePage> {


List<Expense> expenses = [];

void addExpense(String title, double amount) {


var newExp = Expense(
title: title,
amount: amount,
date: [Link](),
);
setState(() => [Link](newExp));
}

void openAddDialog() {
var title = '';
var amount = '';

showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text('Add Expense'),
content: Column(
mainAxisSize: [Link],
children: [
TextField(
decoration: InputDecoration(labelText: 'Title'),
onChanged: (val) => title = val,
),
TextField(
decoration: InputDecoration(labelText: 'Amount'),
keyboardType: [Link],
onChanged: (val) => amount = val,
),
],
),
actions: [
TextButton(
onPressed: () {
if ([Link] && [Link](amount) != null) {
addExpense(title, [Link](amount));
}
[Link](context).pop();
},
child: Text('Add'),
)
],
),
);
}

List<BarChartGroupData> getChartData() {
Map<String, double> dailyTotals = {};
for (var exp in expenses) {
var date = "${[Link]}/${[Link]}";
dailyTotals[date] = (dailyTotals[date] ?? 0) + [Link];
}

var index = 0;
return [Link]((entry) {
return BarChartGroupData(
x: index++,
barRods: [
BarChartRodData(toY: [Link], color: [Link], width: 16),
],

);
}).toList();
}

@override
Widget build(BuildContext context) {
var chartData = getChartData();

return Scaffold(
appBar: AppBar(title: Text('Expense Tracker')),
floatingActionButton: FloatingActionButton(
onPressed: openAddDialog,
child: Icon([Link]),
),
body: Column(
children: [
SizedBox(
height: 200,
child: Padding(
padding: const [Link](16.0),
child: BarChart(
BarChartData(
titlesData: FlTitlesData(show: false),
barGroups: chartData,
),
),
),
),
Expanded(
child: [Link](
itemCount: [Link],
itemBuilder: (_, i) => ListTile(
title: Text(expenses[i].title),
subtitle: Text(expenses[i].[Link]()),
trailing:
Text("₹${expenses[i].[Link](2)}"),
),
),
)
],
),
);
}
}

You might also like