Skip to content

Commit

Permalink
feat: Improved cover edit bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-bak committed Apr 22, 2024
1 parent 05fc03f commit 1522706
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 146 deletions.
68 changes: 0 additions & 68 deletions lib/ui/add_book_screen/widgets/cover_option_button.dart

This file was deleted.

111 changes: 34 additions & 77 deletions lib/ui/add_book_screen/widgets/cover_view_edit.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// ignore_for_file: use_build_context_synchronously

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand All @@ -9,15 +11,16 @@ import 'package:image_picker/image_picker.dart';
import 'package:blurhash_dart/blurhash_dart.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:openreads/core/helpers/helpers.dart';
import 'package:openreads/model/book.dart';
import 'package:openreads/resources/open_library_service.dart';

import 'package:openreads/core/constants/constants.dart';
import 'package:openreads/core/themes/app_theme.dart';
import 'package:openreads/generated/locale_keys.g.dart';
import 'package:openreads/logic/cubit/edit_book_cubit.dart';
import 'package:openreads/main.dart';
import 'package:openreads/ui/add_book_screen/widgets/edit_cover_options.dart';
import 'package:openreads/ui/add_book_screen/widgets/widgets.dart';
import 'package:openreads/ui/search_covers_screen/search_covers_screen.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -85,16 +88,9 @@ class _CoverViewEditState extends State<CoverViewEdit> {
_setCoverLoading(false);
}

void _editCurrentCover({
required BuildContext context,
bool pop = true,
}) async {
void _editCurrentCover(BuildContext context) async {
_setCoverLoading(true);

if (pop) {
Navigator.of(context).pop();
}

final cover = context.read<EditBookCoverCubit>().state;

if (cover == null) {
Expand Down Expand Up @@ -213,74 +209,35 @@ class _CoverViewEditState extends State<CoverViewEdit> {
showCoverLoadBottomSheet(BuildContext context) {
FocusManager.instance.primaryFocus?.unfocus();

showModalBottomSheet(
context: context,
isScrollControlled: true,
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
builder: (modalContext) {
return Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 10),
Container(
height: 3,
width: MediaQuery.of(context).size.width / 4,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(10),
),
),
Container(
padding: const EdgeInsets.fromLTRB(10, 30, 10, 60),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
CoverOptionButton(
text: LocaleKeys.load_cover_from_phone.tr(),
icon: FontAwesomeIcons.mobile,
onPressed: () => _loadCoverFromStorage(context),
),
const SizedBox(height: 15),
CoverOptionButton(
text: LocaleKeys.searchOnlineForCover.tr(),
icon: FontAwesomeIcons.magnifyingGlass,
onPressed: () => _searchForCoverOnline(context),
),
const SizedBox(height: 15),
CoverOptionButton(
text: LocaleKeys.get_cover_from_open_library.tr(),
icon: FontAwesomeIcons.globe,
onPressed: () => _loadCoverFromOpenLibrary(context),
),
BlocBuilder<EditBookCubit, Book>(
builder: (blocContext, state) {
if (state.hasCover) {
return Column(
children: [
const SizedBox(height: 15),
CoverOptionButton(
text: LocaleKeys.edit_current_cover.tr(),
icon: FontAwesomeIcons.image,
onPressed: () => _editCurrentCover(
context: context,
),
),
],
);
} else {
return const SizedBox();
}
},
),
],
),
),
],
);
},
);
if (Platform.isIOS) {
showCupertinoModalBottomSheet(
context: context,
expand: false,
builder: (_) {
return EditCoverOptions(
loadCoverFromStorage: _loadCoverFromStorage,
searchForCoverOnline: _searchForCoverOnline,
loadCoverFromOpenLibrary: _loadCoverFromOpenLibrary,
editCurrentCover: _editCurrentCover,
);
},
);
} else if (Platform.isAndroid) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
builder: (modalContext) {
return EditCoverOptions(
loadCoverFromStorage: _loadCoverFromStorage,
searchForCoverOnline: _searchForCoverOnline,
loadCoverFromOpenLibrary: _loadCoverFromOpenLibrary,
editCurrentCover: _editCurrentCover,
);
},
);
}
}

@override
Expand Down
93 changes: 93 additions & 0 deletions lib/ui/add_book_screen/widgets/edit_cover_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:openreads/generated/locale_keys.g.dart';
import 'package:openreads/logic/cubit/edit_book_cubit.dart';
import 'package:openreads/model/book.dart';

class EditCoverOptions extends StatelessWidget {
const EditCoverOptions({
super.key,
required this.loadCoverFromStorage,
required this.searchForCoverOnline,
required this.loadCoverFromOpenLibrary,
required this.editCurrentCover,
});

final Function(BuildContext) loadCoverFromStorage;
final Function(BuildContext) searchForCoverOnline;
final Function(BuildContext) loadCoverFromOpenLibrary;
final Function(BuildContext) editCurrentCover;

@override
Widget build(BuildContext context) {
return Material(
child: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
if (Platform.isIOS)
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Container(
height: 5,
width: 40,
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.onSurfaceVariant
.withOpacity(0.4),
borderRadius: BorderRadius.circular(50),
),
),
),
ListTile(
title: Text(LocaleKeys.load_cover_from_phone.tr()),
leading: FaIcon(
FontAwesomeIcons.mobile,
color: Theme.of(context).colorScheme.primary,
),
onTap: () => loadCoverFromStorage(context),
),
ListTile(
title: Text(LocaleKeys.searchOnlineForCover.tr()),
leading: FaIcon(
FontAwesomeIcons.magnifyingGlass,
color: Theme.of(context).colorScheme.primary,
),
onTap: () => searchForCoverOnline(context),
),
ListTile(
title: Text(LocaleKeys.get_cover_from_open_library.tr()),
leading: FaIcon(
FontAwesomeIcons.globe,
color: Theme.of(context).colorScheme.primary,
),
onTap: () => loadCoverFromOpenLibrary(context),
),
BlocBuilder<EditBookCubit, Book>(
builder: (blocContext, state) {
if (state.hasCover) {
return ListTile(
title: Text(LocaleKeys.edit_current_cover.tr()),
leading: FaIcon(
FontAwesomeIcons.image,
color: Theme.of(context).colorScheme.primary,
),
onTap: () => editCurrentCover(context),
);
} else {
return const SizedBox();
}
},
),
],
),
),
);
}
}
1 change: 0 additions & 1 deletion lib/ui/add_book_screen/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export 'book_rating_bar.dart';
export 'tags_text_field.dart';
export 'book_type_dropdown.dart';
export 'reading_row.dart';
export 'cover_option_button.dart';
export 'duck_duck_go_alert.dart';

0 comments on commit 1522706

Please sign in to comment.