Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored the download button and the more from author section #126

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class _BookDetailsScreenState extends ConsumerState<BookDetailsScreen> {
_MoreBooksFromAuthor(
authorUrl:
widget.entry.author!.uri!.t!.replaceAll(r'\&lang=en', ''),
entry: widget.entry,
),
const SizedBox(height: 30.0),
],
Expand Down Expand Up @@ -197,13 +198,7 @@ class _BookDescriptionSection extends StatelessWidget {
),
const SizedBox(height: 5.0),
_CategoryChips(entry: entry),
Center(
child: SizedBox(
height: 50.0,
width: MediaQuery.of(context).size.width,
child: _DownloadButton(entry: entry),
),
),
_DownloadButton(entry: entry),
],
),
),
Expand Down Expand Up @@ -281,11 +276,16 @@ class _DownloadButton extends ConsumerWidget {
final book = books.firstWhere((element) => element['id'] == id);
return TextButton(
onPressed: () => openBook(book['path'] as String, context, ref),
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
),
child: Text(
'Read Book'.toUpperCase(),
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: context.theme.textTheme.titleLarge?.color ?? Colors.black,
decoration: TextDecoration.underline,
),
),
);
Expand All @@ -294,6 +294,9 @@ class _DownloadButton extends ConsumerWidget {
}

Widget _downloadButton(BuildContext context) => TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
),
onPressed: () {
DownloadAlert.show(
context: context,
Expand All @@ -307,7 +310,9 @@ class _DownloadButton extends ConsumerWidget {
'Download'.toUpperCase(),
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: context.theme.textTheme.titleLarge?.color ?? Colors.black,
decoration: TextDecoration.underline,
),
),
);
Expand Down Expand Up @@ -356,9 +361,11 @@ class _SectionTitle extends StatelessWidget {

class _MoreBooksFromAuthor extends ConsumerStatefulWidget {
final String authorUrl;
final Entry entry;

const _MoreBooksFromAuthor({
required this.authorUrl,
required this.entry,
});

@override
Expand Down Expand Up @@ -394,18 +401,45 @@ class _MoreBooksFromAuthorState extends ConsumerState<_MoreBooksFromAuthor> {
loading: () => const LoadingWidget(),
data: (related) {
if (related.feed!.entry == null || related.feed!.entry!.isEmpty) {
return const Text('Empty');
return const Center(
child: Padding(
padding: EdgeInsets.only(top: 50.0),
child: Text(
'Empty',
),
),
);
}
final entries = related.feed!.entry!;
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: related.feed!.entry!.length,
itemBuilder: (BuildContext context, int index) {
final entry = related.feed!.entry![index];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: BookListItem(entry: entry),
);
final entry = entries[index];
final isSingleEntry = entries.length == 1;
if (entry.id!.t == widget.entry.id!.t && isSingleEntry) {
return const Center(
child: Padding(
padding: EdgeInsets.only(top: 40.0),
child: Text(
"oops, there's no other book from this author available",
style: TextStyle(
fontSize: 16,
),
textAlign: TextAlign.center,
),
),
);
} else if (entry.id!.t == widget.entry.id!.t) {
return const SizedBox
.shrink(); // Skip rendering the current entry
} else {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: BookListItem(entry: entry),
);
}
},
);
},
Expand Down