Mobile Application Development
MASTER OF COMPUTER APPLICATIONS
of
KLE TECHNOLOGICAL UNIVERSITY
by
Amol Rathod
01FE23MCA053
DEPARTMENT OF MASTER OF COMPUTER APPLICATIONS
KLE TECHNOLOGICAL UNIVERSITY
Vidyanagar, Hubballi-580031 Karnataka.
May- 2025
SL.NO Program Date
1 Write Dart program to implement various mathematical operations 20/02/2025
2 Write Dart program to implement control flow statements in Dart 06/03/2025
Create a UI layout using built-in widgets such as Column, Row, Container using
3 13/03/2025
stateless
4 Create custom widgets in Flutter for reusable UI components 13/03/2025
5 Create Login screen, handle user input and gestures in Flutter app 27/03/2025
6 Create a login screen with validations 27/03/2025
7 Develop a Flutter app with a navigation drawer 24/04/2025
8 Develop a Flutter app with a bottom navigation bar 24/04/2025
9 Develop a COVID-19 Global Statistics App using Flutter 24/04/2025
1.Mathematical Operation
import 'dart:io';
double add(double a, double b) => a + b;
double subtract(double a, double b) => a - b;
double multiply(double a, double b) => a * b;
double divide(double a, double b) {
if (b == 0) {
throw ArgumentError('Cannot divide by zero');
}
return a / b;
void main() {
stdout.write('Enter first number: ');
String? input1 = stdin.readLineSync();
double num1 = double.tryParse(input1 ?? '') ?? 0;
stdout.write('Enter second number: ');
String? input2 = stdin.readLineSync();
double num2 = double.tryParse(input2 ?? '') ?? 0;
print('Addition: ${add(num1, num2)}');
print('Subtraction: ${subtract(num1, num2)}');
print('Multiplication: ${multiply(num1, num2)}');
try {
print('Division: ${divide(num1, num2)}');
} catch (e) {
print(e);
}
}
2. Control Statement
void main() {
List<int> numbers = [5, 10, 15, 20];
String operation = 'average'; // Try: 'sum', 'average', 'multiply'
switch (operation) {
case 'sum':
int sum = 0;
for (int i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
print('Sum of numbers: $sum');
break;
case 'average':
int total = 0;
for (int num in numbers) {
total += num;
}
double average = total / numbers.length;
print('Average of numbers: $average');
break;
case 'multiply':
int product = 1;
for (int i = 0; i < numbers.length; i++) {
product *= numbers[i];
}
print('Product of numbers: $product');
break;
default:
print('Invalid operation selected.');
}
}
3.UI Layout using built-In widgets.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Nesting Widget Demo',
home: Nesting(),
);
}
}
class Nesting extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Nesting Widget"),
),
body: SingleChildScrollView(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(10),
height: 120,
decoration: BoxDecoration(
border: Border.all(width: 2),
borderRadius: BorderRadius.circular(20),
),
child: Column(
children: [
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
],
),
),
SizedBox(width: 20),
Container(
padding: EdgeInsets.all(10),
height: 120,
decoration: BoxDecoration(
border: Border.all(width: 2),
borderRadius: BorderRadius.circular(20),
),
child: Column(
children: [
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
],
),
),
],
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(10),
height: 120,
decoration: BoxDecoration(
border: Border.all(width: 2),
borderRadius: BorderRadius.circular(20),
),
child: Column(
children: [
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
],
),
),
SizedBox(width: 20),
Container(
padding: EdgeInsets.all(10),
height: 120,
decoration: BoxDecoration(
border: Border.all(width: 2),
borderRadius: BorderRadius.circular(20),
),
child: Column(
children: [
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
Text('Column Text Widget 1'),
],
),
),
],
),
],
),
),
);
}
}
4.Custom Widgets
main.dart
import 'userCard.dart';
import 'package:flutter/material.dart';
void main() async {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.red,
),
debugShowCheckedModeBanner: false,
initialRoute: '/customWidget',
routes: {'/customWidget': (context) => CustomWidget()},
);
}
}
userCard.dart
import 'customWidget.dart';
import 'package:flutter/material.dart';
class CustomWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Nesting Widget"),
),
body: Container(
height: 400,
alignment: Alignment.center,
child: UserCard(
name: 'Sadanand',
email: 'sadanand@gmail.com',
),
),
);
}
}
customWidget.dart
import 'package:flutter/material.dart';
class UserCard extends StatelessWidget {
final String name;
final String email;
const UserCard({required this.name, required this.email});
@override
Widget build(BuildContext context) {
return Card(
elevation: 4,
child: Container(
padding: EdgeInsets.all(50),
child: Column(
children: [
Text(
"Profile",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
SizedBox(height: 10),
Image.asset(
"assets/images/sam.jpg",
width: 200,
height: 150,
fit: BoxFit.cover,
),
SizedBox(height: 20),
Text(
name,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
SizedBox(height: 10),
RichText(
text: TextSpan(
text: email,
style: TextStyle(color: Colors.black, fontSize: 16),
),
),
],
),
),
);
}
}
5.Handling User Inputs.
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Login(),
debugShowCheckedModeBanner: false,
));
}
class Login extends StatelessWidget {
final TextEditingController emailController = TextEditingController();
final TextEditingController passwordController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Login'),
),
body: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
"assets/images/sam.jpg", // No 'assets/' prefix in code
height: 150,
width: 200,
),
SizedBox(height: 15),
TextField(
controller: emailController,
decoration: InputDecoration(
labelText: 'Email',
prefixIcon: Icon(Icons.email),
border: OutlineInputBorder(),
),
keyboardType: TextInputType.emailAddress,
),
SizedBox(height: 15),
TextField(
controller: passwordController,
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: Icon(Icons.lock),
border: OutlineInputBorder(),
),
obscureText: true,
),
SizedBox(height: 15),
ElevatedButton(
onPressed: () {
String email = emailController.text;
String password = passwordController.text;
print("Email: $email , Password: $password");
},
child: Text('Login'),
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
),
),
],
),
),
);
}
}
6. Login Screen with validation
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Login App',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
),
home: Login(),
);
}
class Login extends StatelessWidget {
final TextEditingController emailController = TextEditingController();
final TextEditingController passwordController = TextEditingController();
bool isValidEmail(String email) {
return RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(email);
}
bool isValidPassword(String password) {
return password.length >= 8;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Login'),
),
body: Padding(
padding: const EdgeInsets.all(15.0),
child: SingleChildScrollView(
child: Column(
children: [
Image.asset(
"assets/images/sam.jpg",
height: 150,
width: 200,
),
SizedBox(height: 15),
TextField(
controller: emailController,
decoration: InputDecoration(
labelText: 'Email',
prefixIcon: Icon(Icons.email),
border: OutlineInputBorder(),
),
keyboardType: TextInputType.emailAddress,
),
SizedBox(height: 15),
TextField(
controller: passwordController,
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: Icon(Icons.lock),
border: OutlineInputBorder(),
),
obscureText: true,
),
SizedBox(height: 15),
ElevatedButton(
onPressed: () {
String email = emailController.text;
String password = passwordController.text;
if (!isValidEmail(email)) {
print("Enter a Valid Email");
}
if (!isValidPassword(password)) {
print("Password must be at least 8 characters");
print("Email: $email , Password: $password");
},
child: Text('Login'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
)
],
),
),
),
);
}
}
7. Navigation Drawer
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Navigation Drawer Only',
theme: ThemeData(primarySwatch: Colors.deepPurple),
home: NavigationDrawerScreen(),
);
}
}
class NavigationDrawerScreen extends StatefulWidget {
@override
_NavigationDrawerScreenState createState() => _NavigationDrawerScreenState();
}
class _NavigationDrawerScreenState extends State<NavigationDrawerScreen> {
int _selectedIndex = 0;
static const List<Widget> _pages = <Widget>[
Center(
child: Text('🏠 Home Page', style: TextStyle(fontSize: 24)),
),
Center(
child: Text('🎬 Movies Page', style: TextStyle(fontSize: 24)),
),
Center(
child: Text('📺 Web Series Page', style: TextStyle(fontSize: 24)),
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
Navigator.pop(context); // Close the drawer
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(
decoration: BoxDecoration(
color: Colors.deepPurple,
),
child: Column(
children: [
CircleAvatar(
radius: 40,
child: Icon(Icons.person, size: 40),
),
SizedBox(height: 10),
Text(
'Sam',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
],
),
),
ListTile(
leading: Icon(Icons.home),
title: Text("Home"),
onTap: () => _onItemTapped(0),
),
ListTile(
leading: Icon(Icons.local_movies),
title: Text("Movies"),
onTap: () => _onItemTapped(1),
),
ListTile(
leading: Icon(Icons.live_tv),
title: Text("Web Series"),
onTap: () => _onItemTapped(2),
),
],
),
),
body: _pages[_selectedIndex],
);
}
}
8. Bottom Navigation
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Bottom Navigation Only',
theme: ThemeData(primarySwatch: Colors.deepPurple),
home: NavigationScreen(),
);
}
}
class NavigationScreen extends StatefulWidget {
@override
_NavigationScreenState createState() => _NavigationScreenState();
}
class _NavigationScreenState extends State<NavigationScreen> {
int _selectedIndex = 0;
static const List<Widget> _pages = <Widget>[
Center(
child: Text('🏠 Home Page', style: TextStyle(fontSize: 24)),
),
Center(
child: Text('🎬 Movies Page', style: TextStyle(fontSize: 24)),
),
Center(
child: Text('📺 Web Series Page', style: TextStyle(fontSize: 24)),
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
static const List<BottomNavigationBarItem> _navItems = [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.local_movies),
label: 'Movies',
),
BottomNavigationBarItem(
icon: Icon(Icons.live_tv),
label: 'Web Series',
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _pages[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
items: _navItems,
currentIndex: _selectedIndex,
selectedItemColor: Colors.deepPurple,
unselectedItemColor: Colors.grey,
onTap: _onItemTapped,
),
);
}
}
9.Covid Data
i. Covid Model
class CovidModel {
int? updated;
int? cases;
int? todayCases;
int? deaths;
int? todayDeaths;
int? recovered;
int? todayRecovered;
int? active;
int? critical;
int? casesPerOneMillion;
double? deathsPerOneMillion;
int? tests;
double? testsPerOneMillion;
int? population;
int? oneCasePerPeople;
int? oneDeathPerPeople;
int? oneTestPerPeople;
double? activePerOneMillion;
double? recoveredPerOneMillion;
double? criticalPerOneMillion;
int? affectedCountries;
CovidModel(
{this.updated,
this.cases,
this.todayCases,
this.deaths,
this.todayDeaths,
this.recovered,
this.todayRecovered,
this.active,
this.critical,
this.casesPerOneMillion,
this.deathsPerOneMillion,
this.tests,
this.testsPerOneMillion,
this.population,
this.oneCasePerPeople,
this.oneDeathPerPeople,
this.oneTestPerPeople,
this.activePerOneMillion,
this.recoveredPerOneMillion,
this.criticalPerOneMillion,
this.affectedCountries});
CovidModel.fromJson(Map<String, dynamic> json) {
updated = json['updated'];
cases = json['cases'];
todayCases = json['todayCases'];
deaths = json['deaths'];
todayDeaths = json['todayDeaths'];
recovered = json['recovered'];
todayRecovered = json['todayRecovered'];
active = json['active'];
critical = json['critical'];
casesPerOneMillion = json['casesPerOneMillion'];
deathsPerOneMillion = json['deathsPerOneMillion'];
tests = json['tests'];
testsPerOneMillion = json['testsPerOneMillion'];
population = json['population'];
oneCasePerPeople = json['oneCasePerPeople'];
oneDeathPerPeople = json['oneDeathPerPeople'];
oneTestPerPeople = json['oneTestPerPeople'];
activePerOneMillion = json['activePerOneMillion'];
recoveredPerOneMillion = json['recoveredPerOneMillion'];
criticalPerOneMillion = json['criticalPerOneMillion'];
affectedCountries = json['affectedCountries'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['updated'] = this.updated;
data['cases'] = this.cases;
data['todayCases'] = this.todayCases;
data['deaths'] = this.deaths;
data['todayDeaths'] = this.todayDeaths;
data['recovered'] = this.recovered;
data['todayRecovered'] = this.todayRecovered;
data['active'] = this.active;
data['critical'] = this.critical;
data['casesPerOneMillion'] = this.casesPerOneMillion;
data['deathsPerOneMillion'] = this.deathsPerOneMillion;
data['tests'] = this.tests;
data['testsPerOneMillion'] = this.testsPerOneMillion;
data['population'] = this.population;
data['oneCasePerPeople'] = this.oneCasePerPeople;
data['oneDeathPerPeople'] = this.oneDeathPerPeople;
data['oneTestPerPeople'] = this.oneTestPerPeople;
data['activePerOneMillion'] = this.activePerOneMillion;
data['recoveredPerOneMillion'] = this.recoveredPerOneMillion;
data['criticalPerOneMillion'] = this.criticalPerOneMillion;
data['affectedCountries'] = this.affectedCountries;
return data;
}
}
ii. CovidApi.dart
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:mystateful/model/CovidModel.dart';
class CovidApi {
Future<CovidModel?> fetchCovidData() async {
var apiUrl = Uri.parse('https://disease.sh/v3/covid-19/all');
var response = await http.get(apiUrl);
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
return CovidModel.fromJson(data);
} else {
throw Exception("Failed to fetch data");
}
}
}
iii. CovidData.dart
import 'package:flutter/material.dart';
import 'Services/CovidApi.dart';
import 'model/CovidModel.dart';
class CovidData extends StatefulWidget {
@override
_CovidDataState createState() => _CovidDataState();
}
class _CovidDataState extends State<CovidData> {
final CovidApi covidApi = CovidApi();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Covid Data'),
),
body: FutureBuilder<CovidModel?>(
future: covidApi.fetchCovidData(),
builder: (context, snapShot) {
if (snapShot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else if (snapShot.hasError) {
return Center(child: Text('Error in loading the data'));
} else if (!snapShot.hasData || snapShot.data == null) {
return Center(child: Text('No Data'));
}
var covidData = snapShot.data!;
List<Map<String, dynamic>> covidStat = [
{
'label': 'Covid Cases',
'icon': Icons.coronavirus,
'value': covidData.cases
},
{
'label': 'Deaths',
'icon': Icons.airline_seat_flat,
'value': covidData.deaths
},
{
'label': 'Critical Cases',
'icon': Icons.warning,
'value': covidData.critical
},
{
'label': 'Total Population',
'icon': Icons.people,
'value': covidData.population
},
{
'label': 'Recovered Today',
'icon': Icons.healing,
'value': covidData.todayRecovered
},
{
'label': 'Active',
'icon': Icons.local_hospital,
'value': covidData.active
},
];
return ListView.builder(
itemCount: covidStat.length,
itemBuilder: (context, index) {
var stat = covidStat[index];
return ListTile(
leading: Icon(stat['icon']),
title: Text(stat['label']),
trailing: Text(stat['value'].toString()),
);
},
);
},
),
);
}
}
iv. main.dart
import 'package:flutter/material.dart';
import 'CovidData.dart'; // Your CovidData screen
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Hello World',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: InitialRoutine(), // Start here
);
}
}
class InitialRoutine extends StatefulWidget {
@override
_InitialRoutineState createState() => _InitialRoutineState();
}
class _InitialRoutineState extends State<InitialRoutine> {
@override
void initState() {
super.initState();
// Simulate initialization logic
Future.delayed(Duration(seconds: 2), () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => CovidData()),
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 20),
Text("Initializing... Please wait")
],
),
),
);
}
}