Ad
Flutter. How To Collapse GridView.builder When It Empty (do Not Have Any Elements)
I have a GridView.builder with shrinkWrap to true. It fills dynamically, but the problem that at start it empty but takes place, like it has elements (sort of reserving place) depends on the size of maxCrossAxisExtent. Is it possible change this? Empty space not very good.. I looked docs and google but didnt find any answer.
This is the code
class _PhotosState extends State<Photos> {
List<File> photos = [];
final ImagePicker _picker = ImagePicker();
Widget getGrid() {
return Container(
child: GridView.builder(
padding: EdgeInsets.all(0),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
//childAspectRatio: 3 / 2,
// crossAxisSpacing: 10,
// mainAxisSpacing: 10,
//mainAxisExtent: 200,
),
itemCount: photos.length,
itemBuilder: (BuildContext ctx, index) {
return Container(
color: Colors.blueGrey,
);
},
),
);
}
Ad
Answer
try
Widget getGrid() {
return photos.length<1?SizedBox():
Container(
child: GridView.builder(
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad