Skip to content

Commit

Permalink
Merge pull request #44 from flyerhq/fg/url_launcher
Browse files Browse the repository at this point in the history
Flutter 3 & Update url launcher usage to make CI run through
  • Loading branch information
demchenkoalex authored Jun 12, 2022
2 parents a10c037 + b7bf3e4 commit c62ec49
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linter:
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
- use_super_parameters

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
1 change: 1 addition & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linter:
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
- use_super_parameters

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
8 changes: 8 additions & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
2 changes: 1 addition & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Future<PreviewData> getPreviewData(
);

if (!url.toLowerCase().startsWith('http')) {
url = 'https://' + url;
url = 'https://$url';
}
previewDataUrl = _calculateUrl(url, proxy);
final uri = Uri.parse(previewDataUrl);
Expand Down
41 changes: 22 additions & 19 deletions lib/src/widgets/link_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../utils.dart' show getPreviewData;
class LinkPreview extends StatefulWidget {
/// Creates [LinkPreview]
const LinkPreview({
Key? key,
super.key,
this.animationDuration,
this.corsProxy,
this.enableAnimation = false,
Expand All @@ -34,7 +34,7 @@ class LinkPreview extends StatefulWidget {
this.textWidget,
this.userAgent,
required this.width,
}) : super(key: key);
});

/// Expand animation duration
final Duration? animationDuration;
Expand Down Expand Up @@ -104,7 +104,7 @@ class LinkPreview extends StatefulWidget {
final double width;

@override
_LinkPreviewState createState() => _LinkPreviewState();
State<LinkPreview> createState() => _LinkPreviewState();
}

class _LinkPreviewState extends State<LinkPreview>
Expand Down Expand Up @@ -201,8 +201,11 @@ class _LinkPreviewState extends State<LinkPreview>
Future<void> _onOpen(String url) async {
if (widget.onLinkPressed != null) {
widget.onLinkPressed!(url);
} else if (await canLaunch(url)) {
await launch(url);
} else {
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri, mode: LaunchMode.externalApplication);
}
}
}

Expand All @@ -216,7 +219,7 @@ class _LinkPreviewState extends State<LinkPreview>
}

Widget _bodyWidget(PreviewData data, double width) {
final _padding = widget.padding ??
final padding = widget.padding ??
const EdgeInsets.only(
bottom: 16,
left: 24,
Expand All @@ -231,9 +234,9 @@ class _LinkPreviewState extends State<LinkPreview>
widget.openOnPreviewTitleTap ? () => _onOpen(data.link!) : null,
child: Container(
padding: EdgeInsets.only(
bottom: _padding.bottom,
left: _padding.left,
right: _padding.right,
bottom: padding.bottom,
left: padding.left,
right: padding.right,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -256,7 +259,7 @@ class _LinkPreviewState extends State<LinkPreview>
bool withPadding = false,
Widget? child,
}) {
final _padding = widget.padding ??
final padding = widget.padding ??
const EdgeInsets.symmetric(
horizontal: 24,
vertical: 16,
Expand All @@ -266,17 +269,17 @@ class _LinkPreviewState extends State<LinkPreview>

return Container(
constraints: BoxConstraints(maxWidth: widget.width),
padding: withPadding ? _padding : null,
padding: withPadding ? padding : null,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: withPadding
? const EdgeInsets.all(0)
: EdgeInsets.only(
left: _padding.left,
right: _padding.right,
top: _padding.top,
left: padding.left,
right: padding.right,
top: padding.top,
bottom: _hasOnlyImage() ? 0 : 16,
),
child: Column(
Expand Down Expand Up @@ -423,21 +426,21 @@ class _LinkPreviewState extends State<LinkPreview>

@override
Widget build(BuildContext context) {
final _previewData = widget.previewData;
final previewData = widget.previewData;

if (_previewData != null && _hasData(_previewData)) {
if (previewData != null && _hasData(previewData)) {
final aspectRatio = widget.previewData!.image == null
? null
: widget.previewData!.image!.width /
widget.previewData!.image!.height;

final _width = aspectRatio == 1 ? widget.width : widget.width - 32;
final width = aspectRatio == 1 ? widget.width : widget.width - 32;

return _containerWidget(
animate: shouldAnimate,
child: aspectRatio == 1
? _minimizedBodyWidget(_previewData)
: _bodyWidget(_previewData, _width),
? _minimizedBodyWidget(previewData)
: _bodyWidget(previewData, width),
withPadding: aspectRatio == 1,
);
} else {
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ homepage: https://flyer.chat
repository: https://github.com/flyerhq/flutter_link_previewer

environment:
sdk: ">=2.16.0 <3.0.0"
sdk: ">=2.17.0 <3.0.0"
flutter: ">=2.0.0"

dependencies:
Expand All @@ -19,9 +19,9 @@ dependencies:
http: ^0.13.4
linkify: ^4.1.0
meta: ^1.7.0
url_launcher: ^6.0.20
url_launcher: ^6.1.2

dev_dependencies:
flutter_lints: ^1.0.4
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter

0 comments on commit c62ec49

Please sign in to comment.