mirror of
https://github.com/dstark5/Openlib.git
synced 2025-05-17 06:26:00 +08:00
Fixed grey screen on search and changed share button position
This commit is contained in:
@ -128,7 +128,7 @@ class _MainScreenState extends ConsumerState<MainScreen> {
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
title: const Text("Openlib"),
|
||||
titleTextStyle: Theme.of(context).textTheme.displayLarge,
|
||||
),
|
||||
|
23
lib/services/share_book.dart
Normal file
23
lib/services/share_book.dart
Normal file
@ -0,0 +1,23 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
Future<void> shareBook(String title, String link, String path) async {
|
||||
try {
|
||||
final url = Uri.parse(path);
|
||||
final response = await http.get(url);
|
||||
final bytes = response.bodyBytes;
|
||||
|
||||
//temp
|
||||
final temp = await getTemporaryDirectory();
|
||||
final dest = '${temp.path}/image.jpg';
|
||||
File(dest).writeAsBytes(bytes);
|
||||
|
||||
String message = 'Discover this amazing book: "$title"\nRead more : $link';
|
||||
await Share.shareXFiles([XFile(dest)], text: message);
|
||||
} catch (e) {
|
||||
debugPrint('Error sharing the book: $e');
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ class AboutPage extends StatelessWidget {
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
title: const Text("Openlib"),
|
||||
titleTextStyle: Theme.of(context).textTheme.displayLarge,
|
||||
),
|
||||
|
@ -2,18 +2,14 @@
|
||||
// import 'dart:convert';
|
||||
|
||||
// Flutter imports:
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:flutter/scheduler.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:dio/dio.dart' show CancelToken;
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:openlib/services/share_book.dart';
|
||||
// import 'package:flutter_svg/svg.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:openlib/services/annas_archieve.dart' show BookInfoData;
|
||||
@ -25,8 +21,6 @@ import 'package:openlib/ui/components/file_buttons_widget.dart';
|
||||
import 'package:openlib/ui/components/snack_bar_widget.dart';
|
||||
import 'package:openlib/ui/webview_page.dart';
|
||||
|
||||
|
||||
|
||||
import 'package:openlib/state/state.dart'
|
||||
show
|
||||
bookInfoProvider,
|
||||
@ -43,7 +37,6 @@ import 'package:openlib/state/state.dart'
|
||||
checkSumState,
|
||||
checkIdExists,
|
||||
myLibraryProvider;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class BookInfoPage extends ConsumerWidget {
|
||||
const BookInfoPage({super.key, required this.url});
|
||||
@ -55,9 +48,25 @@ class BookInfoPage extends ConsumerWidget {
|
||||
final bookInfo = ref.watch(bookInfoProvider(url));
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
title: const Text("Openlib"),
|
||||
titleTextStyle: Theme.of(context).textTheme.displayLarge,
|
||||
actions: [
|
||||
bookInfo.maybeWhen(data: (data) {
|
||||
return IconButton(
|
||||
icon: Icon(
|
||||
Icons.share_sharp,
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
),
|
||||
iconSize: 19.0,
|
||||
onPressed: () async {
|
||||
await shareBook(data.title, data.link, data.thumbnail ?? '');
|
||||
},
|
||||
);
|
||||
}, orElse: () {
|
||||
return const SizedBox.shrink();
|
||||
})
|
||||
],
|
||||
),
|
||||
body: bookInfo.when(
|
||||
skipLoadingOnRefresh: false,
|
||||
@ -198,13 +207,15 @@ class _ActionButtonWidgetState extends ConsumerState<ActionButtonWidget> {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 21, bottom: 21),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start, // Aligns buttons properly
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.start, // Aligns buttons properly
|
||||
children: [
|
||||
// Button for "Add To My Library"
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.secondary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
textStyle: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w900,
|
||||
@ -214,8 +225,8 @@ class _ActionButtonWidgetState extends ConsumerState<ActionButtonWidget> {
|
||||
onPressed: () async {
|
||||
final result = await Navigator.push(context,
|
||||
MaterialPageRoute(builder: (BuildContext context) {
|
||||
return Webview(url: widget.data.mirror ?? '');
|
||||
}));
|
||||
return Webview(url: widget.data.mirror ?? '');
|
||||
}));
|
||||
|
||||
if (result != null) {
|
||||
widget.data.mirror = result;
|
||||
@ -223,30 +234,9 @@ class _ActionButtonWidgetState extends ConsumerState<ActionButtonWidget> {
|
||||
}
|
||||
},
|
||||
child: const Text('Add To My Library'),
|
||||
),
|
||||
|
||||
// Spacing between the buttons
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// Button for "Share"
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.secondary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
textStyle: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w900,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
await shareBook(widget.data.title, widget.data.link,widget.data.thumbnail ?? '');
|
||||
},
|
||||
child: const Text('Share'),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
},
|
||||
@ -273,7 +263,7 @@ Future<void> downloadFileWidget(
|
||||
});
|
||||
|
||||
List<String> mirrors = [data.mirror!];
|
||||
print(mirrors);
|
||||
// print(mirrors);
|
||||
downloadFile(
|
||||
mirrors: mirrors,
|
||||
md5: data.md5,
|
||||
@ -672,23 +662,3 @@ Future<void> _showWarningFileDialog(BuildContext context) async {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Future<void> shareBook(String title, String link,String path) async {
|
||||
try {
|
||||
final url = Uri.parse(path);
|
||||
final response = await http.get(url);
|
||||
final bytes = response.bodyBytes;
|
||||
|
||||
//temp
|
||||
final temp = await getTemporaryDirectory();
|
||||
final dest = '${temp.path}/image.jpg';
|
||||
File(dest).writeAsBytes(bytes);
|
||||
|
||||
String message = 'Discover this amazing book: "$title"\nRead more : $link';
|
||||
await Share.shareXFiles([XFile(dest)], text: message);
|
||||
} catch (e) {
|
||||
debugPrint('Error sharing the book: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,7 @@ class CategoryListingPage extends ConsumerWidget {
|
||||
final booksBasedOnGenre = ref.watch(getSubCategoryTypeList(url));
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
title: const Text("Openlib"),
|
||||
titleTextStyle: Theme.of(context).textTheme.displayLarge,
|
||||
),
|
||||
|
@ -65,7 +65,7 @@ class PelletContainer extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 30,
|
||||
width: 125,
|
||||
width: 115,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
|
@ -6,6 +6,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:openlib/services/database.dart';
|
||||
import 'package:openlib/services/share_book.dart';
|
||||
import 'package:openlib/ui/components/book_info_widget.dart';
|
||||
import 'package:openlib/ui/components/file_buttons_widget.dart';
|
||||
|
||||
@ -16,18 +17,40 @@ class BookPage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
MyLibraryDb dataBase = MyLibraryDb.instance;
|
||||
final bookInfo = dataBase.getId(id);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
title: const Text("Openlib"),
|
||||
titleTextStyle: Theme.of(context).textTheme.displayLarge,
|
||||
actions: [
|
||||
FutureBuilder(
|
||||
future: bookInfo,
|
||||
builder: (BuildContext context, AsyncSnapshot<MyBook?> snapshot) {
|
||||
if (snapshot.hasData &&
|
||||
snapshot.data?.title != null &&
|
||||
snapshot.data?.link != null) {
|
||||
return IconButton(
|
||||
icon: Icon(
|
||||
Icons.share_sharp,
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
),
|
||||
iconSize: 19.0,
|
||||
onPressed: () async {
|
||||
await shareBook(snapshot.data!.title, snapshot.data!.link,
|
||||
snapshot.data?.thumbnail ?? '');
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
})
|
||||
],
|
||||
),
|
||||
body: Consumer(
|
||||
builder: (BuildContext context, WidgetRef ref, _) {
|
||||
MyLibraryDb dataBase = MyLibraryDb.instance;
|
||||
|
||||
final bookInfo = dataBase.getId(id);
|
||||
|
||||
return FutureBuilder(
|
||||
future: bookInfo,
|
||||
builder: (BuildContext context, AsyncSnapshot<MyBook?> snapshot) {
|
||||
|
@ -24,7 +24,7 @@ class ResultPage extends ConsumerWidget {
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
title: const Text("Openlib"),
|
||||
titleTextStyle: Theme.of(context).textTheme.displayLarge,
|
||||
),
|
||||
@ -46,8 +46,8 @@ class ResultPage extends ConsumerWidget {
|
||||
title: i.title,
|
||||
author: i.author ?? "unknown",
|
||||
publisher: i.publisher ?? "unknown",
|
||||
thumbnail: i.thumbnail!,
|
||||
info: i.info,
|
||||
thumbnail: i.thumbnail ?? '',
|
||||
info: i.info ?? '',
|
||||
link: i.link,
|
||||
onClick: () {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
|
Reference in New Issue
Block a user