Gridview padding changes based on target

I’m working on a Flutter project where I have a PageView with three children. Each child contains a LayoutBuilder that builds a GridView.

When I don’t specify any padding, the grid looks like this:

However, when I add padding directly to the GridView or wrap it with padding, everything looks correct on a desktop screen, but on mobile devices, there’s extra padding or space at the bottom of the grid.

Desktop View (Correct): The layout appears as expected, with consistent padding around the grid.

Mobile View (Incorrect): On mobile devices (and Raspberry Pi using Flutter-pi), the same grid has extra space below the last row, even though no additional padding is set there.

Question:
Why does the layout behave differently on mobile devices compared to desktop, and how can I ensure a consistent UI across all platforms, including when embedded on a Raspberry Pi using Flutter-pi?

class MainPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        margin: const EdgeInsets.symmetric(
          vertical: 50.0,
        ),
        child: PageView(
          controller: PageController(
            initialPage: 0,
            viewportFraction: 0.9,
          ),
          children: const [
            GrindBuilderBeverages(
              backgroundColor: Colors.redAccent,
              rows: 4,
              columns: 4,
              crossAxisSpacing: 15.0,
              mainAxisSpacing: 20.0,
            ),
            GrindBuilderBeverages(
              backgroundColor: Colors.purpleAccent,
              rows: 3,
              columns: 3,
              crossAxisSpacing: 10.0,
              mainAxisSpacing: 10.0,
            ),
            GrindBuilderBeverages(
              backgroundColor: Colors.greenAccent,
              rows: 2,
              columns: 5,
              crossAxisSpacing: 5.0,
              mainAxisSpacing: 5.0,
            ),
          ],
        ),
      ),
    );
  }
}

class GrindBuilderBeverages extends StatelessWidget {
  final Color backgroundColor;
  final int rows;
  final int columns;
  final double crossAxisSpacing;
  final double mainAxisSpacing;

  const GrindBuilderBeverages(
      {super.key,
      required this.backgroundColor,
      required this.rows,
      required this.columns,
      required this.crossAxisSpacing,
      required this.mainAxisSpacing});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16.0),
      decoration: BoxDecoration(
        color: backgroundColor,
        borderRadius: BorderRadius.circular(16.0),
      ),
      child: LayoutBuilder(
        builder: (context, constraints) {
          // Calculate the childAspectRatio based on the available width and height
          final double totalHorizontalSpacing = (columns - 1) * crossAxisSpacing;
          final double totalVerticalSpacing = (rows - 1) * mainAxisSpacing;

          final double itemWidth =
              (constraints.maxWidth - totalHorizontalSpacing) / columns;
          final double itemHeight =
              (constraints.maxHeight - totalVerticalSpacing) / rows;
          final double aspectRatio = itemWidth / itemHeight;

          return GridView.builder(
            padding: const EdgeInsets.all(16.0),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: columns, // Set the number of columns
              childAspectRatio: aspectRatio, // Dynamic aspect ratio
              crossAxisSpacing: crossAxisSpacing, // Horizontal spacing
              mainAxisSpacing: mainAxisSpacing, // Vertical spacing
            ),
            itemCount: rows * columns, // Total number of items
            itemBuilder: (context, index) {
              return Container(
                color: Colors.white.withOpacity(0.5),
                child: Center(
                  child: Text(
                    'Item $index',
                    style: const TextStyle(color: Colors.black),
                  ),
                ),
              );
            },
          );
        },
      ),
    );
  }
}

A simple solution would be to change the code according to the platform, you can do such a thing by using the 'dart:io' library.

here is an example:

import'dart:io' show Platform;
void main(){
   if(Platform.isIOS){
     //make the Grid for the IOS
   }else if(Platform.isAndroid){
     //make the Grid for the Android
   }else if (Platform.isWindows) {
     // make the Grid for the Windows
   }else if(Platform.isMacOS){
     //make the Grid for the MacOS
}

And you can explore more and learn how to use it from the Flutter documentation for sure: https://flutter.dev/

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật