Welcome to the Expense Tracker Flutter app! This application is designed to help you manage your expenses efficiently. With its user-friendly interface, you can easily add, edit, and delete expenses, as well as view expense details and summary reports.
To get started with the Expense Tracker app, follow these simple steps:
- Make sure you have Flutter and Dart installed on your development machine.
- Clone this repository to your local environment using
git clone
. - Open the project in your favorite IDE or code editor.
- Run
flutter pub get
to install all the required dependencies. - Connect a physical device or start an emulator/simulator.
- Launch the app by executing
flutter run
in the terminal.
-
final
: Declares an immutable variable that can be assigned a value only once. Once assigned, its value cannot be changed.final double price = 25.99;
-
const
: Declares a compile-time constant variable with a known value that remains constant throughout the app's execution.const int daysInAWeek = 7;
-
key
: A unique identifier for widgets, enabling widget state persistence and efficient updates in the widget tree.Widget build(BuildContext context) { return Text( "Hello, World!", key: Key('helloText'), ); }
-
context
: Represents the current location in the widget tree and provides access to various services like localization and theme data.void _showSnackBar(BuildContext context) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Expense added!')), ); }
-
Initializers: Used to initialize variables, particularly in constructors.
class Expense { final String name; final double amount; Expense(this.name, this.amount); }
-
Additional Constructors: Allow creating multiple constructors for a class with different parameters.
class Expense { final String name; final double amount; Expense(this.name, this.amount); Expense.fromMap(Map<String, dynamic> map) : name = map['name'], amount = map['amount']; }
-
debugShowCheckedModeBanner
: A flag to show or hide the "debug" banner at the top-right corner of the app when running in debug mode.void main() { MaterialApp( debugShowCheckedModeBanner: true, runApp(MyApp() ), ), }
-
darkTheme
and 9.theme
: Define the dark and light themes of the app, respectively.MaterialApp( theme: ThemeData.light(), darkTheme: ThemeData.dark(), home: MyExpenseTrackerApp(), );
-
ScaffoldMessenger
: Show snack bars and other in-app messages. A newer replacement forScaffold.of()
.void _showSnackBar(BuildContext context) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Expense added!')), ); }
-
SnackBar
: Display temporary messages at the bottom of the screen.ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Expense added!'), action: SnackBarAction( label: 'Undo', onPressed: () { // Undo expense addition logic }, ), ), );
-
SnackBarAction
: Represent the action of aSnackBar
, such as "Undo" in the above example.SnackBarAction( label: 'Undo', onPressed: () { // Undo logic here }, )
-
Duration
: Represents a duration of time, used with animations and timers.Timer(Duration(seconds: 2), () { // Code to be executed after 2 seconds });
-
AppBar
: Represents the top app bar in a Scaffold.AppBar( title: Text('Expense Tracker'), actions: [ IconButton( icon: Icon(Icons.add), onPressed: () { // Add expense logic }, ), ], )
-
Column
andRow
: Layout widgets used to arrange child widgets vertically and horizontally, respectively.Column( children: [ Text('Expense 1'), Text('Expense 2'), Text('Expense 3'), ], ) Row( children: [ Text('Expense 1'), Text('Expense 2'), Text('Expense 3'), ], )
-
IconButton
: A button widget with an icon.IconButton( icon: Icon(Icons.add), onPressed: () { // Add expense logic }, )
-
ElevatedButton
: A Material Design elevated button.ElevatedButton( onPressed: () { // Button pressed logic }, child: Text('Save Expense'), )
-
Expanded
: A widget that expands to fill the available space along the main axis in aColumn
orRow
.Row( children: [ Expanded(child: Text('Expense 1')), Expanded(child: Text('Expense 2')), Expanded(child: Text('Expense 3')), ], )
-
Spacer
: A widget that takes up available space, forcing its siblings to the opposite side.Row( children: [ Text('Expense 1'), Spacer(), Text('Expense 2'), ], )
-
MediaQuery
: A widget used to get the media query information, such as the screen size and orientation.final screenSize = MediaQuery.of(context).size;
-
Padding
: A widget used to add padding around its child widget.Padding( padding: EdgeInsets.all(16.0), child: Text('Expense Details'), )
-
BorderRadius
: A class used to create rounded corners for widgets likeContainer
.Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(8.0), color: Colors.blue, ), child: Text('Expense Widget'), )
-
SizedBox
: A box with a specified width, height, or both.SizedBox( width: 100, height: 50, child: Text('Box Widget'), )
-
Text
: A widget used to display text on the screen.Text('Expense Name: Grocery')
-
Dismissible
: A widget used to make another widget dismissible by swiping.Dismissible( key: Key(expense.id), child: ListTile( title: Text(expense.name), subtitle: Text('\$${expense.amount}'), ), onDismissed: (direction) { // Delete expense logic }, )
-
DropdownButton
: A widget that displays a dropdown menu with selectable options.DropdownButton<String>( value: selectedCategory, onChanged: (String newValue) { setState(() { selectedCategory = newValue; }); }, items: <String>['Food', 'Transport', 'Shopping', 'Others'] .map<DropdownMenuItem<String>>((String value) { return DropdownMenuItem<String>( value: value, child: Text(value), ); }).toList(), )
-
ListView
: A scrollable list of widgets.ListView.builder( itemCount: expenses.length, itemBuilder: (BuildContext context, int index) { return ListTile( title: Text(expenses[index].name), subtitle: Text('\$${expenses[index].amount}'), ); }, )
-
Navigator.pop
: A method used to pop the top route off the navigator's stack.void _onSaveExpense() { // Save expense logic Navigator.pop(context); }
-
showModalBottomSheet
: A method used to display a bottom sheet.void _showAddExpenseBottomSheet() { showModalBottomSheet( context: context, builder: (context) { return Container( child: Text('Add Expense Form'), ); }, ); }
-
LinearGradient
: A class used to create a gradient with linear interpolation.Container( decoration: BoxDecoration( gradient: LinearGradient( colors: [Colors.blue, Colors.purple], begin: Alignment.topLeft, end: Alignment.bottomRight, ), ), )
-
BoxShape
: An enumeration that defines the different shapes for aBoxDecoration
.Container( decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.red, ), )
-
FractionallySizedBox
: A widget that sizes its child to a fraction of the total available space.FractionallySizedBox( widthFactor: 0.8, child: Text('80% of the screen width'), )