Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plan B] TF-2764 Printing pdf when preview #2780

Merged
merged 8 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions contact/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.13.0"
archive:
dependency: transitive
description:
name: archive
sha256: ecf4273855368121b1caed0d10d4513c7241dfc813f7d3c8933b36622ae9b265
url: "https://pub.dev"
source: hosted
version: "3.5.1"
args:
dependency: transitive
description:
Expand All @@ -33,6 +41,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
barcode:
dependency: transitive
description:
name: barcode
sha256: ab180ce22c6555d77d45f0178a523669db67f95856e3378259ef2ffeb43e6003
url: "https://pub.dev"
source: hosted
version: "2.2.8"
bidi:
dependency: transitive
description:
name: bidi
sha256: "1a7d0c696324b2089f72e7671fd1f1f64fef44c980f3cebc84e803967c597b63"
url: "https://pub.dev"
source: hosted
version: "2.0.10"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -511,6 +535,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
image:
dependency: transitive
description:
name: image
sha256: "4c68bfd5ae83e700b5204c1e74451e7bf3cf750e6843c6e158289cf56bda018e"
url: "https://pub.dev"
source: hosted
version: "4.1.7"
intl:
dependency: transitive
description:
Expand Down Expand Up @@ -703,6 +735,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.1"
pdf:
dependency: transitive
description:
name: pdf
sha256: "243f05342fc0bdf140eba5b069398985cdbdd3dbb1d776cf43d5ea29cc570ba6"
url: "https://pub.dev"
source: hosted
version: "3.10.8"
pdf_widget_wrapper:
dependency: transitive
description:
name: pdf_widget_wrapper
sha256: e9d31fd7782ce28ae346b127ea7d1cd748d799bddee379f31191693610e23749
url: "https://pub.dev"
source: hosted
version: "1.0.1"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -743,6 +791,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.5.1"
printing:
dependency: transitive
description:
name: printing
sha256: "1c99cab90ebcc1fff65831d264627d5b529359d563e53f33ab9b8117f2d280bc"
url: "https://pub.dev"
source: hosted
version: "5.12.0"
pub_semver:
dependency: transitive
description:
Expand All @@ -759,6 +815,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.3"
qr:
dependency: transitive
description:
name: qr
sha256: "64957a3930367bf97cc211a5af99551d630f2f4625e38af10edd6b19131b64b3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
quiver:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion core/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ linter:
rules:
constant_identifier_names: false
non_constant_identifier_names: false
unnecessary_string_escapes: false
unnecessary_string_escapes: false
avoid_web_libraries_in_flutter: false
2 changes: 2 additions & 0 deletions core/lib/data/constants/constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ class Constant {
static const pdfMimeType = 'application/pdf';
static const textHtmlMimeType = 'text/html';
static const octetStreamMimeType = 'application/octet-stream';
static const pdfExtension = '.pdf';
static const imageType = 'image';
}
2 changes: 0 additions & 2 deletions core/lib/domain/extensions/media_type_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import 'package:core/domain/preview/supported_preview_file_types.dart';
import 'package:http_parser/http_parser.dart';

extension MediaTypeExtension on MediaType {
static const String imageType = 'image';

bool isAndroidSupportedPreview() => SupportedPreviewFileTypes.androidSupportedTypes.contains(mimeType);

bool isIOSSupportedPreview() => SupportedPreviewFileTypes.iOSSupportedTypes.containsKey(mimeType);
Expand Down
4 changes: 0 additions & 4 deletions core/lib/presentation/resources/image_paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@ class ImagePaths {
return AssetsPaths.images + imageName;
}

String _getIconPath(String iconName) {
return AssetsPaths.icons + iconName;
}

String getConfigurationImagePath(String imageName) {
return AssetsPaths.configurationImages + imageName;
}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/presentation/views/text/text_form_field_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class _TextFieldFormBuilderState extends State<TextFormFieldBuilder> {

@override
Widget build(BuildContext context) {
return TextFormField(
return TextField(
key: widget.key,
controller: _controller,
cursorColor: widget.cursorColor,
Expand Down Expand Up @@ -105,7 +105,7 @@ class _TextFieldFormBuilderState extends State<TextFormFieldBuilder> {
}
}
},
onFieldSubmitted: widget.onTextSubmitted,
onSubmitted: widget.onTextSubmitted,
onTap: widget.onTap,
);
}
Expand Down
10 changes: 9 additions & 1 deletion core/lib/utils/print_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import 'dart:async';
import 'dart:typed_data';

import 'package:core/data/model/print_attachment.dart';
import 'package:core/utils/app_logger.dart';
Expand All @@ -8,8 +8,16 @@ import 'package:core/utils/html/html_template.dart';
import 'package:core/utils/html/html_utils.dart';
import 'package:html/dom.dart';
import 'package:html/parser.dart';
import 'package:printing/printing.dart';

class PrintUtils {

Future<void> printPDFFile(Uint8List bytes, String fileName) async {
await Printing.layoutPdf(
name: fileName,
onLayout: (_) => bytes);
}

Element? _createUserInformationElement({
required String appName,
required String userName,
Expand Down
72 changes: 72 additions & 0 deletions core/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
sha256: ecf4273855368121b1caed0d10d4513c7241dfc813f7d3c8933b36622ae9b265
url: "https://pub.dev"
source: hosted
version: "3.5.1"
args:
dependency: transitive
description:
Expand All @@ -17,6 +25,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
barcode:
dependency: transitive
description:
name: barcode
sha256: ab180ce22c6555d77d45f0178a523669db67f95856e3378259ef2ffeb43e6003
url: "https://pub.dev"
source: hosted
version: "2.2.8"
bidi:
dependency: transitive
description:
name: bidi
sha256: "1a7d0c696324b2089f72e7671fd1f1f64fef44c980f3cebc84e803967c597b63"
url: "https://pub.dev"
source: hosted
version: "2.0.10"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -73,6 +97,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.3+7"
crypto:
dependency: transitive
description:
name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.3"
csslib:
dependency: transitive
description:
Expand Down Expand Up @@ -344,6 +376,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
image:
dependency: transitive
description:
name: image
sha256: "4c68bfd5ae83e700b5204c1e74451e7bf3cf750e6843c6e158289cf56bda018e"
url: "https://pub.dev"
source: hosted
version: "4.1.7"
intl:
dependency: "direct main"
description:
Expand Down Expand Up @@ -464,6 +504,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.1"
pdf:
dependency: transitive
description:
name: pdf
sha256: "243f05342fc0bdf140eba5b069398985cdbdd3dbb1d776cf43d5ea29cc570ba6"
url: "https://pub.dev"
source: hosted
version: "3.10.8"
pdf_widget_wrapper:
dependency: transitive
description:
name: pdf_widget_wrapper
sha256: e9d31fd7782ce28ae346b127ea7d1cd748d799bddee379f31191693610e23749
url: "https://pub.dev"
source: hosted
version: "1.0.1"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -496,6 +552,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.9.1"
printing:
dependency: "direct main"
description:
name: printing
sha256: "1c99cab90ebcc1fff65831d264627d5b529359d563e53f33ab9b8117f2d280bc"
url: "https://pub.dev"
source: hosted
version: "5.12.0"
qr:
dependency: transitive
description:
name: qr
sha256: "64957a3930367bf97cc211a5af99551d630f2f4625e38af10edd6b19131b64b3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 2 additions & 0 deletions core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ dependencies:

linkify: 5.0.0

printing: 5.12.0

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
28 changes: 28 additions & 0 deletions docs/adr/0048-view-one-by-one-pdf-in-dart-side-in-only-web-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 48. View one-by-one PDF in Dart side in only Web app

Date: 2024-05-17

## Status

Accepted

## Context

- In EmailView when the user clicks on an attachment, we should display a PDF viewer for the user.
- In PDF Viewer users can view full pages of the PDF file and can download or print it.

## Decision

- Create PDF Viewer with [pdf_render](https://github.com/linagora/flutter_pdf_render.git)
- Viewer will stay overlay in web app tab
- Actions supported: `Download`, `Print`, `Zoom In/Out`, `Show current/total pages` in viewer

## Consequences

- PDF viewer works well on all browsers (Chrome/Firefox/Edge/Safari/Opera)

## Improvement

- `Print name`: Some browsers (Firefox/Safari/Edge) use a random name to name the file when printing.
- `Jump to page`: When using the standard size of PDF pages to display in the viewer, the `jumpToPage` method of `pdf_render` does not work correctly. So we will temporarily disable it.
- `Drag the scrollbar`: Currently the pdf page is displayed in an `Interactive viewer` so does not interact with the `Scrollbar`
16 changes: 11 additions & 5 deletions lib/features/base/widget/circle_loading_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import 'package:tmail_ui_user/features/base/styles/circle_loading_widget_styles.
class CircleLoadingWidget extends StatelessWidget {

final double? size;
final double? strokeWidth;
final EdgeInsetsGeometry? padding;

const CircleLoadingWidget({super.key, this.size, this.padding});
const CircleLoadingWidget({
super.key,
this.size,
this.padding,
this.strokeWidth
});

@override
Widget build(BuildContext context) {
Expand All @@ -16,19 +22,19 @@ class CircleLoadingWidget extends StatelessWidget {
child: SizedBox(
width: size ?? CircleLoadingWidgetStyles.size,
height: size ?? CircleLoadingWidgetStyles.size,
child: const CircularProgressIndicator(
child: CircularProgressIndicator(
color: CircleLoadingWidgetStyles.progressColor,
strokeWidth: CircleLoadingWidgetStyles.width,
strokeWidth: strokeWidth ?? CircleLoadingWidgetStyles.width,
)
),
);
} else {
return SizedBox(
width: size ?? CircleLoadingWidgetStyles.size,
height: size ?? CircleLoadingWidgetStyles.size,
child: const CircularProgressIndicator(
child: CircularProgressIndicator(
color: CircleLoadingWidgetStyles.progressColor,
strokeWidth: CircleLoadingWidgetStyles.width,
strokeWidth: strokeWidth ?? CircleLoadingWidgetStyles.width,
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import 'package:dartz/dartz.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:file_picker/file_picker.dart';

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (forward)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (rule_filter)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (email_recovery)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (contact)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (fcm)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (core)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (model)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (server_settings)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages

Check notice on line 11 in lib/features/composer/presentation/composer_controller.dart

View workflow job for this annotation

GitHub Actions / analyze-test (default)

The imported package 'file_picker' isn't a dependency of the importing package. For more details, see https://dart.dev/tools/diagnostic-messages#depend_on_referenced_packages
import 'package:filesize/filesize.dart';
import 'package:fk_user_agent/fk_user_agent.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -1948,7 +1948,7 @@
return;
}

if (fileUpload.type?.startsWith(MediaTypeExtension.imageType) == true) {
if (fileUpload.type?.startsWith(Constant.imageType) == true) {
final fileInfo = await fileUpload.toFileInfo();
if (fileInfo != null) {
_uploadInlineAttachmentsAction(fileInfo);
Expand Down
3 changes: 2 additions & 1 deletion lib/features/email/data/datasource/email_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ abstract class EmailDataSource {
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
StreamController<Either<Failure, Success>> onReceiveController
StreamController<Either<Failure, Success>> onReceiveController,
{CancelToken? cancelToken}
);

Future<List<EmailId>> moveToMailbox(Session session, AccountId accountId, MoveToMailboxRequest moveRequest);
Expand Down
Loading
Loading