Mad Lab 06 023
Mad Lab 06 023
Lab 6
{SP22-BSE-023}
Class: BSE-7A
Problem:
• Add three different images to your app and stack them vertically using a Column.
void main() {
runApp(MyApp());
}
OUTPUT:
Task 2: Display an Image with a Fixed Size
Problem:
• Show an image on the screen with a fixed width of 150 pixels and a height of 200
pixels.
void main() {
runApp(MyApp());
}
Output:
Task 3: Display an Image Inside a Circle
Problem:
void main() {
runApp(MyApp());
}
OUTPUT:
Task 4: Add a Border Around the Image
Problem:
void main() {
runApp(MyApp());
}
Problem:
void main() {
runApp(MyApp());
}
OUTPUT:
Problem:
• Add two images and a button. When you click the button, the image should change.
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
void changeImage() {
setState(() {
currentImage = currentImage == "assets/images/image1.jpg"
? "assets/images/image2.jpg"
: "assets/images/image1.jpg";
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/image1.jpg"),
fit: BoxFit.cover,
),
),
child: Center(
child: Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.8),
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 3,
blurRadius: 7,
offset: Offset(0, 3),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Change Image Example",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.blueGrey,
),
),
SizedBox(height: 10),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 5),
),
child: Image.asset(
currentImage,
width: 150,
height: 200,
fit: BoxFit.cover,
),
),
SizedBox(height: 10),
ElevatedButton(
onPressed: changeImage,
child: Text("Change Image"),
),
],
),
),
),
),
),
);
}
}
OUTPUT:
Problem:
void main() {
runApp(MyApp());
}
void changeImage() {
setState(() {
currentImage = currentImage == "assets/images/image1.jpg"
? "assets/images/image2.jpg"
: "assets/images/image1.jpg";
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/image1.png"),
fit: BoxFit.cover,
),
),
child: Center(
child: Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.8),
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 3,
blurRadius: 7,
offset: Offset(0, 3),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Load Image from Internet",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.blueGrey,
),
),
SizedBox(height: 10),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 5),
),
child: Image.network(
"https://www.shutterstock.com/shutterstock/photos/219824502
9/display_1500/stock-photo-autumn-nature-landscape-lake-bridge-in-fall-forest-
path-way-in-gold-woods-romantic-view-image-2198245029.jpg",
width: 150,
height: 200,
fit: BoxFit.cover,
),
),
],
),
),
),
),
),
);
}
}
OUTPUT: