-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebase_storage_image.txt
More file actions
61 lines (56 loc) · 1.58 KB
/
firebase_storage_image.txt
File metadata and controls
61 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import 'package:flutter/material.dart';
import 'package:firebase_storage/firebase_storage.dart';
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
late String imageUrl;
bool isLoading = true; // Track loading state
final storage = FirebaseStorage.instance;
@override
void initState() {
super.initState();
imageUrl = '';
loadProfileImage();
}
Future<void> loadProfileImage() async {
try {
final ref = storage.ref().child('profile_images.png');
final url = await ref.getDownloadURL();
setState(() {
imageUrl = url;
isLoading = false; // Set loading to false once the image is loaded
});
} catch (e) {
print("Error loading image: $e");
setState(() {
isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Home')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
isLoading
? CircularProgressIndicator() // Show loading indicator
: SizedBox(
height: 300,
child: Image(
image: NetworkImage(imageUrl),
fit: BoxFit.cover,
),
),
SizedBox(height: 20), // Space between image and text
Text('Welcome! You are logged in.'),
],
),
),
);
}
}