aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/screens/chat_screen.dart12
-rw-r--r--lib/screens/dashboard_screen.dart7
-rw-r--r--lib/screens/new_chat_screen.dart5
-rw-r--r--lib/widgets/cached_avatar.dart22
4 files changed, 33 insertions, 13 deletions
diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart
index 61f3f9e..64f8621 100644
--- a/lib/screens/chat_screen.dart
+++ b/lib/screens/chat_screen.dart
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:linkchat/firebase/auth.dart';
import 'package:linkchat/firebase/database.dart';
import 'package:linkchat/models/group.dart';
+import 'package:linkchat/widgets/cached_avatar.dart';
import '../models/favorite.dart';
import '../models/message.dart';
@@ -42,11 +43,12 @@ class _ChatScreenState extends State<ChatScreen> {
leadingWidth: 30,
title: Row(
children: [
- ClipRRect(
- borderRadius: BorderRadius.circular(30),
- child: CircleAvatar(
- backgroundImage: NetworkImage(user!.photoUrl),
- )),
+ // ClipRRect(
+ // borderRadius: BorderRadius.circular(30),
+ // child: CircleAvatar(
+ // backgroundImage: NetworkImage(user!.photoUrl),
+ // )),
+ CachedAvatar(user?.photoUrl),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(user!.displayName),
diff --git a/lib/screens/dashboard_screen.dart b/lib/screens/dashboard_screen.dart
index 97a9de6..4905b84 100644
--- a/lib/screens/dashboard_screen.dart
+++ b/lib/screens/dashboard_screen.dart
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
+import 'package:linkchat/widgets/cached_avatar.dart';
import 'package:provider/provider.dart';
import '../firebase/auth.dart';
@@ -49,11 +50,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
child: ListView(
children: [
UserAccountsDrawerHeader(
- currentAccountPicture: CircleAvatar(
- backgroundImage: _auth.currentUser?.photoURL != null
- ? NetworkImage(_auth.currentUser!.photoURL!)
- : null,
- ),
+ currentAccountPicture: CachedAvatar(_auth.currentUser?.photoURL),
accountName: Text(_auth.currentUser?.displayName ?? "Lincite"),
accountEmail: _auth.currentUser?.email != null
? Text(_auth.currentUser!.email!)
diff --git a/lib/screens/new_chat_screen.dart b/lib/screens/new_chat_screen.dart
index bf7486f..3c37f2c 100644
--- a/lib/screens/new_chat_screen.dart
+++ b/lib/screens/new_chat_screen.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:linkchat/firebase/database.dart';
import 'package:linkchat/models/group.dart';
+import 'package:linkchat/widgets/cached_avatar.dart';
import '../firebase/auth.dart';
import '../models/user.dart';
@@ -71,9 +72,7 @@ class _NewChatScreenState extends State<NewChatScreen> {
itemBuilder: (context, index) {
FsUser user = filteredUsers[index];
return ListTile(
- leading: CircleAvatar(
- backgroundImage: NetworkImage(user.photoUrl),
- ),
+ leading: CachedAvatar(user.photoUrl),
title: Text(user.displayName),
trailing: IconButton(
icon: const Icon(Icons.send),
diff --git a/lib/widgets/cached_avatar.dart b/lib/widgets/cached_avatar.dart
new file mode 100644
index 0000000..e6fcf89
--- /dev/null
+++ b/lib/widgets/cached_avatar.dart
@@ -0,0 +1,22 @@
+import 'package:cached_network_image/cached_network_image.dart';
+import 'package:flutter/material.dart';
+
+class CachedAvatar extends StatelessWidget {
+ final String? avatarUrl;
+ const CachedAvatar(this.avatarUrl, {super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return CircleAvatar(
+ backgroundImage:
+ avatarUrl != null ? CachedNetworkImageProvider(avatarUrl!) : null,
+ backgroundColor: Theme.of(context).colorScheme.primary,
+ child: avatarUrl == null
+ ? Icon(
+ Icons.person,
+ color: Theme.of(context).colorScheme.onPrimary,
+ )
+ : null,
+ );
+ }
+}