TF-105 Handle event click link and loading content of HtmlContentViewer
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart' as launcher;
|
||||||
|
|
||||||
class _HtmlGenerationArguments {
|
class _HtmlGenerationArguments {
|
||||||
final String message;
|
final String message;
|
||||||
@@ -35,12 +36,22 @@ class HtmlContentViewer extends StatefulWidget {
|
|||||||
/// Register this callback if you want a reference to the [InAppWebViewController].
|
/// Register this callback if you want a reference to the [InAppWebViewController].
|
||||||
final void Function(InAppWebViewController controller)? onWebViewCreated;
|
final void Function(InAppWebViewController controller)? onWebViewCreated;
|
||||||
|
|
||||||
|
final void Function(InAppWebViewController controller, Uri? uri)? onWebViewLoadStart;
|
||||||
|
|
||||||
|
final void Function(InAppWebViewController controller, Uri? uri)? onWebViewLoadStop;
|
||||||
|
|
||||||
|
/// Handler for mailto: links
|
||||||
|
final Future Function(Uri mailto)? mailtoDelegate;
|
||||||
|
|
||||||
const HtmlContentViewer({
|
const HtmlContentViewer({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.message,
|
required this.message,
|
||||||
this.blockExternalImages = false,
|
this.blockExternalImages = false,
|
||||||
this.onError,
|
this.onError,
|
||||||
this.onWebViewCreated,
|
this.onWebViewCreated,
|
||||||
|
this.onWebViewLoadStart,
|
||||||
|
this.onWebViewLoadStop,
|
||||||
|
this.mailtoDelegate,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -144,6 +155,11 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
|
|||||||
enableViewportScale: true,
|
enableViewportScale: true,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
onLoadStart: (controller, uri) {
|
||||||
|
if (widget.onWebViewLoadStart != null) {
|
||||||
|
widget.onWebViewLoadStart!(controller, uri);
|
||||||
|
}
|
||||||
|
},
|
||||||
onWebViewCreated: widget.onWebViewCreated,
|
onWebViewCreated: widget.onWebViewCreated,
|
||||||
onLoadStop: (controller, uri) async {
|
onLoadStop: (controller, uri) async {
|
||||||
var scrollHeight = (await controller.evaluateJavascript(source: 'document.body.scrollHeight'));
|
var scrollHeight = (await controller.evaluateJavascript(source: 'document.body.scrollHeight'));
|
||||||
@@ -162,10 +178,34 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
|
|||||||
_webViewContentHeight = double.tryParse('${scrollHeight + 10.0}');
|
_webViewContentHeight = double.tryParse('${scrollHeight + 10.0}');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (widget.onWebViewLoadStop != null) {
|
||||||
|
widget.onWebViewLoadStop!(controller, uri);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
shouldOverrideUrlLoading: _shouldOverrideUrlLoading,
|
||||||
gestureRecognizers: {
|
gestureRecognizers: {
|
||||||
Factory<LongPressGestureRecognizer>(() => LongPressGestureRecognizer()),
|
Factory<LongPressGestureRecognizer>(() => LongPressGestureRecognizer()),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<NavigationActionPolicy> _shouldOverrideUrlLoading(
|
||||||
|
InAppWebViewController controller,
|
||||||
|
NavigationAction request
|
||||||
|
) async {
|
||||||
|
final requestUri = request.request.url!;
|
||||||
|
final mailtoHandler = widget.mailtoDelegate;
|
||||||
|
if (mailtoHandler != null && requestUri.isScheme('mailto')) {
|
||||||
|
await mailtoHandler(requestUri);
|
||||||
|
return NavigationActionPolicy.CANCEL;
|
||||||
|
}
|
||||||
|
final url = requestUri.toString();
|
||||||
|
if (await launcher.canLaunch(url)) {
|
||||||
|
await launcher.launch(url);
|
||||||
|
return NavigationActionPolicy.CANCEL;
|
||||||
|
} else {
|
||||||
|
return NavigationActionPolicy.ALLOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+8
-4
@@ -1,6 +1,8 @@
|
|||||||
name: core
|
name: core
|
||||||
description: Core Module
|
description: Core Module
|
||||||
|
|
||||||
|
# As we are not publishing this Installer in pub.dev, we can add publish_to: 'none'
|
||||||
|
publish_to: none
|
||||||
# The following defines the version and build number for your application.
|
# The following defines the version and build number for your application.
|
||||||
# A version number is three numbers separated by dots, like 1.2.43
|
# A version number is three numbers separated by dots, like 1.2.43
|
||||||
# followed by an optional build number separated by a +.
|
# followed by an optional build number separated by a +.
|
||||||
@@ -59,11 +61,13 @@ dependencies:
|
|||||||
# getwidget
|
# getwidget
|
||||||
getwidget: 2.0.4
|
getwidget: 2.0.4
|
||||||
|
|
||||||
# enough_html_editor
|
# flutter_inappwebview
|
||||||
enough_html_editor:
|
flutter_inappwebview:
|
||||||
git:
|
git:
|
||||||
url: git://github.com/dab246/enough_html_editor.git
|
url: https://github.com/robert-virkus/flutter_inappwebview.git
|
||||||
ref: fix_bug_enough_platform_widgets
|
|
||||||
|
# url_launcher
|
||||||
|
url_launcher: 6.0.6
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
@@ -8,6 +9,7 @@ import 'package:get/get.dart';
|
|||||||
import 'package:model/model.dart';
|
import 'package:model/model.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/email_controller.dart';
|
import 'package:tmail_ui_user/features/email/presentation/email_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/model/text_format.dart';
|
import 'package:tmail_ui_user/features/email/presentation/model/text_format.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/presentation/model/web_view_state.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/widgets/app_bar_mail_widget_builder.dart';
|
import 'package:tmail_ui_user/features/email/presentation/widgets/app_bar_mail_widget_builder.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_file_tile_builder.dart';
|
import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_file_tile_builder.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/widgets/bottom_bar_mail_widget_builder.dart';
|
import 'package:tmail_ui_user/features/email/presentation/widgets/bottom_bar_mail_widget_builder.dart';
|
||||||
@@ -119,7 +121,7 @@ class EmailView extends GetView {
|
|||||||
Widget _buildLoadingView() {
|
Widget _buildLoadingView() {
|
||||||
return Obx(() => emailController.viewState.value.fold(
|
return Obx(() => emailController.viewState.value.fold(
|
||||||
(failure) => SizedBox.shrink(),
|
(failure) => SizedBox.shrink(),
|
||||||
(success) => success is LoadingState
|
(success) => success is LoadingState || success is WebViewLoadingState
|
||||||
? Center(child: Padding(
|
? Center(child: Padding(
|
||||||
padding: EdgeInsets.only(top: 16, bottom: 16),
|
padding: EdgeInsets.only(top: 16, bottom: 16),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
@@ -148,8 +150,8 @@ class EmailView extends GetView {
|
|||||||
emailController.emailAddressExpandMode.value)
|
emailController.emailAddressExpandMode.value)
|
||||||
.onOpenExpandAddressReceiverActionClick(() => emailController.toggleDisplayEmailAddressAction(expandMode: ExpandMode.EXPAND))
|
.onOpenExpandAddressReceiverActionClick(() => emailController.toggleDisplayEmailAddressAction(expandMode: ExpandMode.EXPAND))
|
||||||
.build()),
|
.build()),
|
||||||
_buildLoadingView(),
|
|
||||||
_buildListAttachments(context),
|
_buildListAttachments(context),
|
||||||
|
_buildLoadingView(),
|
||||||
_buildListMessageContent(),
|
_buildListMessageContent(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -293,6 +295,13 @@ class EmailView extends GetView {
|
|||||||
color: AppColor.mailboxTextColor)))
|
color: AppColor.mailboxTextColor)))
|
||||||
: HtmlContentViewer(
|
: HtmlContentViewer(
|
||||||
message: messageContents.first.content,
|
message: messageContents.first.content,
|
||||||
|
onWebViewLoadStart: (webController, uri) {
|
||||||
|
emailController.dispatchState(Right(WebViewLoadingState()));
|
||||||
|
},
|
||||||
|
onWebViewLoadStop: (webController, uri) {
|
||||||
|
emailController.clearState();
|
||||||
|
},
|
||||||
|
mailtoDelegate: (uri) async {},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return SizedBox.shrink();
|
return SizedBox.shrink();
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
import 'package:core/core.dart';
|
||||||
|
|
||||||
|
class WebViewLoadingState extends UIState {
|
||||||
|
WebViewLoadingState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
name: model
|
name: model
|
||||||
description: A model module contains entities
|
description: A model module contains entities
|
||||||
|
|
||||||
|
# As we are not publishing this Installer in pub.dev, we can add publish_to: 'none'
|
||||||
|
publish_to: none
|
||||||
# The following defines the version and build number for your application.
|
# The following defines the version and build number for your application.
|
||||||
# A version number is three numbers separated by dots, like 1.2.43
|
# A version number is three numbers separated by dots, like 1.2.43
|
||||||
# followed by an optional build number separated by a +.
|
# followed by an optional build number separated by a +.
|
||||||
|
|||||||
Reference in New Issue
Block a user