feat: Add print feature, refine gradient on details page

This commit is contained in:
Anton Stubenbord
2023-05-29 17:10:33 +02:00
parent d8ee418828
commit e4df202190
7 changed files with 150 additions and 48 deletions

View File

@@ -1,12 +1,14 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
class DocumentView extends StatefulWidget {
final Future<Uint8List> documentBytes;
final String? title;
const DocumentView({
Key? key,
required this.documentBytes,
this.title,
}) : super(key: key);
@override
@@ -14,37 +16,90 @@ class DocumentView extends StatefulWidget {
}
class _DocumentViewState extends State<DocumentView> {
// late PdfController _pdfController;
@override
void initState() {
super.initState();
// _pdfController = PdfController(
// document: PdfDocument.openData(
// widget.documentBytes,
// ),
// );
}
int? _currentPage;
int? _totalPages;
PDFViewController? _controller;
@override
Widget build(BuildContext context) {
return Container();
// return Scaffold(
// appBar: AppBar(
// title: Text(S.of(context)!.preview),
// ),
// body: PdfView(
// builders: PdfViewBuilders<DefaultBuilderOptions>(
// options: const DefaultBuilderOptions(
// loaderSwitchDuration: Duration(milliseconds: 500),
// ),
// pageLoaderBuilder: (context) => const Center(
// child: CircularProgressIndicator(),
// ),
// ),
// scrollDirection: Axis.vertical,
// controller: _pdfController,
// ),
// );
final isInitialized = _controller != null && _currentPage != null && _totalPages != null;
final canGoToNextPage = isInitialized && _currentPage! + 1 < _totalPages!;
final canGoToPreviousPage = isInitialized && _currentPage! > 0;
return Scaffold(
appBar: AppBar(
title: widget.title != null ? Text(widget.title!) : null,
),
bottomNavigationBar: BottomAppBar(
child: Row(
children: [
Flexible(
child: Row(
children: [
IconButton.filled(
onPressed: canGoToPreviousPage
? () {
_controller?.setPage(_currentPage! - 1);
}
: null,
icon: const Icon(Icons.arrow_left),
),
const SizedBox(width: 16),
IconButton.filled(
onPressed: canGoToNextPage
? () {
_controller?.setPage(_currentPage! + 1);
}
: null,
icon: const Icon(Icons.arrow_right),
),
],
),
),
if (_currentPage != null && _totalPages != null)
Text(
"${_currentPage! + 1}/$_totalPages",
style: Theme.of(context).textTheme.labelLarge,
),
],
),
),
body: FutureBuilder(
future: widget.documentBytes,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}
return PDFView(
pdfData: snapshot.data,
defaultPage: 0,
enableSwipe: true,
fitPolicy: FitPolicy.BOTH,
swipeHorizontal: true,
onRender: (pages) {
setState(() {
_currentPage = 0;
_totalPages = pages ?? -1;
});
},
onPageChanged: (page, total) {
setState(() {
_currentPage = page;
_totalPages = total;
});
},
onViewCreated: (controller) {
_controller = controller;
},
onError: (error) {
print(error.toString());
},
onPageError: (page, error) {
print('$page: ${error.toString()}');
},
);
}),
);
}
}