mirror of
https://github.com/dstark5/Openlib.git
synced 2025-06-04 19:07:07 +08:00
59 lines
2.0 KiB
Dart
59 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:openlib/services/database.dart';
|
|
import 'package:openlib/state/state.dart' show dbProvider;
|
|
|
|
import 'package:openlib/ui/components/book_info_widget.dart';
|
|
import 'package:openlib/ui/components/file_buttons_widget.dart';
|
|
|
|
class BookPage extends StatelessWidget {
|
|
const BookPage({Key? key, required this.id}) : super(key: key);
|
|
|
|
final String id;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
title: const Text("Openlib"),
|
|
titleTextStyle: Theme.of(context).textTheme.displayLarge,
|
|
),
|
|
body: Consumer(
|
|
builder: (BuildContext context, WidgetRef ref, _) {
|
|
final bookInfo = ref.read(dbProvider).getId(id);
|
|
|
|
return FutureBuilder(
|
|
future: bookInfo,
|
|
builder: (BuildContext context, AsyncSnapshot<MyBook?> snapshot) {
|
|
if (snapshot.hasData) {
|
|
return BookInfoWidget(
|
|
data: snapshot.data,
|
|
child: FileOpenAndDeleteButtons(
|
|
id: snapshot.data!.id,
|
|
format: snapshot.data!.format!,
|
|
onDelete: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
));
|
|
} else if (snapshot.hasError) {
|
|
return Center(
|
|
child: Text(snapshot.toString()),
|
|
);
|
|
} else {
|
|
return Center(
|
|
child: SizedBox(
|
|
width: 25,
|
|
height: 25,
|
|
child: CircularProgressIndicator(
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
),
|
|
));
|
|
}
|
|
});
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|