LAB PROJECT ON
“UNIT CONVERTER”
Submitted to the:
GURU NANAK INSTITUTIONS TECHNICAL
CAMPUS(AUTONOMUS)
IN PARTIAL REQUIREMENTS FOR PBL LAB PROJECT
in
COMPUTER SCIENCE & ENGINEERING
By:
MD FAISAL
ROLL NO.: 22WJ1A05AH, CSE -5, GNITC
Under the Esteemed Guidance Of
Mr. Shiek Riyaz
(Associate Professor of CSE, GNITC)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
(AUTONOMOUS)
SCHOOL OF ENGINEERING AND TECHNOLOGY,
IBRAHIMPATNAM, R.R DISTRICT 501506
2023-2024
CERTIFICATE
This is to certify that this Lab Project for the course- UI Design Flutter
Lab(22SD0CS03) entitled "Unit Converter" being submitted by Md.
Faisal(22WJ1A05AH), in partial fulfillment for the award of the Degree of
Bachelor of Technology in Computer Science & Engineering of the Guru Nanak
Institutions Technical Campus, Hyderabad during the academic year 2024-2025,
is a record of bonafide work carried out under our guidance and supervision at Guru
Nanak Institutions Technical Campus (Autonomous).
SIGNATURE SIGNATURE
Mr. Shiek Riyaz Dr. Geeta Tripathi
Lab Faculty -UI Design Flutter (Head of Department)
Dept. of CSE, GNITC
ABSTRACT
This Flutter application is a versatile unit converter designed to efficiently
convert values between various units of measurement. It provides a user-
friendly interface that allows users to input a value in one unit and instantly
view the equivalent value in multiple other units. The application covers a
wide range of units, including length, weight, temperature, area, volume,
speed, time, energy, power, and digital storage. The project includes a clean
design, responsive layouts, and dynamic features such as real-time currency
conversion using API integration, customizable unit categories, and a history
of past conversions. The application aims to simplify everyday tasks for users
in education, travel, cooking, and engineering by offering a comprehensive
and accessible conversion tool. This project demonstrates the potential of
Flutter for building robust, cross-platform applications with an emphasis on
usability and functionality.
iv
TABLE OF CONTENTS
Chapter No. Title Page No.
ABSTRACT iii
TABLE OF CONTENTS iv
1 INTRODUCTION 5
2 SOFTWARE REQUIREMENTS 6
3 HARDWARE REQUIREMENTS 6
4 ADVANTAGES 7
5 DISADVANTAGES 7
6 IMPLEMENTATION & CODE 8-12
8 EXECUTION/OUTPUT 13
9 RESULTS 14
iv
INTRODUCTION
The Unit Converter App is a mobile application developed using the Flutter framework,
designed to provide users with a convenient and efficient tool for converting values across
various units of measurement. In everyday life, unit conversion is often required in fields
such as education, travel, cooking, engineering, and commerce. This project addresses the
need for a reliable, accurate, and user-friendly solution for these tasks.
Built with Flutter, the app offers a seamless cross-platform experience, running efficiently on
both Android and iOS devices with a single codebase. The application supports multiple
categories of unit conversions, including length, weight, temperature, volume, currency, and
more. It leverages Flutter's rich widget library and fast rendering capabilities to create an
intuitive and visually appealing user interface.
5
SOFTWARE REQUIREMENTS:
1. Flutter: A cross-platform framework for building the app, supporting both Android,
iOS, and web development.
2. Dart: The programming language used with Flutter for app development.
3. IDE (Visual Studio Code/Android Studio): Essential for writing, debugging, and
testing the code.
HARDWARE REQUIREMENTS:
1. Computer: A system with at least 4 GB of RAM and a modern processor (Intel i5 or
equivalent) for running development tools smoothly.
2. Mobile Device: Android or iOS device (or emulators/simulators) for testing the app on
various screen sizes.
3. Storage: Sufficient disk space (at least 10 GB) to store the development environment,
SDKs, libraries, and project files.
4. Internet Connection: A stable internet connection for downloading dependencies,
frameworks, and APIs.
6
ADVANTAGES :
1. Cross-Platform Compatibility
Flutter enables a single codebase to run on both Android and iOS devices, reducing
development time and effort while ensuring consistency in user experience.
2. Fast Development
With features like Hot Reload, Flutter allows developers to see code changes instantly,
speeding up the development process and facilitating rapid iterations.
3. Customizable User Interface
Flutter’s rich set of pre-built widgets and customizable UI components makes it easy to
design a visually appealing and highly interactive user interface.
4. Performance Optimization
Flutter apps are compiled into native code, offering near-native performance. This ensures
that the Unit Converter operates smoothly and handles calculations quickly.
5. Versatility
The application can support multiple unit categories (e.g., length, weight, temperature,
currency) and can integrate with APIs for real-time data, such as currency conversion rates.
DISADVANTAGES:
1. Large Application Size
Flutter applications generally have a larger initial size compared to native apps, which can be
a concern for users with limited device storage or slower internet connections.
2. Limited Native Features
While Flutter supports many native functionalities, certain advanced platform-specific
features may require additional plugins or custom platform integration, increasing
complexity.
3. Learning Curve
Developers who are new to Flutter or Dart may face a learning curve, especially if they are
accustomed to other frameworks or programming languages.
4. Performance Overhead for Complex Calculations
Although Flutter offers near-native performance, apps involving heavy computation (e.g.,
large-scale conversions or extensive data handling) might perform slightly slower compared
to optimized native apps.
5. Dependency on Third-Party Packages
The project might rely on third-party plugins or packages for certain features, such as API
integration or advanced UI components. If these packages are poorly maintained or
deprecated, it could lead to compatibility issue
8
IMPLEMENTATION & CODE
import 'package:flutter/material.dart';
void main() => runApp(UnitConverterApp());
class UnitConverterApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Unit Converter',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: UnitConverterHome(),
);
}
}
class UnitConverterHome extends StatefulWidget {
@override
_UnitConverterHomeState createState() => _UnitConverterHomeState();
}
class _UnitConverterHomeState extends State<UnitConverterHome> {
// Variables to hold input, category, and result
double inputValue = 0.0;
String selectedCategory = 'Length';
String inputUnit = 'Meters';
String outputUnit = 'Kilometers';
String result = '';
// Unit categories and their respective conversion rates
final Map<String, Map<String, double>> unitCategories = {
'Length': {
'Meters': 1.0,
'Kilometers': 0.001,
'Miles': 0.000621371,
'Feet': 3.28084,
'Centimeters': 100.0,
'Yards': 1.09361,
},
'Quantity': {
'Liters': 1.0,
'Milliliters': 1000.0,
'Gallons': 0.264172,
'Cups': 4.22675,
},
};
// Convert the input value
9
void convert() {
setState(() {
try {
// Get the current category's conversion rates
final conversionRates = unitCategories[selectedCategory]!;
// Convert input value to base unit
double inputInBaseUnit = inputValue * conversionRates[inputUnit]!;
// Convert from base unit to output unit
double convertedValue = inputInBaseUnit / conversionRates[outputUnit]!;
result = convertedValue.toStringAsFixed(4);
} catch (e) {
result = 'Error: Invalid input or conversion';
}
});
}
// Reset the input and result fields
void reset() {
setState(() {
inputValue = 0.0;
selectedCategory = 'Length';
inputUnit = 'Meters';
outputUnit = 'Kilometers';
result = '';
});
}
@override
Widget build(BuildContext context) {
// Get the units for the selected category
final units = unitCategories[selectedCategory]!.keys.toList();
return Scaffold(
appBar: AppBar(
title: Text('Unit Converter'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Input field
TextField(
decoration: InputDecoration(
labelText: 'Enter value',
border: OutlineInputBorder(),
hintText: 'e.g., 100',
),
keyboardType: TextInputType.number,
10
onChanged: (value) {
setState(() {
inputValue = double.tryParse(value) ?? 0.0;
});
},
),
SizedBox(height: 20),
// Dropdown for Category
Text(
'Select Category:',
style: TextStyle(fontWeight: FontWeight.bold),
),
DropdownButton<String>(
value: selectedCategory,
isExpanded: true,
onChanged: (String? newValue) {
setState(() {
selectedCategory = newValue!;
// Reset units based on the new category
inputUnit = unitCategories[selectedCategory]!.keys.first;
outputUnit = unitCategories[selectedCategory]!.keys.last;
});
},
items: unitCategories.keys
.map<DropdownMenuItem<String>>((String category) {
return DropdownMenuItem<String>(
value: category,
child: Text(category),
);
}).toList(),
),
SizedBox(height: 20),
// Dropdown for Input Unit
Text(
'Select Input Unit:',
style: TextStyle(fontWeight: FontWeight.bold),
),
DropdownButton<String>(
value: inputUnit,
isExpanded: true,
onChanged: (String? newValue) {
setState(() {
inputUnit = newValue!;
});
},
items: units.map<DropdownMenuItem<String>>((String unit) {
return DropdownMenuItem<String>(
value: unit,
child: Text(unit),
);
}).toList(),
),
11
SizedBox(height: 20),
// Dropdown for Output Unit
Text(
'Select Output Unit:',
style: TextStyle(fontWeight: FontWeight.bold),
),
DropdownButton<String>(
value: outputUnit,
isExpanded: true,
onChanged: (String? newValue) {
setState(() {
outputUnit = newValue!;
});
},
items: units.map<DropdownMenuItem<String>>((String unit) {
return DropdownMenuItem<String>(
value: unit,
child: Text(unit),
);
}).toList(),
),
SizedBox(height: 20),
// Convert button
ElevatedButton(
onPressed: convert,
child: Text('Convert'),
),
SizedBox(height: 10),
// Reset button
ElevatedButton(
onPressed: reset,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
),
child: Text('Reset'),
),
SizedBox(height: 20),
// Result display
Text(
result.isEmpty ? 'Result will appear here' : 'Converted Value: $result',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
],
),
),
);
}
}
12
EXECUTION
10
RESULTS:
1. User Input: The TextField allows the user to enter the value to be converted.
2. Unit Selection: The two DropdownButtonFormField widgets let the user choose the
initial and target units.
3. Conversion Logic: The _convert function performs the conversion based on the
selected units. You can add more conversion cases for different units.
4. Result Display: The Text widget displays the calculated result.
Error Handling: Implement error handling to handle invalid input and
unsupported units.
Unit Database: Consider using a database or a configuration file to store unit
information for easier management and scalability.
Unit Conversion Library: You can use a third-party library like
unit_converter to simplify the conversion logic.
Accessibility: Ensure your app is accessible to users with disabilities by
following accessibility guidelines.
14