Mobile Application Development LAB Programs[2][1]
Mobile Application Development LAB Programs[2][1]
Lab Programs
1. Create a stateless widget and use initialRoute to launch one screen as the
starting screen.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
},
);
@override
return Scaffold(
body: Center(
child: RaisedButton(
Mobile Application Development Lab
onPressed: () {
Navigator.pushNamed(context, '/second');
},
),
),
);
@override
return Scaffold(
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
),
),
);
}
Mobile Application Development Lab
Mobile Application Development Lab
2. Create a stateless widget program to load an image from the assets folder and
display it on the screen.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
debugShowCheckedModeBanner: false,
home: ImageScreen(),
);
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: Image.asset(
),
),
);
}
Mobile Application Development Lab
Mobile Application Development Lab
3. Create a stateless widget form with fields for Name, Email, Phone, and Message,
and a "Submit" button. Print "Form Submitted" on submit.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
debugShowCheckedModeBanner: false,
home: ContactForm(),
);
@override
return Scaffold(
appBar: AppBar(
Mobile Application Development Lab
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
controller: nameController,
decoration: InputDecoration(
labelText: 'Name',
border: OutlineInputBorder(),
),
),
SizedBox(height: 10),
TextField(
controller: emailController,
decoration: InputDecoration(
labelText: 'Email',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.emailAddress,
),
SizedBox(height: 10),
TextField(
controller: phoneController,
Mobile Application Development Lab
decoration: InputDecoration(
labelText: 'Phone',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.phone,
),
SizedBox(height: 10),
TextField(
controller: messageController,
decoration: InputDecoration(
labelText: 'Message',
border: OutlineInputBorder(),
),
maxLines: 3,
),
SizedBox(height: 20),
Center(
child: RaisedButton(
onPressed: () {
print("Form Submitted");
},
child: Text('Submit'),
color: Colors.blue,
textColor: Colors.white,
),
),
],
), ), ); } }
Mobile Application Development Lab
Mobile Application Development Lab
4. Create a stateless widget form with Name, Email, Phone, and Message fields.
Validate inputs of all fields and print "Form Submitted" on submit.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
debugShowCheckedModeBanner: false,
home: ContactForm(),
);
if (value.isEmpty) {
Mobile Application Development Lab
if (!regex.hasMatch(value)) {
return null;
if (value.isEmpty) {
if (!regex.hasMatch(value)) {
return null;
@override
return Scaffold(
appBar: AppBar(
),
body: SingleChildScrollView(
child: Form(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
controller: nameController,
decoration: InputDecoration(
labelText: 'Name',
border: OutlineInputBorder(),
),
validator: (value) {
if (value.isEmpty) {
return null;
},
),
SizedBox(height: 10),
TextFormField(
controller: emailController,
decoration: InputDecoration(
labelText: 'Email',
Mobile Application Development Lab
border: OutlineInputBorder(),
),
keyboardType: TextInputType.emailAddress,
validator: _validateEmail,
),
SizedBox(height: 10),
TextFormField(
controller: phoneController,
decoration: InputDecoration(
labelText: 'Phone',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.phone,
validator: _validatePhone,
),
SizedBox(height: 10),
// Message Field
TextFormField(
controller: messageController,
decoration: InputDecoration(
labelText: 'Message',
border: OutlineInputBorder(),
),
maxLines: 3,
),
Mobile Application Development Lab
SizedBox(height: 20),
Center(
child: MaterialButton(
onPressed: () {
if (_formKey.currentState.validate()) {
print("Form Submitted");
} else {
},
child: Text('Submit'),
color: Colors.blue,
textColor: Colors.white,
),
),
],
),
),
),
);
}
Mobile Application Development Lab
Mobile Application Development Lab
5. Create a stateless widget program to add the Google Fonts package from
pub.dev to the project and display a text widget using a Google fonts.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
debugShowCheckedModeBanner: false,
home: FontDisplayScreen(),
);
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: Text(
Mobile Application Development Lab
'Lato-Regular',
),
),
);
}
Mobile Application Development Lab
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: Scaffold(
appBar: AppBar(
),
body: Padding(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
],
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
],
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
],
),
],
),
),
),
);
}
Mobile Application Development Lab
Mobile Application Development Lab
7. Design a login screen with fields for "Username" and "Password" and a "Submit"
button.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
debugShowCheckedModeBanner: false,
home: LoginScreen(),
);
@override
return Scaffold(
appBar: AppBar(
),
Mobile Application Development Lab
body: Padding(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Username Field
TextField(
controller: usernameController,
decoration: InputDecoration(
labelText: 'Username',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.person),
),
),
// Password Field
TextField(
controller: passwordController,
decoration: InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.lock),
),
),
// Submit Button
RaisedButton(
onPressed: () {
print('Username: $username');
print('Password: $password');
},
color: Colors.blue,
textColor: Colors.white,
child: Text('Submit'),
),
],
),
),
);
}
Mobile Application Development Lab
Mobile Application Development Lab
8. Create an app with two screens and navigate between them using the Navigator.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
debugShowCheckedModeBanner: false,
);
// First Screen
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: RaisedButton(
Mobile Application Development Lab
onPressed: () {
Navigator.push(
context,
);
},
color: Colors.blue,
textColor: Colors.white,
),
),
);
// Second Screen
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
color: Colors.green,
textColor: Colors.white,
),
),
);
}
Mobile Application Development Lab
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: BottomNavScreen(),
);
@override
int _selectedIndex = 0;
Screen1(),
Screen2(),
Screen3(),
Mobile Application Development Lab
];
setState(() {
_selectedIndex = index;
});
@override
return Scaffold(
appBar: AppBar(
),
body: _screens[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
onTap: _onItemTapped,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
),
BottomNavigationBarItem(
Mobile Application Development Lab
icon: Icon(Icons.settings),
),
],
),
);
@override
@override
@override
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: NavigationDrawerScreen(),
);
@override
return Scaffold(
appBar: AppBar(
),
drawer: Drawer(
child: ListView(
Mobile Application Development Lab
children: <Widget>[
UserAccountsDrawerHeader(
accountEmail: Text('[email protected]'),
currentAccountPicture: CircleAvatar(
backgroundColor: Colors.orange,
),
),
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
onTap: () {
Navigator.push(
context,
);
},
),
ListTile(
leading: Icon(Icons.search),
title: Text('Search'),
onTap: () {
Navigator.push(
context,
Mobile Application Development Lab
);
},
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
onTap: () {
Navigator.push(
context,
);
},
),
],
),
),
);
@override
return Scaffold(
Mobile Application Development Lab
);
@override
return Scaffold(
);
@override
return Scaffold(
);
}
Mobile Application Development Lab
Mobile Application Development Lab