1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Added support of weblink posts

This commit is contained in:
Pierre HUBERT 2019-06-24 10:48:31 +02:00
parent 54482fc70f
commit 4085c6cdd5
4 changed files with 63 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import 'package:comunic/utils/navigation_utils.dart';
import 'package:comunic/utils/post_utils.dart'; import 'package:comunic/utils/post_utils.dart';
import 'package:comunic/utils/ui_utils.dart'; import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
/// Single posts tile /// Single posts tile
/// ///
@ -166,6 +167,10 @@ class _PostTileState extends State<PostTile> {
postContent = _buildPostImage(); postContent = _buildPostImage();
break; break;
case PostKind.WEB_LINK:
postContent = _buildPostWebLink();
break;
default: default:
} }
@ -249,6 +254,41 @@ class _PostTileState extends State<PostTile> {
); );
} }
Widget _buildPostWebLink() {
return Card(
color: Color.fromRGBO(0xf7, 0xf7, 0xf7, 1),
child: InkWell(
onTap: () => launch(widget.post.linkURL),
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: NetworkImageWidget(
url: widget.post.linkImage,
width: 70,
roundedEdges: false,
),
),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(htmlDecodeCharacters(widget.post.linkTitle),
style: TextStyle(fontSize: 20.0)),
Text(
widget.post.linkURL,
maxLines: 3,
),
Text(htmlDecodeCharacters(widget.post.linkDescription))
],
),
)
],
),
),
);
}
/// Build the list of comments /// Build the list of comments
Widget _buildComments() { Widget _buildComments() {
assert(widget.post.hasComments); assert(widget.post.hasComments);

View File

@ -1,6 +1,7 @@
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:html/parser.dart';
/// User interface utilities /// User interface utilities
/// ///
@ -171,3 +172,8 @@ Widget smartInputCounterWidgetBuilder(
@required bool isFocused, @required bool isFocused,
}) => }) =>
currentLength > 0 ? Text("$currentLength/$maxLength") : Container(); currentLength > 0 ? Text("$currentLength/$maxLength") : Container();
/// Parse an HTML String to decode special characters
String htmlDecodeCharacters(String input) {
return parse(input).documentElement.text;
}

View File

@ -57,6 +57,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.6" version: "2.0.6"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.0"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -88,6 +95,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
html:
dependency: "direct main"
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+2"
http: http:
dependency: transitive dependency: transitive
description: description:

View File

@ -42,6 +42,9 @@ dependencies:
# URL launcher is useful to open URL in the phone browser # URL launcher is useful to open URL in the phone browser
url_launcher: ^5.0.2 url_launcher: ^5.0.2
# Allows to parse HTML special characters
html: ^0.14.0+2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter