-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0c0bba
commit 961afb4
Showing
7 changed files
with
235 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:flipub/data/book_library.dart'; | ||
import 'package:flipub/data/constants.dart'; | ||
import 'package:flipub/presentation/library/views/library_tile.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class BookGridView extends StatelessWidget { | ||
const BookGridView({ | ||
super.key, | ||
required this.library, | ||
}); | ||
|
||
final BookLibrary library; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GridView.builder( | ||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | ||
crossAxisCount: MediaQuery.of(context).isPortrait ? 2 : 4, | ||
), | ||
itemCount: library.bookPathList.length, | ||
itemBuilder: (context, index) { | ||
return LibraryTile( | ||
bookPath: library.bookPathList[index], | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class EmptyLibraryView extends StatelessWidget { | ||
const EmptyLibraryView({ | ||
super.key, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Icon( | ||
Icons.book_outlined, | ||
size: 64, | ||
), | ||
Text( | ||
'No books added yet', | ||
style: TextStyle( | ||
fontSize: 24, | ||
fontWeight: FontWeight.w400, | ||
), | ||
), | ||
Text( | ||
'Open a new file to add a book', | ||
style: TextStyle( | ||
fontSize: 12, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import 'package:epubx/epubx.dart'; | ||
import 'package:flipub/data/constants.dart'; | ||
import 'package:flipub/presentation/book/book_cover.dart'; | ||
import 'package:flipub/presentation/book/book_view.dart'; | ||
import 'package:flipub/providers/epub/book_provider.dart'; | ||
import 'package:flipub/providers/epub/library_provider.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class LibraryTile extends ConsumerWidget { | ||
const LibraryTile({super.key, required this.bookPath}); | ||
|
||
final String bookPath; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final book = ref.watch(bookProvider(bookPath)); | ||
return book.when( | ||
data: (book) { | ||
return _LibraryTileContent( | ||
bookPath: bookPath, | ||
book: book, | ||
); | ||
}, | ||
loading: () => const Center( | ||
child: CircularProgressIndicator(), | ||
), | ||
error: (error, stackTrace) { | ||
return InkWell( | ||
onTap: () { | ||
ref.read(bookLibraryNotifierProvider.notifier).removeBook(bookPath); | ||
}, | ||
child: Center( | ||
child: Text('Error: $error'), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class _LibraryTileContent extends ConsumerStatefulWidget { | ||
final String bookPath; | ||
final EpubBook book; | ||
|
||
const _LibraryTileContent({ | ||
required this.bookPath, | ||
required this.book, | ||
}); | ||
|
||
@override | ||
_LibraryTileContentState createState() => _LibraryTileContentState(); | ||
} | ||
|
||
class _LibraryTileContentState extends ConsumerState<_LibraryTileContent> { | ||
bool _isHovering = false; | ||
|
||
void _onMouseEnter() { | ||
setState(() { | ||
_isHovering = true; | ||
}); | ||
} | ||
|
||
void _onMouseExit() { | ||
setState(() { | ||
_isHovering = false; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MouseRegion( | ||
onEnter: (_) => _onMouseEnter(), | ||
onExit: (_) => _onMouseExit(), | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: InkWell( | ||
onTap: () { | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => BookView( | ||
bookPath: widget.bookPath, | ||
), | ||
), | ||
); | ||
}, | ||
child: FittedBox( | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
_isHovering || isMobile | ||
? InkWell( | ||
onTap: () => ref | ||
.read(bookLibraryNotifierProvider.notifier) | ||
.removeBook(widget.bookPath), | ||
child: CircleAvatar( | ||
radius: 16, | ||
backgroundColor: | ||
Theme.of(context).brightness == Brightness.dark | ||
? Colors.grey[800] | ||
: Colors.grey[400], | ||
child: const Icon(Icons.close), | ||
), | ||
) | ||
: const SizedBox( | ||
height: 32, | ||
), | ||
BookCover(book: widget.book), | ||
Text( | ||
widget.book.Title ?? 'Unknown title', | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.