I'm currently using SliverStaggeredGrid to build my appication but since it has been removed I am unable to use it not can find any other code that has replaced it. I tried using a lower version but since flutter creates certain dependencies, I was unable to use the lower version. How do I get about this:
This is the code for the SliverStaggeredGrid:
: SliverStaggeredGrid.countBuilder(
staggeredTileBuilder: (c) => const StaggeredTile.count(1, 1.5),
crossAxisCount: 2,
mainAxisSpacing: 1,
crossAxisSpacing: 0,
itemBuilder: (context, index) {
Items model = Items.fromJson(
snapshot.data!.docs[index].data()!
as Map<String, dynamic>);
return Padding(
padding: const EdgeInsets.all(8.0),
child: ItemsDesign(
model: model,
context: context,
),
);
},
itemCount: snapshot.data!.docs.length,
);
EDIT:
Dependencies version:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
firebase_core: ^2.17.0
firebase_auth: ^4.10.1
cloud_firestore: ^4.9.3
firebase_storage: ^11.2.8
shared_preferences: ^2.0.11
flutter_staggered_grid_view: ^0.7.0
fluttertoast: ^8.0.8
google_fonts: ^6.1.0
hexcolor: ^3.0.1
lottie: ^2.6.0
image_picker: ^1.0.4
geolocator: ^10.1.0
geocoding: ^2.0.1
intl: ^0.18.1
Error that is currently showing:
Undefined name 'SliverStaggeredGrid'. Try correcting the name to one that is defined, or defining the name.
The name 'fit' isn't a class. Try correcting the name to match an existing class.
Flutter Doctor results:
[✓] Flutter (Channel master, 3.16.0-10.0.pre.20, on macOS 14.0 23A344 darwin-arm64, locale en-TZ)
• Flutter version 3.16.0-10.0.pre.20 on channel master at /Users/mustafa/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ec94ccff83 (31 hours ago), 2023-10-11 07:41:40 -0400
• Engine revision bddb34b09c
• Dart version 3.3.0 (build 3.3.0-6.0.dev)
• DevTools version 2.28.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at /Users/mustafa/Library/Android/sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15A240d
• CocoaPods version 1.13.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
[✓] VS Code (version 1.83.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.74.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.0 23A344 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 117.0.5938.149
This probably isn't an answer you want to hear, but you probably can't use SliverStaggeredGrid as-is any more.
You might have to switch to newer code from a plugin, for example flutter_staggered_grid_view
or masonry_grid
. I believe SliverQuiltedGridDeletate
in the flutter_staggered_grid_view package probably does what you need.
An alternative could be to copy the source code for SliverStaggeredGrid
directly into your project or fork the plugin (assuming it's coming from a plugin) and update only what you need - as long as you can update it for the most recent flutter version it should work, but there's probably a good reason for it being deprecated so I wouldn't recommend it.