Untitled
unknown
plain_text
a month ago
1.8 kB
8
Indexable
// LAB 2 - Flutter App that displays an asset image
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Lab 2 - Image Display',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const ImagePage(),
);
}
}
class ImagePage extends StatelessWidget {
const ImagePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Hello'),
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
backgroundColor: Colors.blue,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/my_image.jpg',
width: double.infinity,
height: 300,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Container(
width: double.infinity,
height: 300,
color: Colors.green.shade800,
child: const Center(
child: Text(
'Add your image to assets folder\nand update pubspec.yaml',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white, fontSize: 16),
),
),
);
},
),
],
),
),
);
}
}
Editor is loading...
Leave a Comment