I'm encountering performance issues with animations in my Flutter app after transitioning from using FutureBuilder
to StreamBuilder
and integrating StreamProvider to fetch data dynamically from Firebase Firestore
.
I've tried running in release mode. The animations still seem to be very junky and delayed. I'm using https://pub.dev/packages/flutter_animate for animations.
Interestingly, reverting to FutureBuilder
restores normal animation behavior.
Any guidance or potential solutions to optimize animation performance while leveraging Firestore streams would be greatly appreciated.
Thanks in advance
Here's a snippet of my database service fetching the data:
class DatabaseService {
final FirebaseFirestore _db = FirebaseFirestore.instance;
Stream<List<Person>> streamBirthdays() {
return _db.collection('birthdays').snapshots().map((result) {
return result.docs.map((doc) {
final person = Person.fromJson(doc.data());
person.id = doc.id;
return person;
}).toList();
});
}
}
In my app's setup, I'm using MultiProvider to manage different providers, including a StreamProvider:
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => settingsController),
StreamProvider<List<Person>>(
create: (context) => databaseService.streamBirthdays(),
initialData: initialData,
),
],
child: MyApp(
settingsController: settingsController,
savedThemeMode: savedTterhemeMode,
),
),
);
Within my UI, I consume the stream and play animations:
return Consumer<List<Person>>(
builder: (context, birthdayList, _) {
if (birthdayList.isEmpty) {
return Center(
child: Text(
message,
),
).animate().fadeIn();
}
return BirthdayListOld(birthdays: birthdayList);
},
);