Amol Flutter
Amol Flutter
of
by
Amol Rathod
01FE23MCA053
May- 2025
SL.NO Program Date
Create a UI layout using built-in widgets such as Column, Row, Container using
3 13/03/2025
stateless
5 Create Login screen, handle user input and gestures in Flutter app 27/03/2025
void main() {
stdout.write('Enter first number: ');
String? input1 = stdin.readLineSync();
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;
}
case 'multiply':
int product = 1;
for (int i = 0; i < numbers.length; i++) {
product *= numbers[i];
}
print('Product of numbers: $product');
break;
default:
void main() {
runApp(MyApp());
}
);
}
}
@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'),
SizedBox(width: 20),
Container(
padding: EdgeInsets.all(10),
height: 120,
decoration: BoxDecoration(
],
),
),
],
),
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'),
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';
theme: ThemeData(
primarySwatch: Colors.red,
),
debugShowCheckedModeBanner: false,
initialRoute: '/customWidget',
userCard.dart
import 'customWidget.dart';
import 'package:flutter/material.dart';
appBar: AppBar(
title: Text("Nesting Widget"),
),
body: Container(
height: 400,
alignment: Alignment.center,
child: UserCard(
name: 'Sadanand',
email: '[email protected]',
),
),
);
}
}
customWidget.dart
import 'package:flutter/material.dart';
@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,
));
}
@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());
}
primarySwatch: Colors.red,
),
home: Login(),
);
}
@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)) {
if (!isValidPassword(password)) {
print("Password must be at least 8 characters");
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
)
],
),
),
),
);
}
}
7. Navigation Drawer
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
);
}
}
@override
_NavigationDrawerScreenState createState() => _NavigationDrawerScreenState();
}
int _selectedIndex = 0;
Center(
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"),
),
body: _pages[_selectedIndex],
);
}
}
8. Bottom Navigation
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
);
}
}
@override
_NavigationScreenState createState() => _NavigationScreenState();
}
int _selectedIndex = 0;
Center(
setState(() {
_selectedIndex = index;
});
}
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});
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'];
}
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 {
if (response.statusCode == 200) {
import 'package:flutter/material.dart';
import 'Services/CovidApi.dart';
import 'model/CovidModel.dart';
@override
_CovidDataState createState() => _CovidDataState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Covid Data'),
),
body: FutureBuilder<CovidModel?>(
future: covidApi.fetchCovidData(),
'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());
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Hello World',
theme: ThemeData(
primarySwatch: Colors.blue,
),
);
});
}
@override
children: [
CircularProgressIndicator(),
SizedBox(height: 20),
Text("Initializing... Please wait")
],
),
),
);
}
}