Skip to content

Commit

Permalink
feat(wip): work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrFLEURY committed Mar 9, 2024
1 parent 5fa2c8d commit 8f7ac12
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 38 deletions.
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "flipub",
"request": "launch",
"type": "dart"
},
{
"name": "flipub (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flipub (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
11 changes: 11 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "generate sources",
"type": "shell",
"command": "dart run build_runner build",
"problemMatcher": []
}
]
}
11 changes: 6 additions & 5 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import 'package:flipub/providers/theme_provider.dart';
import 'package:flipub/views/library_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

const sharedPreferencesFontSizeKey = 'fontSize';

class Flipub extends StatelessWidget {
class Flipub extends ConsumerWidget {
const Flipub({
super.key,
});

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final themeMode = ref.watch(themeNotifierProvider);
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData.dark(),
theme: themeMode == ThemeMode.dark ? ThemeData.dark() : ThemeData.light(),
home: const LibrayView(),
);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/data/constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'dart:io';

const sharedPreferencesFontSizeKey = 'fontSize';
const sharedPreferencesThemeKey = 'theme';

bool get isMobile => Platform.isAndroid || Platform.isIOS;
31 changes: 31 additions & 0 deletions lib/providers/theme_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flipub/data/constants.dart';
import 'package:flipub/providers/preferences_provider.dart';
import 'package:flutter/material.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'theme_provider.g.dart';

@riverpod
class ThemeNotifier extends _$ThemeNotifier {
@override
ThemeMode build() {
_readPreferences();
return ThemeMode.dark;
}

Future<void> _readPreferences() async {
final sharedPreferences = await ref.read(preferencesProvider.future);
final isDark =
sharedPreferences.getBool(sharedPreferencesThemeKey) ?? false;
state = isDark ? ThemeMode.dark : ThemeMode.light;
}

Future<void> toggle() async {
state = state == ThemeMode.light ? ThemeMode.dark : ThemeMode.light;
final sharedPreferences = await ref.read(preferencesProvider.future);
sharedPreferences.setBool(
sharedPreferencesThemeKey,
state == ThemeMode.dark,
);
}
}
26 changes: 26 additions & 0 deletions lib/providers/theme_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/views/book_cover.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ class BookCover extends StatelessWidget {
height: 200,
width: 200,
child: Center(
child: Text('No cover'),
child: Text(
'No cover',
style: TextStyle(
fontSize: 42,
),
),
),
);
}
Expand Down
74 changes: 55 additions & 19 deletions lib/views/book_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:epubx/epubx.dart';
import 'package:flipub/data/constants.dart';
import 'package:flipub/providers/book_provider.dart';
import 'package:flipub/views/chapter_view.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -33,37 +34,72 @@ class BookView extends ConsumerWidget {
}
}

class _BookViewContent extends StatelessWidget {
class _BookViewContent extends StatefulWidget {
final EpubBook book;

const _BookViewContent({
required this.book,
});

@override
State<_BookViewContent> createState() => _BookViewContentState();
}

class _BookViewContentState extends State<_BookViewContent> {
EpubChapter? chapter;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(book.Title ?? 'Unknown title'),
title: Text(widget.book.Title ?? 'Unknown title'),
),
body: ListView.builder(
itemCount: book.Chapters?.length ?? 0,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ChapterView(chapter: book.Chapters![index]),
),
);
},
child: ListTile(
title: Text(book.Chapters?[index].Title ?? 'Unknown chapter'),
body: Row(
children: [
Flexible(
child: ListView.builder(
itemCount: widget.book.Chapters?.length ?? 0,
itemBuilder: (context, index) {
return InkWell(
onTap: () =>
_onChapterTap(context, widget.book.Chapters![index]),
child: ListTile(
selected: chapter == widget.book.Chapters![index],
title: Text(
widget.book.Chapters?[index].Title ?? 'Unknown chapter',
),
),
);
},
),
);
},
),
!isMobile && chapter != null
? Expanded(
flex: 3,
child: ChapterView(
chapter: chapter!,
),
)
: Container(),
],
),
);
}

void _onChapterTap(BuildContext context, EpubChapter chapter) {
if (isMobile) {
_navigateToChapterView(context, chapter);
} else {
setState(() {
this.chapter = chapter;
});
}
}

void _navigateToChapterView(BuildContext context, EpubChapter chapter) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ChapterView(chapter: chapter),
),
);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/views/chapter_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:io';

import 'package:epubx/epubx.dart';
import 'package:flipub/app.dart';
import 'package:flipub/data/constants.dart';
import 'package:flipub/providers/preferences_provider.dart';
import 'package:flipub/views/audio_book.dart';
import 'package:flipub/views/linear_pogress_listener.dart';
Expand Down Expand Up @@ -95,7 +95,10 @@ class _ChapterViewState extends ConsumerState<_ChapterViewInternal> {
body: SingleChildScrollView(
controller: scrollController,
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 16,
),
child: Html(
style: {
'body': Style(
Expand Down
36 changes: 25 additions & 11 deletions lib/views/library_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:epubx/epubx.dart' show EpubBook;
import 'package:flipub/data/book_library.dart';
import 'package:flipub/providers/book_provider.dart';
import 'package:flipub/providers/library_provider.dart';
import 'package:flipub/providers/theme_provider.dart';
import 'package:flipub/views/book_cover.dart';
import 'package:flipub/views/book_view.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -31,18 +32,31 @@ class LibrayView extends ConsumerWidget {
}
}

class _LibraryViewContent extends StatelessWidget {
class _LibraryViewContent extends ConsumerWidget {
final BookLibrary library;

const _LibraryViewContent({
required this.library,
});

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final currentTheme = ref.watch(themeNotifierProvider);
return Scaffold(
appBar: AppBar(
title: const Text('Library'),
actions: [
IconButton(
icon: Icon(
currentTheme == ThemeMode.dark
? Icons.dark_mode
: Icons.light_mode,
),
onPressed: () {
ref.read(themeNotifierProvider.notifier).toggle();
},
),
],
),
body: Padding(
padding: const EdgeInsets.all(48.0),
Expand Down Expand Up @@ -113,15 +127,15 @@ class _LibraryTileContent extends StatelessWidget {
),
);
},
child: Card(
child: FittedBox(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
BookCover(book: book),
Text(book.Title ?? 'Unknown title'),
],
),
child: FittedBox(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
BookCover(book: book),
Text(
book.Title ?? 'Unknown title',
),
],
),
),
),
Expand Down

0 comments on commit 8f7ac12

Please sign in to comment.