Skip to content

Commit

Permalink
Adjust book layout for bigger screens
Browse files Browse the repository at this point in the history
  • Loading branch information
shockbytes committed Nov 28, 2023
1 parent 93fbb82 commit 5b21662
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/src/ui/main/book_state_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:dantex/src/data/book/entity/book_state.dart';
import 'package:dantex/src/providers/book.dart';
import 'package:dantex/src/ui/book/book_item_widget.dart';
import 'package:dantex/src/ui/core/generic_error_widget.dart';
import 'package:dantex/src/util/layout_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Expand Down Expand Up @@ -37,6 +38,20 @@ class _BooksScreen extends StatelessWidget {
);
}

return LayoutBuilder(
builder: (context, constraints) {
final DeviceFormFactor formFactor = getDeviceFormFactor(constraints);

return switch (formFactor) {
DeviceFormFactor.desktop => _buildLargeLayout(columns: 3),
DeviceFormFactor.tablet => _buildLargeLayout(columns: 2),
DeviceFormFactor.phone => _buildPhoneLayout(),
};
},
);
}

Widget _buildPhoneLayout() {
return ListView.separated(
padding: const EdgeInsets.all(16.0),
physics: const BouncingScrollPhysics(),
Expand All @@ -46,4 +61,20 @@ class _BooksScreen extends StatelessWidget {
const SizedBox(height: 16),
);
}

Widget _buildLargeLayout({
required int columns,
}) {
return GridView.builder(
padding: const EdgeInsets.all(16),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: columns,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 4,
),
itemBuilder: (context, index) => BookItemWidget(books[index]),
itemCount: books.length,
);
}
}

0 comments on commit 5b21662

Please sign in to comment.